-
Notifications
You must be signed in to change notification settings - Fork 144
[OTAGENT-980] Reference v1.0.5 WorkloadAllowlist exemption when OTel collector is enabled #3022
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
Closed
+406
−12
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
internal/controller/datadogagent/experimental/autopilot_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed | ||
| // under the Apache License Version 2.0. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| // Copyright 2016-present Datadog, Inc. | ||
|
|
||
| package experimental | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common" | ||
| "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake" | ||
| "github.com/stretchr/testify/assert" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // TestHasOtelAgentContainer verifies that the otel-agent container detection used to | ||
| // gate the v1.0.5 WorkloadAllowlist exemption inclusion works for both the present | ||
| // and absent cases. See OTAGENT-980. | ||
| func TestHasOtelAgentContainer(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| containers []corev1.Container | ||
| expected bool | ||
| }{ | ||
| { | ||
| name: "no otel-agent container", | ||
| containers: []corev1.Container{ | ||
| {Name: string(apicommon.CoreAgentContainerName)}, | ||
| {Name: string(apicommon.TraceAgentContainerName)}, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "otel-agent container present", | ||
| containers: []corev1.Container{ | ||
| {Name: string(apicommon.CoreAgentContainerName)}, | ||
| {Name: string(apicommon.OtelAgent)}, | ||
| }, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "empty containers", | ||
| containers: nil, | ||
| expected: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| manager := fake.NewPodTemplateManagers(t, corev1.PodTemplateSpec{ | ||
| Spec: corev1.PodSpec{Containers: tt.containers}, | ||
| }) | ||
| assert.Equal(t, tt.expected, hasOtelAgentContainer(manager)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // TestApplyExperimentalAutopilotOverrides_SynchronizerInvocation verifies that the | ||
| // autopilot override branch invokes the synchronizer creator with the correct flag | ||
| // derived from the rendered pod template (OTAGENT-980). | ||
| func TestApplyExperimentalAutopilotOverrides_SynchronizerInvocation(t *testing.T) { | ||
| // Stub out the synchronizer creator so tests don't hit kubeconfig loading. | ||
| origCreator := createAllowlistSynchronizer | ||
| defer func() { createAllowlistSynchronizer = origCreator }() | ||
|
|
||
| autopilotAnnotation := map[string]string{ | ||
| ExperimentalAnnotationPrefix + "/" + ExperimentalAutopilotSubkey: "true", | ||
| } | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| annotations map[string]string | ||
| containers []corev1.Container | ||
| expectInvoked bool | ||
| expectOtelFlagPassed bool | ||
| }{ | ||
| { | ||
| name: "autopilot disabled does not invoke synchronizer", | ||
| annotations: nil, | ||
| containers: []corev1.Container{{Name: string(apicommon.CoreAgentContainerName)}}, | ||
| expectInvoked: false, | ||
| expectOtelFlagPassed: false, | ||
| }, | ||
| { | ||
| name: "autopilot enabled without otel-agent invokes synchronizer with false", | ||
| annotations: autopilotAnnotation, | ||
| containers: []corev1.Container{{Name: string(apicommon.CoreAgentContainerName)}}, | ||
| expectInvoked: true, | ||
| expectOtelFlagPassed: false, | ||
| }, | ||
| { | ||
| name: "autopilot enabled with otel-agent invokes synchronizer with true", | ||
| annotations: autopilotAnnotation, | ||
| containers: []corev1.Container{{Name: string(apicommon.CoreAgentContainerName)}, {Name: string(apicommon.OtelAgent)}}, | ||
| expectInvoked: true, | ||
| expectOtelFlagPassed: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| var invoked bool | ||
| var passedFlag bool | ||
| createAllowlistSynchronizer = func(otelCollectorEnabled bool) { | ||
| invoked = true | ||
| passedFlag = otelCollectorEnabled | ||
| } | ||
|
|
||
| dda := &metav1.ObjectMeta{Annotations: tt.annotations} | ||
| manager := fake.NewPodTemplateManagers(t, corev1.PodTemplateSpec{ | ||
| Spec: corev1.PodSpec{Containers: tt.containers}, | ||
| }) | ||
|
|
||
| applyExperimentalAutopilotOverrides(dda, manager) | ||
|
|
||
| assert.Equal(t, tt.expectInvoked, invoked, "synchronizer creator invocation") | ||
| if tt.expectInvoked { | ||
| assert.Equal(t, tt.expectOtelFlagPassed, passedFlag, "otelCollectorEnabled flag") | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.