Skip to content

Commit

Permalink
fix(operator): truncate sidecar pod injected label to 63 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
RoVernekar committed Oct 19, 2023
1 parent 41295b4 commit 59c4cc4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/sidecar/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func add(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemetryCo
if pod.Labels == nil {
pod.Labels = map[string]string{}
}
pod.Labels[label] = fmt.Sprintf("%s.%s", otelcol.Namespace, otelcol.Name)
pod.Labels[label] = naming.Truncate("%s.%s", 63, otelcol.Namespace, otelcol.Name)

return pod, nil
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/sidecar/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestAddSidecarWhenNoSidecarExists(t *testing.T) {
}
otelcol := v1alpha1.OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "otelcol-sample",
Name: "otelcol-sample-with-a-name-that-is-longer-than-sixty-three-characters",
Namespace: "some-app",
},
Spec: v1alpha1.OpenTelemetryCollectorSpec{
Expand All @@ -74,7 +74,8 @@ processors:
require.Len(t, changed.Spec.Containers, 2)
require.Len(t, changed.Spec.InitContainers, 2)
require.Len(t, changed.Spec.Volumes, 1)
assert.Equal(t, "some-app.otelcol-sample", changed.Labels["sidecar.opentelemetry.io/injected"])
assert.Equal(t, "otelcol-sample-with-a-name-that-is-longer-than-sixty-three-cha",
changed.Labels["sidecar.opentelemetry.io/injected"])
assert.Equal(t, corev1.Container{
Name: "otc-container",
Image: "some-default-image",
Expand Down

0 comments on commit 59c4cc4

Please sign in to comment.