Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operator: Add PodDisruptionBudget to the Ruler #9262

Merged
merged 4 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions operator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Main
- [9262](https://github.com/grafana/loki/pull/9262) **btaani**: Add PodDisruptionBudget to the Ruler
- [9188](https://github.com/grafana/loki/pull/9188) **aminesnow**: Add PodDisruptionBudgets to the query path
- [9162](https://github.com/grafana/loki/pull/9162) **aminesnow**: Add a PodDisruptionBudget to lokistack-gateway
- [9049](https://github.com/grafana/loki/pull/9049) **alanconway**: Revert 1x.extra-small changes, add 1x.demo
Expand Down
27 changes: 27 additions & 0 deletions operator/internal/manifests/ruler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -61,6 +62,7 @@ func BuildRuler(opts Options) ([]client.Object, error) {
statefulSet,
NewRulerGRPCService(opts),
NewRulerHTTPService(opts),
NewRulerPodDisruptionBudget(opts),
), nil
}

Expand Down Expand Up @@ -364,3 +366,28 @@ func ruleVolumeItems(configMapName string, tenants map[string]TenantConfig) []co

return items
}

// NewRulerPodDisruptionBudget returns a PodDisruptionBudget for the LokiStack ruler pods.
func NewRulerPodDisruptionBudget(opts Options) *policyv1.PodDisruptionBudget {
l := ComponentLabels(LabelRulerComponent, opts.Name)

ma := intstr.FromInt(1)

return &policyv1.PodDisruptionBudget{
TypeMeta: metav1.TypeMeta{
Kind: "PodDisruptionBudget",
APIVersion: policyv1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Labels: l,
Name: RulerName(opts.Name),
Namespace: opts.Namespace,
},
Spec: policyv1.PodDisruptionBudgetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: l,
},
MinAvailable: &ma,
},
}
}
30 changes: 29 additions & 1 deletion operator/internal/manifests/ruler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/grafana/loki/operator/internal/manifests/openshift"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
)

func TestNewRulerStatefulSet_HasTemplateConfigHashAnnotation(t *testing.T) {
Expand Down Expand Up @@ -78,7 +79,7 @@ func TestBuildRuler_HasExtraObjectsForTenantMode(t *testing.T) {
})

require.NoError(t, err)
require.Len(t, objs, 7)
require.Len(t, objs, 8)
}

func TestNewRulerStatefulSet_SelectorMatchesLabels(t *testing.T) {
Expand Down Expand Up @@ -169,3 +170,30 @@ func TestNewRulerStatefulSet_ShardedRulesConfigMap(t *testing.T) {
require.Len(t, volumeNames, 2)
require.Len(t, volumeProjections, 2)
}

func TestBuildRuler_PodDisruptionBudget(t *testing.T) {
opts := manifests.Options{
Name: "abcd",
Namespace: "efgh",
Stack: lokiv1.LokiStackSpec{
Template: &lokiv1.LokiTemplateSpec{
Ruler: &lokiv1.LokiComponentSpec{
Replicas: 1,
},
},
},
}

objs, err := manifests.BuildRuler(opts)

require.NoError(t, err)
require.Len(t, objs, 4)

pdb := objs[3].(*policyv1.PodDisruptionBudget)
require.NotNil(t, pdb)
require.Equal(t, "abcd-ruler", pdb.Name)
require.Equal(t, "efgh", pdb.Namespace)
require.NotNil(t, pdb.Spec.MinAvailable.IntVal)
require.Equal(t, int32(1), pdb.Spec.MinAvailable.IntVal)
require.EqualValues(t, manifests.ComponentLabels(manifests.LabelRulerComponent, opts.Name), pdb.Spec.Selector.MatchLabels)
}