Skip to content

Commit 47e8393

Browse files
authored
enforce min agent version for CNM direct send (#3010)
enforce min agent version for CNM direct send Co-authored-by: bryce.kahle <bryce.kahle@datadoghq.com>
1 parent 491d342 commit 47e8393

4 files changed

Lines changed: 50 additions & 10 deletions

File tree

internal/controller/datadogagent/feature/npm/feature.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/agent"
1818
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature"
1919
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/volume"
20+
"github.com/DataDog/datadog-operator/pkg/utils"
2021
)
2122

2223
func init() {
@@ -44,7 +45,7 @@ func (f *npmFeature) ID() feature.IDType {
4445
}
4546

4647
// Configure is used to configure the feature from a v2alpha1.DatadogAgent instance.
47-
func (f *npmFeature) Configure(_ metav1.Object, ddaSpec *v2alpha1.DatadogAgentSpec, _ *v2alpha1.RemoteConfigConfiguration) (reqComp feature.RequiredComponents) {
48+
func (f *npmFeature) Configure(dda metav1.Object, ddaSpec *v2alpha1.DatadogAgentSpec, _ *v2alpha1.RemoteConfigConfiguration) (reqComp feature.RequiredComponents) {
4849
if ddaSpec.Features == nil {
4950
return
5051
}
@@ -54,9 +55,17 @@ func (f *npmFeature) Configure(_ metav1.Object, ddaSpec *v2alpha1.DatadogAgentSp
5455
apicommon.CoreAgentContainerName,
5556
apicommon.SystemProbeContainerName,
5657
}
57-
if !apiutils.BoolValue(ddaSpec.Features.NPM.DirectSend) {
58+
59+
directSendEnabled := apiutils.BoolValue(ddaSpec.Features.NPM.DirectSend)
60+
const directSendMinVersion = "7.77.0-0"
61+
defaultIfVersionUnknown := false
62+
if !utils.IsAboveMinVersion(common.GetComponentVersion(dda, v2alpha1.NodeAgentComponentName), directSendMinVersion, &defaultIfVersionUnknown) {
63+
directSendEnabled = false
64+
}
65+
if !directSendEnabled {
5866
containers = append(containers, apicommon.ProcessAgentContainerName)
5967
}
68+
f.directSend = directSendEnabled
6069

6170
reqComp = feature.RequiredComponents{
6271
Agent: feature.RequiredComponent{
@@ -67,7 +76,6 @@ func (f *npmFeature) Configure(_ metav1.Object, ddaSpec *v2alpha1.DatadogAgentSp
6776
npm := ddaSpec.Features.NPM
6877
f.collectDNSStats = apiutils.BoolValue(npm.CollectDNSStats)
6978
f.enableConntrack = apiutils.BoolValue(npm.EnableConntrack)
70-
f.directSend = apiutils.BoolValue(npm.DirectSend)
7179
}
7280

7381
return reqComp

internal/controller/datadogagent/feature/npm/feature_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ func Test_npmFeature_Configure(t *testing.T) {
4242
ddaNPMEnabledConfig.Spec.Features.NPM.EnableConntrack = ptr.To(false)
4343

4444
ddaCNMDirectSendEnabledConfig := ddaNPMEnabled.DeepCopy()
45+
ddaCNMDirectSendEnabledConfig.Spec.Override = map[v2alpha1.ComponentName]*v2alpha1.DatadogAgentComponentOverride{
46+
v2alpha1.NodeAgentComponentName: {
47+
Image: &v2alpha1.AgentImageConfig{Tag: "7.77.0"},
48+
},
49+
}
4550
ddaCNMDirectSendEnabledConfig.Spec.Features.NPM.DirectSend = ptr.To(true)
4651

52+
ddaCNMDirectSendEnabledUnsupportedAgentVersionConfig := ddaCNMDirectSendEnabledConfig.DeepCopy()
53+
ddaCNMDirectSendEnabledUnsupportedAgentVersionConfig.Spec.Override[v2alpha1.NodeAgentComponentName].Image.Tag = "7.76.0"
54+
4755
npmFeatureEnvVarWantFunc := func(t testing.TB, mgrInterface feature.PodTemplateManagers) {
4856
mgr := mgrInterface.(*fake.PodTemplateManagers)
4957
// check env vars
@@ -278,6 +286,12 @@ func Test_npmFeature_Configure(t *testing.T) {
278286
WantConfigure: true,
279287
Agent: test.NewDefaultComponentTest().WithWantFunc(cnmDirectSendWantFunc),
280288
},
289+
{
290+
Name: "CNM enabled, Direct Send enabled on unsupported agent version",
291+
DDA: ddaCNMDirectSendEnabledUnsupportedAgentVersionConfig,
292+
WantConfigure: true,
293+
Agent: test.NewDefaultComponentTest().WithWantFunc(npmAgentNodeWantFunc),
294+
},
281295
}
282296

283297
tests.Run(t, buildNPMFeature)

internal/controller/datadogagent/feature/usm/feature.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/agent"
1818
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature"
1919
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/object/volume"
20+
"github.com/DataDog/datadog-operator/pkg/utils"
2021
)
2122

2223
func init() {
@@ -53,20 +54,24 @@ func (f *usmFeature) Configure(dda metav1.Object, ddaSpec *v2alpha1.DatadogAgent
5354
apicommon.CoreAgentContainerName,
5455
apicommon.SystemProbeContainerName,
5556
}
56-
if ddaSpec.Features.NPM == nil || !apiutils.BoolValue(ddaSpec.Features.NPM.DirectSend) {
57+
58+
directSendEnabled := ddaSpec.Features.NPM != nil && apiutils.BoolValue(ddaSpec.Features.NPM.DirectSend)
59+
const directSendMinVersion = "7.77.0-0"
60+
defaultIfVersionUnknown := false
61+
if !utils.IsAboveMinVersion(common.GetComponentVersion(dda, v2alpha1.NodeAgentComponentName), directSendMinVersion, &defaultIfVersionUnknown) {
62+
directSendEnabled = false
63+
}
64+
if !directSendEnabled {
5765
containers = append(containers, apicommon.ProcessAgentContainerName)
5866
}
67+
f.directSend = directSendEnabled
5968

6069
reqComp = feature.RequiredComponents{
6170
Agent: feature.RequiredComponent{
6271
IsRequired: ptr.To(true),
6372
Containers: containers,
6473
},
6574
}
66-
67-
if ddaSpec.Features.NPM != nil {
68-
f.directSend = apiutils.BoolValue(ddaSpec.Features.NPM.DirectSend)
69-
}
7075
}
7176

7277
return reqComp

internal/controller/datadogagent/feature/usm/feature_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ func Test_usmFeature_Configure(t *testing.T) {
3939
{
4040
ddaUSMEnabled.Spec.Features.USM.Enabled = ptr.To(true)
4141
}
42+
4243
ddaUSMDirectSendEnabled := ddaUSMEnabled.DeepCopy()
43-
{
44-
ddaUSMDirectSendEnabled.Spec.Features.NPM = &v2alpha1.NPMFeatureConfig{DirectSend: ptr.To(true)}
44+
ddaUSMDirectSendEnabled.Spec.Override = map[v2alpha1.ComponentName]*v2alpha1.DatadogAgentComponentOverride{
45+
v2alpha1.NodeAgentComponentName: {
46+
Image: &v2alpha1.AgentImageConfig{Tag: "7.77.0"},
47+
},
4548
}
49+
ddaUSMDirectSendEnabled.Spec.Features.NPM = &v2alpha1.NPMFeatureConfig{DirectSend: ptr.To(true)}
50+
51+
ddaUSMDirectSendEnabledUnsupportedAgentVersionConfig := ddaUSMDirectSendEnabled.DeepCopy()
52+
ddaUSMDirectSendEnabledUnsupportedAgentVersionConfig.Spec.Override[v2alpha1.NodeAgentComponentName].Image.Tag = "7.76.0"
4653

4754
usmAgentNodeWantFunc := func(t testing.TB, mgrInterface feature.PodTemplateManagers) {
4855
mgr := mgrInterface.(*fake.PodTemplateManagers)
@@ -226,6 +233,12 @@ func Test_usmFeature_Configure(t *testing.T) {
226233
WantConfigure: true,
227234
Agent: test.NewDefaultComponentTest().WithWantFunc(usmDirectSendNodeWantFunc),
228235
},
236+
{
237+
Name: "USM enabled, Direct Send enabled on unsupported agent version",
238+
DDA: ddaUSMDirectSendEnabledUnsupportedAgentVersionConfig,
239+
WantConfigure: true,
240+
Agent: test.NewDefaultComponentTest().WithWantFunc(usmAgentNodeWantFunc),
241+
},
229242
}
230243

231244
tests.Run(t, buildUSMFeature)

0 commit comments

Comments
 (0)