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.