diff --git a/.chloggen/fix-2598.yaml b/.chloggen/fix-2598.yaml new file mode 100755 index 0000000000..3ab0f19033 --- /dev/null +++ b/.chloggen/fix-2598.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action) +component: operator + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: propagate otel name label down to selector of ta resources + +# One or more tracking issues related to the change +issues: [2598] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/internal/manifests/targetallocator/labels.go b/internal/manifests/targetallocator/labels.go index 09a43e4108..899269128e 100644 --- a/internal/manifests/targetallocator/labels.go +++ b/internal/manifests/targetallocator/labels.go @@ -28,8 +28,14 @@ func Labels(instance v1beta1.OpenTelemetryCollector, name string) map[string]str // SelectorLabels return the selector labels for Target Allocator Pods. func SelectorLabels(instance v1beta1.OpenTelemetryCollector) map[string]string { selectorLabels := manifestutils.SelectorLabels(instance.ObjectMeta, ComponentOpenTelemetryTargetAllocator) + // TargetAllocator uses the name label as well for selection // This is inconsistent with the Collector, but changing is a somewhat painful breaking change - selectorLabels["app.kubernetes.io/name"] = naming.TargetAllocator(instance.Name) + // Don't override the app name if it already exists + if name, ok := instance.ObjectMeta.Labels["app.kubernetes.io/name"]; ok { + selectorLabels["app.kubernetes.io/name"] = name + } else { + selectorLabels["app.kubernetes.io/name"] = naming.TargetAllocator(instance.Name) + } return selectorLabels } diff --git a/internal/manifests/targetallocator/labels_test.go b/internal/manifests/targetallocator/labels_test.go index 382835d532..4304f97c25 100644 --- a/internal/manifests/targetallocator/labels_test.go +++ b/internal/manifests/targetallocator/labels_test.go @@ -61,11 +61,13 @@ func TestLabelsPropagateDown(t *testing.T) { // test labels := Labels(otelcol, name) + selectorLabels := SelectorLabels(otelcol) // verify assert.Len(t, labels, 7) assert.Equal(t, "mycomponent", labels["myapp"]) assert.Equal(t, "test", labels["app.kubernetes.io/name"]) + assert.Equal(t, "test", selectorLabels["app.kubernetes.io/name"]) } func TestSelectorLabels(t *testing.T) { diff --git a/tests/e2e-targetallocator/targetallocator-features/02-assert.yaml b/tests/e2e-targetallocator/targetallocator-features/02-assert.yaml new file mode 100644 index 0000000000..29b0bd3bb2 --- /dev/null +++ b/tests/e2e-targetallocator/targetallocator-features/02-assert.yaml @@ -0,0 +1,17 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: stateful-targetallocator + labels: + app.kubernetes.io/name: test +spec: + selector: + matchLabels: + app.kubernetes.io/name: test + template: + metadata: + labels: + app.kubernetes.io/name: test +status: + replicas: 1 + readyReplicas: 1 diff --git a/tests/e2e-targetallocator/targetallocator-features/02-install.yaml b/tests/e2e-targetallocator/targetallocator-features/02-install.yaml new file mode 100644 index 0000000000..3ee4c7a576 --- /dev/null +++ b/tests/e2e-targetallocator/targetallocator-features/02-install.yaml @@ -0,0 +1,7 @@ +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: stateful + labels: + app.kubernetes.io/name: test + diff --git a/tests/e2e-targetallocator/targetallocator-features/chainsaw-test.yaml b/tests/e2e-targetallocator/targetallocator-features/chainsaw-test.yaml index 555326724d..9052ecac1a 100755 --- a/tests/e2e-targetallocator/targetallocator-features/chainsaw-test.yaml +++ b/tests/e2e-targetallocator/targetallocator-features/chainsaw-test.yaml @@ -27,3 +27,9 @@ spec: duration: 35s - assert: file: 01-assert.yaml + - name: step-02 + try: + - apply: + file: 02-install.yaml + - assert: + file: 02-assert.yaml