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

Using immutable labels as service selectors #1152

Merged
merged 5 commits into from
Oct 20, 2022
Merged
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
11 changes: 2 additions & 9 deletions pkg/collector/reconcile/service.go
Original file line number Diff line number Diff line change
@@ -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",
3 changes: 1 addition & 2 deletions pkg/collector/reconcile/service_test.go
Original file line number Diff line number Diff line change
@@ -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,
},