Skip to content

Commit b339979

Browse files
authored
Fix name label propagation for TA selectors (open-telemetry#2632)
* propagate name label to selector * add propagation test to e2e-targetallocator * add chlog * restore comments * add test to chainsaw
1 parent c812713 commit b339979

File tree

6 files changed

+55
-1
lines changed

6 files changed

+55
-1
lines changed

.chloggen/fix-2598.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: bug_fix
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
5+
component: operator
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: propagate otel name label down to selector of ta resources
9+
10+
# One or more tracking issues related to the change
11+
issues: [2598]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

internal/manifests/targetallocator/labels.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ func Labels(instance v1beta1.OpenTelemetryCollector, name string) map[string]str
2828
// SelectorLabels return the selector labels for Target Allocator Pods.
2929
func SelectorLabels(instance v1beta1.OpenTelemetryCollector) map[string]string {
3030
selectorLabels := manifestutils.SelectorLabels(instance.ObjectMeta, ComponentOpenTelemetryTargetAllocator)
31+
3132
// TargetAllocator uses the name label as well for selection
3233
// This is inconsistent with the Collector, but changing is a somewhat painful breaking change
33-
selectorLabels["app.kubernetes.io/name"] = naming.TargetAllocator(instance.Name)
34+
// Don't override the app name if it already exists
35+
if name, ok := instance.ObjectMeta.Labels["app.kubernetes.io/name"]; ok {
36+
selectorLabels["app.kubernetes.io/name"] = name
37+
} else {
38+
selectorLabels["app.kubernetes.io/name"] = naming.TargetAllocator(instance.Name)
39+
}
3440
return selectorLabels
3541
}

internal/manifests/targetallocator/labels_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ func TestLabelsPropagateDown(t *testing.T) {
6161

6262
// test
6363
labels := Labels(otelcol, name)
64+
selectorLabels := SelectorLabels(otelcol)
6465

6566
// verify
6667
assert.Len(t, labels, 7)
6768
assert.Equal(t, "mycomponent", labels["myapp"])
6869
assert.Equal(t, "test", labels["app.kubernetes.io/name"])
70+
assert.Equal(t, "test", selectorLabels["app.kubernetes.io/name"])
6971
}
7072

7173
func TestSelectorLabels(t *testing.T) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: stateful-targetallocator
5+
labels:
6+
app.kubernetes.io/name: test
7+
spec:
8+
selector:
9+
matchLabels:
10+
app.kubernetes.io/name: test
11+
template:
12+
metadata:
13+
labels:
14+
app.kubernetes.io/name: test
15+
status:
16+
replicas: 1
17+
readyReplicas: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: opentelemetry.io/v1alpha1
2+
kind: OpenTelemetryCollector
3+
metadata:
4+
name: stateful
5+
labels:
6+
app.kubernetes.io/name: test
7+

tests/e2e-targetallocator/targetallocator-features/chainsaw-test.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ spec:
3939
duration: 35s
4040
- assert:
4141
file: 01-assert.yaml
42+
- name: step-02
43+
try:
44+
- apply:
45+
file: 02-install.yaml
46+
- assert:
47+
file: 02-assert.yaml

0 commit comments

Comments
 (0)