Skip to content

Commit b459861

Browse files
committed
add drift detection test
1 parent 737138e commit b459861

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

internal/controller/datadogagent/feature/apm/profile_overlay_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import (
1414
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1515
"k8s.io/utils/ptr"
1616

17+
apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common"
1718
"github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1"
19+
featurefake "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake"
1820
)
1921

2022
func TestAPMProfileSharedConfigOverlay(t *testing.T) {
@@ -472,6 +474,86 @@ func TestAPMProfileSharedConfigOverlay(t *testing.T) {
472474
}
473475
}
474476

477+
// Profile SSI overlays should render the same Cluster Agent config as direct
478+
// base-DDA SSI config. Node Agent config is intentionally out of scope because
479+
// profile-owned APM config renders on the profile DDAI instead of the default
480+
// DDAI.
481+
func TestAPMProfileSharedConfigOverlayMatchesDirectDDAClusterAgentConfig(t *testing.T) {
482+
tests := []struct {
483+
name string
484+
ssi *v2alpha1.SingleStepInstrumentation
485+
}{
486+
{
487+
name: "enabled namespaces",
488+
ssi: &v2alpha1.SingleStepInstrumentation{
489+
Enabled: ptr.To(true),
490+
EnabledNamespaces: []string{"payments", "checkout"},
491+
LibVersions: map[string]string{"java": "1.43.0", "python": "2.14.0"},
492+
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: ptr.To(true)},
493+
Injector: &v2alpha1.InjectorConfig{ImageTag: "7.66.0"},
494+
InjectionMode: v2alpha1.InjectionModeInitContainer,
495+
Targets: []v2alpha1.SSITarget{
496+
{
497+
Name: "api",
498+
PodSelector: &metav1.LabelSelector{
499+
MatchLabels: map[string]string{"app": "api"},
500+
},
501+
TracerVersions: map[string]string{"java": "1.43.0"},
502+
TracerConfigs: []corev1.EnvVar{
503+
{Name: "DD_TRACE_DEBUG", Value: "true"},
504+
},
505+
},
506+
},
507+
},
508+
},
509+
{
510+
name: "disabled namespaces",
511+
ssi: &v2alpha1.SingleStepInstrumentation{
512+
Enabled: ptr.To(true),
513+
DisabledNamespaces: []string{"kube-system", "datadog"},
514+
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: ptr.To(false)},
515+
},
516+
},
517+
}
518+
519+
for _, tt := range tests {
520+
t.Run(tt.name, func(t *testing.T) {
521+
directDDA := testProfileOverlayBaseSpec(false)
522+
directDDA.Features.APM.SingleStepInstrumentation = tt.ssi.DeepCopy()
523+
524+
overlayDDA := testProfileOverlayBaseSpec(false)
525+
profile := testProfileOverlayProfileSpec(tt.ssi.DeepCopy())
526+
require.NoError(t, applyAPMProfileSharedConfigOverlay(overlayDDA, overlayDDA.DeepCopy(), profile))
527+
528+
assert.Equal(
529+
t,
530+
renderAPMClusterAgentEnvVars(t, directDDA),
531+
renderAPMClusterAgentEnvVars(t, overlayDDA),
532+
)
533+
})
534+
}
535+
}
536+
537+
func renderAPMClusterAgentEnvVars(t testing.TB, spec *v2alpha1.DatadogAgentSpec) []*corev1.EnvVar {
538+
t.Helper()
539+
540+
dda := &v2alpha1.DatadogAgent{
541+
ObjectMeta: metav1.ObjectMeta{
542+
Name: "datadog",
543+
Namespace: "default",
544+
},
545+
Spec: *spec.DeepCopy(),
546+
}
547+
feat := buildAPMFeature(nil).(*apmFeature)
548+
reqComp := feat.Configure(dda, &dda.Spec, nil)
549+
require.True(t, reqComp.ClusterAgent.IsEnabled())
550+
551+
mgr := featurefake.NewPodTemplateManagers(t, corev1.PodTemplateSpec{})
552+
require.NoError(t, feat.ManageClusterAgent(mgr))
553+
554+
return mgr.EnvVarMgr.EnvVarsByC[apicommon.ClusterAgentContainerName]
555+
}
556+
475557
func testProfileOverlayBaseSpec(ssiEnabled bool) *v2alpha1.DatadogAgentSpec {
476558
return &v2alpha1.DatadogAgentSpec{
477559
Features: &v2alpha1.DatadogFeatures{

0 commit comments

Comments
 (0)