From f93ebec0f30f62f2263da222a08b7f4f6d20615b Mon Sep 17 00:00:00 2001 From: "agent-platform-auto-pr[bot]" <153269286+agent-platform-auto-pr[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:07:23 -0500 Subject: [PATCH] [Backport 7.61.x] Only set INSTALLATION environment variables when doing injection (#31898) Co-authored-by: Stan Rozenraukh --- .../auto_instrumentation.go | 4 +- .../auto_instrumentation_test.go | 44 ++----------------- ...disabled-no-env-vars-135252f0eb8ddef4.yaml | 5 +++ 3 files changed, 12 insertions(+), 41 deletions(-) create mode 100644 releasenotes-dca/notes/admission-controller-disabled-no-env-vars-135252f0eb8ddef4.yaml diff --git a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation.go b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation.go index b25289c3a1d31..a3d1aff6b6afa 100644 --- a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation.go +++ b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation.go @@ -157,7 +157,6 @@ func (w *Webhook) inject(pod *corev1.Pod, ns string, _ dynamic.Interface) (bool, if pod.Namespace == "" { pod.Namespace = ns } - injectApmTelemetryConfig(pod) if !w.isPodEligible(pod) { return false, nil @@ -371,6 +370,9 @@ func (s libInfoSource) mutatePod(pod *corev1.Pod) error { Name: instrumentationInstallTypeEnvVarName, Value: s.injectionType(), }) + + injectApmTelemetryConfig(pod) + return nil } diff --git a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_test.go b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_test.go index 2db44b4acbb6a..97dda98d33174 100644 --- a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_test.go +++ b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_test.go @@ -2307,16 +2307,7 @@ func TestInjectAutoInstrumentation(t *testing.T) { "admission.datadoghq.com/enabled": "false", }, }.Create(), - expectedEnvs: []corev1.EnvVar{ - { - Name: "DD_INSTRUMENTATION_INSTALL_TIME", - Value: installTime, - }, - { - Name: "DD_INSTRUMENTATION_INSTALL_ID", - Value: uuid, - }, - }, + expectedEnvs: nil, expectedInjectedLibraries: map[string]string{}, expectedSecurityContext: &corev1.SecurityContext{}, wantErr: false, @@ -2415,16 +2406,7 @@ func TestInjectAutoInstrumentation(t *testing.T) { ParentKind: "replicaset", ParentName: "test-deployment-123", }.Create(), - expectedEnvs: []corev1.EnvVar{ - { - Name: "DD_INSTRUMENTATION_INSTALL_TIME", - Value: installTime, - }, - { - Name: "DD_INSTRUMENTATION_INSTALL_ID", - Value: uuid, - }, - }, + expectedEnvs: nil, expectedInjectedLibraries: map[string]string{}, expectedSecurityContext: &corev1.SecurityContext{}, wantErr: false, @@ -2495,16 +2477,7 @@ func TestInjectAutoInstrumentation(t *testing.T) { ParentKind: "replicaset", ParentName: "test-deployment-123", }.Create(), - expectedEnvs: []corev1.EnvVar{ - { - Name: "DD_INSTRUMENTATION_INSTALL_TIME", - Value: installTime, - }, - { - Name: "DD_INSTRUMENTATION_INSTALL_ID", - Value: uuid, - }, - }, + expectedEnvs: nil, expectedInjectedLibraries: map[string]string{}, expectedSecurityContext: &corev1.SecurityContext{}, wantErr: false, @@ -2517,16 +2490,7 @@ func TestInjectAutoInstrumentation(t *testing.T) { ParentKind: "replicaset", ParentName: "test-deployment-123", }.Create(), - expectedEnvs: []corev1.EnvVar{ - { - Name: "DD_INSTRUMENTATION_INSTALL_TIME", - Value: installTime, - }, - { - Name: "DD_INSTRUMENTATION_INSTALL_ID", - Value: uuid, - }, - }, + expectedEnvs: nil, expectedInjectedLibraries: map[string]string{}, expectedSecurityContext: &corev1.SecurityContext{}, wantErr: false, diff --git a/releasenotes-dca/notes/admission-controller-disabled-no-env-vars-135252f0eb8ddef4.yaml b/releasenotes-dca/notes/admission-controller-disabled-no-env-vars-135252f0eb8ddef4.yaml new file mode 100644 index 0000000000000..763bb18a91d83 --- /dev/null +++ b/releasenotes-dca/notes/admission-controller-disabled-no-env-vars-135252f0eb8ddef4.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + The auto-instrumentation webhook no longer injects the default environment + variables when disabled.