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

Dynamic ThanosRuler governing service name #6389

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/thanos/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const (
rulesDir = "/etc/thanos/rules"
configDir = "/etc/thanos/config"
storageDir = "/thanos/data"
governingServiceName = "thanos-ruler-operated"
defaultPortName = "web"
defaultRetention = "24h"
defaultEvaluationInterval = "15s"
Expand Down Expand Up @@ -410,7 +409,7 @@ func makeStatefulSetSpec(tr *monitoringv1.ThanosRuler, config Config, ruleConfig
// PodManagementPolicy is set to Parallel to mitigate issues in kubernetes: https://github.com/kubernetes/kubernetes/issues/60164
// This is also mentioned as one of limitations of StatefulSets: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#limitations
return &appsv1.StatefulSetSpec{
ServiceName: governingServiceName,
ServiceName: serviceName(tr.Name),
Replicas: tr.Spec.Replicas,
MinReadySeconds: minReadySeconds,
PodManagementPolicy: appsv1.ParallelPodManagement,
Expand Down Expand Up @@ -473,7 +472,7 @@ func makeStatefulSetService(tr *monitoringv1.ThanosRuler, config Config) *v1.Ser

operator.UpdateObject(
svc,
operator.WithName(governingServiceName),
operator.WithName(serviceName(tr.Name)),
operator.WithAnnotations(config.Annotations),
operator.WithLabels(map[string]string{"operated-thanos-ruler": "true"}),
operator.WithLabels(config.Labels),
Expand All @@ -487,6 +486,10 @@ func prefixedName(name string) string {
return fmt.Sprintf("thanos-ruler-%s", name)
}

func serviceName(name string) string {
return fmt.Sprintf("%s-operated", prefixedName(name))
}

func volumeName(name string) string {
return fmt.Sprintf("%s-data", prefixedName(name))
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/thanos/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,9 +932,10 @@ func TestStatefulSetServiceName(t *testing.T) {
QueryEndpoints: emptyQueryEndpoints,
},
}
tr.Name = "test"

// assert set correctly
expect := governingServiceName
expect := serviceName(tr.Name)
spec, err := makeStatefulSetSpec(&tr, defaultTestConfig, nil)
if err != nil {
t.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/thanosruler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ func testTRPreserveUserAddedMetadata(t *testing.T) {
update func(object metav1.Object) (metav1.Object, error)
}{
{
name: "thanos-ruler-operated service",
name: "thanos-ruler operated service",
get: func() (metav1.Object, error) {
return svcClient.Get(context.Background(), "thanos-ruler-operated", metav1.GetOptions{})
return svcClient.Get(context.Background(), "thanos-ruler-test-operated", metav1.GetOptions{})
},
update: func(object metav1.Object) (metav1.Object, error) {
return svcClient.Update(context.Background(), asService(t, object), metav1.UpdateOptions{})
Expand Down