Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/datadoghq/v2alpha1/datadogagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ type USMFeatureConfig struct {
// ServiceDiscoveryFeatureConfig configures the service discovery check feature.
type ServiceDiscoveryFeatureConfig struct {
// Enables the service discovery check.
// Default: false
// Default: true when omitted and the node Agent image is >= 7.78.0. Otherwise false.
// If the image version cannot be determined, it is treated as latest.
// +optional
Enabled *bool `json:"enabled,omitempty"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2501,7 +2501,8 @@ spec:
enabled:
description: |-
Enables the service discovery check.
Default: false
Default: true when omitted and the node Agent image is >= 7.78.0. Otherwise false.
If the image version cannot be determined, it is treated as latest.
type: boolean
networkStats:
description: 'DEPRECATED: NetworkStats is no longer configurable and will be ignored. Scheduled for removal in v1.28.'
Expand Down Expand Up @@ -10933,7 +10934,8 @@ spec:
enabled:
description: |-
Enables the service discovery check.
Default: false
Default: true when omitted and the node Agent image is >= 7.78.0. Otherwise false.
If the image version cannot be determined, it is treated as latest.
type: boolean
networkStats:
description: 'DEPRECATED: NetworkStats is no longer configurable and will be ignored. Scheduled for removal in v1.28.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2600,7 +2600,7 @@
"description": "ServiceDiscovery",
"properties": {
"enabled": {
"description": "Enables the service discovery check.\nDefault: false",
"description": "Enables the service discovery check.\nDefault: true when omitted and the node Agent image is \u003e= 7.78.0. Otherwise false.\nIf the image version cannot be determined, it is treated as latest.",
"type": "boolean"
},
"networkStats": {
Expand Down Expand Up @@ -10769,7 +10769,7 @@
"description": "ServiceDiscovery",
"properties": {
"enabled": {
"description": "Enables the service discovery check.\nDefault: false",
"description": "Enables the service discovery check.\nDefault: true when omitted and the node Agent image is \u003e= 7.78.0. Otherwise false.\nIf the image version cannot be determined, it is treated as latest.",
"type": "boolean"
},
"networkStats": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2501,7 +2501,8 @@ spec:
enabled:
description: |-
Enables the service discovery check.
Default: false
Default: true when omitted and the node Agent image is >= 7.78.0. Otherwise false.
If the image version cannot be determined, it is treated as latest.
type: boolean
networkStats:
description: 'DEPRECATED: NetworkStats is no longer configurable and will be ignored. Scheduled for removal in v1.28.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2604,7 +2604,7 @@
"description": "ServiceDiscovery",
"properties": {
"enabled": {
"description": "Enables the service discovery check.\nDefault: false",
"description": "Enables the service discovery check.\nDefault: true when omitted and the node Agent image is \u003e= 7.78.0. Otherwise false.\nIf the image version cannot be determined, it is treated as latest.",
"type": "boolean"
},
"networkStats": {
Expand Down
6 changes: 4 additions & 2 deletions config/crd/bases/v1/datadoghq.com_datadogagents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2505,7 +2505,8 @@ spec:
enabled:
description: |-
Enables the service discovery check.
Default: false
Default: true when omitted and the node Agent image is >= 7.78.0. Otherwise false.
If the image version cannot be determined, it is treated as latest.
type: boolean
networkStats:
description: 'DEPRECATED: NetworkStats is no longer configurable and will be ignored. Scheduled for removal in v1.28.'
Expand Down Expand Up @@ -11013,7 +11014,8 @@ spec:
enabled:
description: |-
Enables the service discovery check.
Default: false
Default: true when omitted and the node Agent image is >= 7.78.0. Otherwise false.
If the image version cannot be determined, it is treated as latest.
type: boolean
networkStats:
description: 'DEPRECATED: NetworkStats is no longer configurable and will be ignored. Scheduled for removal in v1.28.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2600,7 +2600,7 @@
"description": "ServiceDiscovery",
"properties": {
"enabled": {
"description": "Enables the service discovery check.\nDefault: false",
"description": "Enables the service discovery check.\nDefault: true when omitted and the node Agent image is \u003e= 7.78.0. Otherwise false.\nIf the image version cannot be determined, it is treated as latest.",
"type": "boolean"
},
"networkStats": {
Expand Down Expand Up @@ -10862,7 +10862,7 @@
"description": "ServiceDiscovery",
"properties": {
"enabled": {
"description": "Enables the service discovery check.\nDefault: false",
"description": "Enables the service discovery check.\nDefault: true when omitted and the node Agent image is \u003e= 7.78.0. Otherwise false.\nIf the image version cannot be determined, it is treated as latest.",
"type": "boolean"
},
"networkStats": {
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.v2alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ spec:
| features.sbom.enabled | Enable this option to activate SBOM collection. Default: false |
| features.sbom.host.analyzers | To use for SBOM collection. |
| features.sbom.host.enabled | Enable this option to activate SBOM collection. Default: false |
| features.serviceDiscovery.enabled | Enables the service discovery check. Default: false |
| features.serviceDiscovery.enabled | Enables the service discovery check. Default: true when omitted and the node Agent image is >= 7.78.0. Otherwise false. If the image version cannot be determined, it is treated as latest. |
| features.serviceDiscovery.networkStats.enabled | DEPRECATED: this field is ignored. |
| features.tcpQueueLength.enabled | Enables the TCP queue length eBPF-based check. Default: false |
| features.usm.enabled | Enables Universal Service Monitoring. Default: false |
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration_public.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ spec:
: Enable this option to activate SBOM collection. Default: false

`features.serviceDiscovery.enabled`
: Enables the service discovery check. Default: false
: Enables the service discovery check. Default: true when omitted and the node Agent image is >= 7.78.0. Otherwise false. If the image version cannot be determined, it is treated as latest.

`features.serviceDiscovery.networkStats.enabled`
: DEPRECATED: this field is ignored.
Expand Down
173 changes: 173 additions & 0 deletions internal/controller/datadogagent/controller_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,106 @@ func TestReconcileDatadogAgentV2_Reconcile(t *testing.T) {
verifyDaemonsetContainers(t, c, resourcesNamespace, dsName, expectedContainers)
},
},
{
name: "DatadogAgent with service discovery omitted and supported node agent version auto-enables system-probe",
loadFunc: func(c client.Client) *v2alpha1.DatadogAgent {
dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName).
WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{
Image: &v2alpha1.AgentImageConfig{Tag: "7.78.0"},
}).
Build()
_ = c.Create(context.TODO(), dda)
return dda
},
want: reconcile.Result{RequeueAfter: defaultRequeueDuration},
wantErr: false,
wantFunc: func(t *testing.T, c client.Client) {
expectedContainers := []string{
string(apicommon.CoreAgentContainerName),
string(apicommon.TraceAgentContainerName),
string(apicommon.SystemProbeContainerName),
}

verifyDaemonsetContainers(t, c, resourcesNamespace, dsName, expectedContainers)

agentContainers := getDsContainers(c, resourcesNamespace, dsName)
assertContainerHasEnvVar(t, agentContainers[apicommon.CoreAgentContainerName], "DD_DISCOVERY_ENABLED", "true")
assertContainerHasEnvVar(t, agentContainers[apicommon.SystemProbeContainerName], common.DDSystemProbeSocket, common.DefaultSystemProbeSocketPath)
},
},
{
name: "DatadogAgent with service discovery omitted and unsupported node agent version keeps system-probe disabled",
loadFunc: func(c client.Client) *v2alpha1.DatadogAgent {
dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName).
WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{
Image: &v2alpha1.AgentImageConfig{Tag: "7.77.2"},
}).
Build()
_ = c.Create(context.TODO(), dda)
return dda
},
want: reconcile.Result{RequeueAfter: defaultRequeueDuration},
wantErr: false,
wantFunc: func(t *testing.T, c client.Client) {
expectedContainers := []string{
string(apicommon.CoreAgentContainerName),
string(apicommon.TraceAgentContainerName),
}

verifyDaemonsetContainers(t, c, resourcesNamespace, dsName, expectedContainers)
},
},
{
name: "DatadogAgent with service discovery explicitly disabled keeps system-probe disabled",
loadFunc: func(c client.Client) *v2alpha1.DatadogAgent {
dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName).
WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{
Image: &v2alpha1.AgentImageConfig{Tag: "7.78.0"},
}).
Build()
dda.Spec.Features.ServiceDiscovery = &v2alpha1.ServiceDiscoveryFeatureConfig{
Enabled: ptr.To(false),
}
_ = c.Create(context.TODO(), dda)
return dda
},
want: reconcile.Result{RequeueAfter: defaultRequeueDuration},
wantErr: false,
wantFunc: func(t *testing.T, c client.Client) {
expectedContainers := []string{
string(apicommon.CoreAgentContainerName),
string(apicommon.TraceAgentContainerName),
}

verifyDaemonsetContainers(t, c, resourcesNamespace, dsName, expectedContainers)
},
},
{
name: "DatadogAgent with service discovery explicitly enabled keeps system-probe enabled on unsupported node agent version",
loadFunc: func(c client.Client) *v2alpha1.DatadogAgent {
dda := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName).
WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{
Image: &v2alpha1.AgentImageConfig{Tag: "7.77.2"},
}).
Build()
dda.Spec.Features.ServiceDiscovery = &v2alpha1.ServiceDiscoveryFeatureConfig{
Enabled: ptr.To(true),
}
_ = c.Create(context.TODO(), dda)
return dda
},
want: reconcile.Result{RequeueAfter: defaultRequeueDuration},
wantErr: false,
wantFunc: func(t *testing.T, c client.Client) {
expectedContainers := []string{
string(apicommon.CoreAgentContainerName),
string(apicommon.TraceAgentContainerName),
string(apicommon.SystemProbeContainerName),
}

verifyDaemonsetContainers(t, c, resourcesNamespace, dsName, expectedContainers)
},
},
{
name: "DatadogAgent with Private Action Runner enabled on node, create Daemonset with core, trace, and private-action-runner containers",
loadFunc: func(c client.Client) *v2alpha1.DatadogAgent {
Expand Down Expand Up @@ -1126,6 +1226,19 @@ func getDeploymentContainers(c client.Client, resourcesNamespace, deploymentName
return containers
}

func assertContainerHasEnvVar(t *testing.T, container corev1.Container, name, value string) {
t.Helper()

for _, envVar := range container.Env {
if envVar.Name == name {
assert.Equal(t, value, envVar.Value)
return
}
}

t.Fatalf("env var %s not found in container %s", name, container.Name)
}

func Test_AutopilotOverrides(t *testing.T) {
const resourcesName, resourcesNamespace, dsName = "foo", "bar", "foo-agent"

Expand Down Expand Up @@ -1827,6 +1940,55 @@ func Test_DDAI_ReconcileV3(t *testing.T) {
verifyDDAI(t, c, []v1alpha1.DatadogAgentInternal{*expectedDDAI})
},
},
{
name: "[ddai] Auto-enable service discovery is propagated to DDAI on supported node agent version",
ddaiEnabled: true,
clientBuilder: fake.NewClientBuilder().
WithStatusSubresource(&v2alpha1.DatadogAgent{}, &v1alpha1.DatadogAgentProfile{}, &v1alpha1.DatadogAgentInternal{}),
loadFunc: func(c client.Client) *v2alpha1.DatadogAgent {
ddaSD := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName).
WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{
Image: &v2alpha1.AgentImageConfig{Tag: "7.78.0"},
}).
Build()
_ = c.Create(context.TODO(), ddaSD)
return ddaSD
},
want: reconcile.Result{RequeueAfter: defaultRequeueDuration},
wantErr: false,
wantFunc: func(t *testing.T, c client.Client) {
ddai := getSingleDDAI(t, c)
assert.NotNil(t, ddai.Spec.Features.ServiceDiscovery)
assert.NotNil(t, ddai.Spec.Features.ServiceDiscovery.Enabled)
assert.True(t, *ddai.Spec.Features.ServiceDiscovery.Enabled)
},
},
{
name: "[ddai] Explicitly disabled service discovery remains disabled in DDAI",
ddaiEnabled: true,
clientBuilder: fake.NewClientBuilder().
WithStatusSubresource(&v2alpha1.DatadogAgent{}, &v1alpha1.DatadogAgentProfile{}, &v1alpha1.DatadogAgentInternal{}),
loadFunc: func(c client.Client) *v2alpha1.DatadogAgent {
ddaSD := testutils.NewInitializedDatadogAgentBuilder(resourcesNamespace, resourcesName).
WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{
Image: &v2alpha1.AgentImageConfig{Tag: "7.78.0"},
}).
Build()
ddaSD.Spec.Features.ServiceDiscovery = &v2alpha1.ServiceDiscoveryFeatureConfig{
Enabled: ptr.To(false),
}
_ = c.Create(context.TODO(), ddaSD)
return ddaSD
},
want: reconcile.Result{RequeueAfter: defaultRequeueDuration},
wantErr: false,
wantFunc: func(t *testing.T, c client.Client) {
ddai := getSingleDDAI(t, c)
assert.NotNil(t, ddai.Spec.Features.ServiceDiscovery)
assert.NotNil(t, ddai.Spec.Features.ServiceDiscovery.Enabled)
assert.False(t, *ddai.Spec.Features.ServiceDiscovery.Enabled)
},
},
{
name: "[ddai] Create DDAI from minimal DDA and default profile",
ddaiEnabled: true,
Expand Down Expand Up @@ -2040,6 +2202,17 @@ func verifyDDAI(t *testing.T, c client.Client, expectedDDAI []v1alpha1.DatadogAg
assert.ElementsMatch(t, expectedDDAI, ddaiList.Items, "DDAI resources don't match")
}

func getSingleDDAI(t *testing.T, c client.Client) v1alpha1.DatadogAgentInternal {
t.Helper()

ddaiList := v1alpha1.DatadogAgentInternalList{}
err := c.List(context.TODO(), &ddaiList)
assert.NoError(t, err, "Failed to list DatadogAgentInternal resources")
assert.Len(t, ddaiList.Items, 1, "Expected exactly one DatadogAgentInternal resource")

return ddaiList.Items[0]
}

func getBaseDDAI(dda *v2alpha1.DatadogAgent) v1alpha1.DatadogAgentInternal {
expectedDDAI := v1alpha1.DatadogAgentInternal{
ObjectMeta: metav1.ObjectMeta{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
apiutils "github.com/DataDog/datadog-operator/api/utils"
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/common"
"github.com/DataDog/datadog-operator/pkg/images"
pkgutils "github.com/DataDog/datadog-operator/pkg/utils"
)

// Default configuration values. These are the recommended settings for monitoring with Datadog in Kubernetes.
Expand Down Expand Up @@ -43,7 +44,8 @@ const (

defaultGPUMonitoringEnabled bool = false

defaultServiceDiscoveryEnabled bool = false
defaultServiceDiscoveryEnabled bool = false
serviceDiscoveryAutoEnableMinVersion = "7.78.0-0"

defaultAPMEnabled bool = true
defaultAPMHostPortEnabled bool = false
Expand Down Expand Up @@ -304,7 +306,9 @@ func defaultFeaturesConfig(ddaSpec *v2alpha1.DatadogAgentSpec) {
if ddaSpec.Features.ServiceDiscovery == nil {
ddaSpec.Features.ServiceDiscovery = &v2alpha1.ServiceDiscoveryFeatureConfig{}
}
apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.ServiceDiscovery.Enabled, defaultServiceDiscoveryEnabled)
if ddaSpec.Features.ServiceDiscovery.Enabled == nil {
ddaSpec.Features.ServiceDiscovery.Enabled = ptr.To(shouldEnableServiceDiscoveryByDefault(ddaSpec))
}

// GPU monitoring feature
if ddaSpec.Features.GPU == nil {
Expand Down Expand Up @@ -648,3 +652,15 @@ func defaultFeaturesConfig(ddaSpec *v2alpha1.DatadogAgentSpec) {
}
apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.DataPlane.Dogstatsd.Enabled, defaultDataPlaneDogstatsdEnabled)
}

func shouldEnableServiceDiscoveryByDefault(ddaSpec *v2alpha1.DatadogAgentSpec) bool {
fallback := ptr.To(true)

if ddaSpec.Override != nil {
if nodeAgent, found := ddaSpec.Override[v2alpha1.NodeAgentComponentName]; found && nodeAgent != nil && nodeAgent.Image != nil {
return pkgutils.IsAboveMinVersion(common.GetAgentVersionFromImage(*nodeAgent.Image), serviceDiscoveryAutoEnableMinVersion, fallback)
Comment thread
Yumasi marked this conversation as resolved.
Outdated
}
}

return pkgutils.IsAboveMinVersion(images.AgentLatestVersion, serviceDiscoveryAutoEnableMinVersion, fallback)
}
Loading
Loading