@@ -1380,6 +1380,157 @@ func Test_AutopilotOverrides(t *testing.T) {
13801380 runTestCases (t , tests , runFullReconcilerTest )
13811381}
13821382
1383+ // Test_COSProviderOverrides verifies that the GKE COS provider strips the
1384+ // `src` HostPath volume (and its system-probe mount) that oomkill and
1385+ // tcpqueuelength would otherwise add — the host has no /usr/src on COS nodes.
1386+ // The provider value flows from the DDA's `datadoghq.com/provider` annotation,
1387+ // or from the DAP's annotation propagated onto the per-profile DDAI.
1388+ func Test_COSProviderOverrides (t * testing.T ) {
1389+ const resourcesName , resourcesNamespace = "foo" , "bar"
1390+ const defaultDsName = "foo-agent"
1391+ const profileName = "cos-profile"
1392+ const profileDsName = "cos-profile-agent"
1393+
1394+ defaultRequeueDuration := 15 * time .Second
1395+
1396+ cosProfile := & v1alpha1.DatadogAgentProfile {
1397+ ObjectMeta : metav1.ObjectMeta {
1398+ Name : profileName ,
1399+ Namespace : resourcesNamespace ,
1400+ Annotations : map [string ]string {
1401+ kubernetes .ProviderAnnotationKey : kubernetes .GKECosProvider ,
1402+ },
1403+ },
1404+ Spec : v1alpha1.DatadogAgentProfileSpec {
1405+ ProfileAffinity : & v1alpha1.ProfileAffinity {
1406+ ProfileNodeAffinity : []corev1.NodeSelectorRequirement {
1407+ {
1408+ Key : "foo" ,
1409+ Operator : corev1 .NodeSelectorOpIn ,
1410+ Values : []string {"cos-profile" },
1411+ },
1412+ },
1413+ },
1414+ // Config is required by the DAP webhook validator. We don't need
1415+ // any spec changes — the COS provider is signalled via the
1416+ // metadata.annotations propagated to the DDAI.
1417+ Config : & v2alpha1.DatadogAgentSpec {},
1418+ },
1419+ }
1420+
1421+ // assertVolumes asserts the modules volume is always present (oomkill +
1422+ // tcpqueuelength add it unconditionally) and the src volume is present iff
1423+ // wantSrc is true.
1424+ assertVolumes := func (t * testing.T , c client.Client , ns , name string , wantSrc bool ) {
1425+ t .Helper ()
1426+ ds := & appsv1.DaemonSet {}
1427+ err := c .Get (context .TODO (), types.NamespacedName {Namespace : ns , Name : name }, ds )
1428+ assert .NoError (t , err , "Failed to get DaemonSet %s/%s" , ns , name )
1429+
1430+ var sp * corev1.Container
1431+ for i , ctn := range ds .Spec .Template .Spec .Containers {
1432+ if ctn .Name == string (apicommon .SystemProbeContainerName ) {
1433+ sp = & ds .Spec .Template .Spec .Containers [i ]
1434+ break
1435+ }
1436+ }
1437+ assert .NotNil (t , sp , "system-probe container not found on DaemonSet %s/%s" , ns , name )
1438+
1439+ hasModulesMount , hasSrcMount := false , false
1440+ for _ , m := range sp .VolumeMounts {
1441+ if m .Name == common .ModulesVolumeName {
1442+ hasModulesMount = true
1443+ }
1444+ if m .Name == common .SrcVolumeName {
1445+ hasSrcMount = true
1446+ }
1447+ }
1448+ assert .True (t , hasModulesMount , "system-probe modules volume mount missing on %s/%s" , ns , name )
1449+ assert .Equal (t , wantSrc , hasSrcMount , "system-probe src volume mount: want=%v got=%v on %s/%s" , wantSrc , hasSrcMount , ns , name )
1450+
1451+ hasModulesVol , hasSrcVol := false , false
1452+ for _ , v := range ds .Spec .Template .Spec .Volumes {
1453+ if v .Name == common .ModulesVolumeName {
1454+ hasModulesVol = true
1455+ }
1456+ if v .Name == common .SrcVolumeName {
1457+ hasSrcVol = true
1458+ }
1459+ }
1460+ assert .True (t , hasModulesVol , "pod-level modules volume missing on %s/%s" , ns , name )
1461+ assert .Equal (t , wantSrc , hasSrcVol , "pod-level src volume: want=%v got=%v on %s/%s" , wantSrc , hasSrcVol , ns , name )
1462+ }
1463+
1464+ // buildDDA returns a DDA with oomkill + tcpqueuelength enabled. Caller
1465+ // may layer annotations via opts.
1466+ buildDDA := func (annotations map [string ]string ) * v2alpha1.DatadogAgent {
1467+ b := testutils .NewInitializedDatadogAgentBuilder (resourcesNamespace , resourcesName ).
1468+ WithOOMKillEnabled (true )
1469+ if len (annotations ) > 0 {
1470+ b = b .WithAnnotations (annotations )
1471+ }
1472+ dda := b .Build ()
1473+ dda .Spec .Features .TCPQueueLength = & v2alpha1.TCPQueueLengthFeatureConfig {
1474+ Enabled : ptr .To (true ),
1475+ }
1476+ return dda
1477+ }
1478+
1479+ tests := []testCase {
1480+ {
1481+ name : "[cos] baseline DDA no annotation: src volume present on default DS" ,
1482+ loadFunc : func (c client.Client ) * v2alpha1.DatadogAgent {
1483+ dda := buildDDA (nil )
1484+ _ = c .Create (context .TODO (), dda )
1485+ return dda
1486+ },
1487+ want : reconcile.Result {RequeueAfter : defaultRequeueDuration },
1488+ wantErr : false ,
1489+ wantFunc : func (t * testing.T , c client.Client ) {
1490+ assertVolumes (t , c , resourcesNamespace , defaultDsName , true )
1491+ },
1492+ },
1493+ {
1494+ name : "[cos] DDA with gke-cos annotation strips src volume on default DS" ,
1495+ loadFunc : func (c client.Client ) * v2alpha1.DatadogAgent {
1496+ dda := buildDDA (map [string ]string {
1497+ kubernetes .ProviderAnnotationKey : kubernetes .GKECosProvider ,
1498+ })
1499+ _ = c .Create (context .TODO (), dda )
1500+ return dda
1501+ },
1502+ want : reconcile.Result {RequeueAfter : defaultRequeueDuration },
1503+ wantErr : false ,
1504+ wantFunc : func (t * testing.T , c client.Client ) {
1505+ assertVolumes (t , c , resourcesNamespace , defaultDsName , false )
1506+ },
1507+ },
1508+ {
1509+ name : "[cos] DDA without annotation, DAP with gke-cos strips src on profile DS only" ,
1510+ clientBuilder : fake .NewClientBuilder ().
1511+ WithStatusSubresource (& v2alpha1.DatadogAgent {}, & v1alpha1.DatadogAgentProfile {}, & v1alpha1.DatadogAgentInternal {}).
1512+ WithObjects (cosProfile ),
1513+ loadFunc : func (c client.Client ) * v2alpha1.DatadogAgent {
1514+ dda := buildDDA (nil )
1515+ _ = c .Create (context .TODO (), dda )
1516+ return dda
1517+ },
1518+ profile : cosProfile ,
1519+ profilesEnabled : true ,
1520+ want : reconcile.Result {RequeueAfter : defaultRequeueDuration },
1521+ wantErr : false ,
1522+ wantFunc : func (t * testing.T , c client.Client ) {
1523+ // Profile DDAI inherited the DAP's COS annotation → src stripped.
1524+ assertVolumes (t , c , resourcesNamespace , profileDsName , false )
1525+ // Default DDAI has no provider annotation → src present.
1526+ assertVolumes (t , c , resourcesNamespace , defaultDsName , true )
1527+ },
1528+ },
1529+ }
1530+
1531+ runTestCases (t , tests , runFullReconcilerTest )
1532+ }
1533+
13831534func verifyDaemonsetContainers (t * testing.T , c client.Client , resourcesNamespace , dsName string , expectedContainers []string ) {
13841535 ds := & appsv1.DaemonSet {}
13851536 err := c .Get (context .TODO (), types.NamespacedName {Namespace : resourcesNamespace , Name : dsName }, ds )
0 commit comments