diff --git a/operator/CHANGELOG.md b/operator/CHANGELOG.md index 7d7e592503..b25f5b21e4 100644 --- a/operator/CHANGELOG.md +++ b/operator/CHANGELOG.md @@ -1,4 +1,5 @@ ## Main +- [9339](https://github.com/grafana/loki/pull/9339) **JoaoBraveCoding**: Add default PodAntiAffinity to Ruler - [9329](https://github.com/grafana/loki/pull/9329) **JoaoBraveCoding**: Add default PodAntiAffinity to Ingester - [9262](https://github.com/grafana/loki/pull/9262) **btaani**: Add PodDisruptionBudget to the Ruler - [9260](https://github.com/grafana/loki/pull/9260) **JoaoBraveCoding**: Add PodDisruptionBudgets to the ingestion path diff --git a/operator/internal/manifests/ingester_test.go b/operator/internal/manifests/ingester_test.go index 05dc8763a7..d2d5955d51 100644 --- a/operator/internal/manifests/ingester_test.go +++ b/operator/internal/manifests/ingester_test.go @@ -159,8 +159,7 @@ func TestIngesterPodAntiAffinity(t *testing.T) { LabelSelector: &metav1.LabelSelector{ MatchLabels: map[string]string{ "app.kubernetes.io/component": manifests.LabelIngesterComponent, - "app.kubernetes.io/instance": "abcd", - + "app.kubernetes.io/instance": "abcd", }, }, TopologyKey: "kubernetes.io/hostname", diff --git a/operator/internal/manifests/ruler_test.go b/operator/internal/manifests/ruler_test.go index 6242d33ed6..0cce4a1ec7 100644 --- a/operator/internal/manifests/ruler_test.go +++ b/operator/internal/manifests/ruler_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" lokiv1 "github.com/grafana/loki/operator/apis/loki/v1" "github.com/grafana/loki/operator/internal/manifests" @@ -198,3 +199,36 @@ func TestBuildRuler_PodDisruptionBudget(t *testing.T) { require.Equal(t, int32(1), pdb.Spec.MinAvailable.IntVal) require.EqualValues(t, manifests.ComponentLabels(manifests.LabelRulerComponent, opts.Name), pdb.Spec.Selector.MatchLabels) } + +func TestRulerPodAntiAffinity(t *testing.T) { + sts := manifests.NewRulerStatefulSet(manifests.Options{ + Name: "abcd", + Namespace: "efgh", + Stack: lokiv1.LokiStackSpec{ + StorageClassName: "standard", + Template: &lokiv1.LokiTemplateSpec{ + Ruler: &lokiv1.LokiComponentSpec{ + Replicas: 1, + }, + }, + }, + }) + expectedPodAntiAffinity := &corev1.PodAntiAffinity{ + PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{ + { + Weight: 100, + PodAffinityTerm: corev1.PodAffinityTerm{ + LabelSelector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "app.kubernetes.io/component": manifests.LabelRulerComponent, + "app.kubernetes.io/instance": "abcd", + }, + }, + TopologyKey: "kubernetes.io/hostname", + }, + }, + }, + } + require.NotNil(t, sts.Spec.Template.Spec.Affinity) + require.Equal(t, expectedPodAntiAffinity, sts.Spec.Template.Spec.Affinity.PodAntiAffinity) +} diff --git a/operator/internal/manifests/var.go b/operator/internal/manifests/var.go index fce7cc6c97..28e2e0c741 100644 --- a/operator/internal/manifests/var.go +++ b/operator/internal/manifests/var.go @@ -113,6 +113,7 @@ var ( volumeFileSystemMode = corev1.PersistentVolumeFilesystem podAntiAffinityComponents = map[string]struct{}{ LabelIngesterComponent: {}, + LabelRulerComponent: {}, } )