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

Fix name label propagation for TA selectors #2632

Merged
merged 8 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
16 changes: 16 additions & 0 deletions .chloggen/fix-2598.yaml
Original file line number Diff line number Diff line change
@@ -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:
9 changes: 6 additions & 3 deletions internal/manifests/targetallocator/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ func Labels(instance v1alpha2.OpenTelemetryCollector, name string) map[string]st
// SelectorLabels return the selector labels for Target Allocator Pods.
func SelectorLabels(instance v1alpha2.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
}
2 changes: 2 additions & 0 deletions internal/manifests/targetallocator/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: stateful
labels:
app.kubernetes.io/name: test

Loading