From 8c5835ed3c3ce5744bc3b39c526e86371cc02301 Mon Sep 17 00:00:00 2001 From: Tiago Angelo <5454243+angelokurtis@users.noreply.github.com> Date: Thu, 20 Oct 2022 06:53:03 -0300 Subject: [PATCH] Using immutable labels as service selectors (#1152) * Using immutable labels as service selectors * Fixing expected service selectors * Removing unnecessary selector Co-authored-by: Vineeth Pothulapati --- pkg/collector/reconcile/service.go | 11 ++--------- pkg/collector/reconcile/service_test.go | 3 +-- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/pkg/collector/reconcile/service.go b/pkg/collector/reconcile/service.go index 896c99a356..86a84f2002 100644 --- a/pkg/collector/reconcile/service.go +++ b/pkg/collector/reconcile/service.go @@ -71,10 +71,6 @@ func desiredService(ctx context.Context, params Params) *corev1.Service { labels := collector.Labels(params.Instance, []string{}) labels["app.kubernetes.io/name"] = naming.Service(params.Instance) - // by coincidence, the selector is the same as the label, but note that the selector points to the deployment - // whereas 'labels' refers to the service - selector := labels - config, err := adapters.ConfigFromString(params.Instance.Spec.Config) if err != nil { params.Log.Error(err, "couldn't extract the configuration from the context") @@ -120,7 +116,7 @@ func desiredService(ctx context.Context, params Params) *corev1.Service { Annotations: params.Instance.Annotations, }, Spec: corev1.ServiceSpec{ - Selector: selector, + Selector: collector.SelectorLabels(params.Instance), ClusterIP: "", Ports: ports, }, @@ -176,9 +172,6 @@ func monitoringService(ctx context.Context, params Params) *corev1.Service { labels := collector.Labels(params.Instance, []string{}) labels["app.kubernetes.io/name"] = naming.MonitoringService(params.Instance) - selector := collector.Labels(params.Instance, []string{}) - selector["app.kubernetes.io/name"] = fmt.Sprintf("%s-collector", params.Instance.Name) - return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: naming.MonitoringService(params.Instance), @@ -187,7 +180,7 @@ func monitoringService(ctx context.Context, params Params) *corev1.Service { Annotations: params.Instance.Annotations, }, Spec: corev1.ServiceSpec{ - Selector: selector, + Selector: collector.SelectorLabels(params.Instance), ClusterIP: "", Ports: []corev1.ServicePort{{ Name: "monitoring", diff --git a/pkg/collector/reconcile/service_test.go b/pkg/collector/reconcile/service_test.go index f200a166bc..c98553b208 100644 --- a/pkg/collector/reconcile/service_test.go +++ b/pkg/collector/reconcile/service_test.go @@ -233,7 +233,6 @@ func service(name string, ports []v1.ServicePort) v1.Service { labels := collector.Labels(params().Instance, []string{}) labels["app.kubernetes.io/name"] = name - selector := labels return v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -242,7 +241,7 @@ func service(name string, ports []v1.ServicePort) v1.Service { Annotations: params().Instance.Annotations, }, Spec: v1.ServiceSpec{ - Selector: selector, + Selector: collector.SelectorLabels(params().Instance), ClusterIP: "", Ports: ports, },