Skip to content

Commit

Permalink
Using immutable labels as service selectors (open-telemetry#1152)
Browse files Browse the repository at this point in the history
* Using immutable labels as service selectors

* Fixing expected service selectors

* Removing unnecessary selector

Co-authored-by: Vineeth Pothulapati <[email protected]>
  • Loading branch information
angelokurtis and VineethReddy02 authored Oct 20, 2022
1 parent 3aa4843 commit 8c5835e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
11 changes: 2 additions & 9 deletions pkg/collector/reconcile/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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),
Expand All @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions pkg/collector/reconcile/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
Expand Down

0 comments on commit 8c5835e

Please sign in to comment.