Skip to content

Commit

Permalink
[Backport 7.61.x] Only set INSTALLATION environment variables when do…
Browse files Browse the repository at this point in the history
…ing injection (#31898)

Co-authored-by: Stan Rozenraukh <[email protected]>
  • Loading branch information
agent-platform-auto-pr[bot] and stanistan authored Dec 9, 2024
1 parent 9c46226 commit f93ebec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -371,6 +370,9 @@ func (s libInfoSource) mutatePod(pod *corev1.Pod) error {
Name: instrumentationInstallTypeEnvVarName,
Value: s.injectionType(),
})

injectApmTelemetryConfig(pod)

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
The auto-instrumentation webhook no longer injects the default environment
variables when disabled.

0 comments on commit f93ebec

Please sign in to comment.