@@ -168,6 +168,11 @@ func (d Daemonset) WithHostNetwork(enabled bool) Daemonset {
168168 return d
169169}
170170
171+ func (d Daemonset ) WithDNSPolicy (policy corev1.DNSPolicy ) Daemonset {
172+ d .Spec .Template .Spec .DNSPolicy = policy
173+ return d
174+ }
175+
171176func (d Daemonset ) WithHostPID (enabled bool ) Daemonset {
172177 d .Spec .Template .Spec .HostPID = enabled
173178 return d
@@ -1272,6 +1277,133 @@ func TestTransformDCGMExporter(t *testing.T) {
12721277 },
12731278 }).WithContainer (corev1.Container {Name : "dummy" }).WithPullSecret ("pull-secret" ).WithRuntimeClassName ("nvidia" ).WithHostPID (false ),
12741279 },
1280+ {
1281+ description : "transform dcgm exporter with hostNetwork enabled" ,
1282+ ds : NewDaemonset ().
1283+ WithContainer (corev1.Container {Name : "dcgm-exporter" }).
1284+ WithContainer (corev1.Container {Name : "dummy" }),
1285+ cpSpec : & gpuv1.ClusterPolicySpec {
1286+ DCGMExporter : gpuv1.DCGMExporterSpec {
1287+ Repository : "nvcr.io/nvidia/cloud-native" ,
1288+ Image : "dcgm-exporter" ,
1289+ Version : "v1.0.0" ,
1290+ ImagePullPolicy : "IfNotPresent" ,
1291+ ImagePullSecrets : []string {"pull-secret" },
1292+ Args : []string {"--fail-on-init-error=false" },
1293+ HostNetwork : newBoolPtr (true ),
1294+ Env : []gpuv1.EnvVar {
1295+ {Name : "foo" , Value : "bar" },
1296+ {Name : "DCGM_REMOTE_HOSTENGINE_INFO" , Value : "nvidia-dcgm:5555" },
1297+ },
1298+ },
1299+ },
1300+ expectedDs : NewDaemonset ().WithContainer (corev1.Container {
1301+ Name : "dcgm-exporter" ,
1302+ Image : "nvcr.io/nvidia/cloud-native/dcgm-exporter:v1.0.0" ,
1303+ ImagePullPolicy : corev1 .PullIfNotPresent ,
1304+ Args : []string {"--fail-on-init-error=false" },
1305+ Env : []corev1.EnvVar {
1306+ {Name : "DCGM_REMOTE_HOSTENGINE_INFO" , Value : "nvidia-dcgm:5555" },
1307+ {Name : "foo" , Value : "bar" },
1308+ },
1309+ }).WithContainer (corev1.Container {Name : "dummy" }).WithPullSecret ("pull-secret" ).WithRuntimeClassName ("nvidia" ).WithHostNetwork (true ).WithDNSPolicy (corev1 .DNSClusterFirstWithHostNet ),
1310+ },
1311+ {
1312+ description : "transform dcgm exporter with hostNetwork disabled" ,
1313+ ds : NewDaemonset ().
1314+ WithContainer (corev1.Container {Name : "dcgm-exporter" }).
1315+ WithContainer (corev1.Container {Name : "dummy" }),
1316+ cpSpec : & gpuv1.ClusterPolicySpec {
1317+ DCGMExporter : gpuv1.DCGMExporterSpec {
1318+ Repository : "nvcr.io/nvidia/cloud-native" ,
1319+ Image : "dcgm-exporter" ,
1320+ Version : "v1.0.0" ,
1321+ ImagePullPolicy : "IfNotPresent" ,
1322+ ImagePullSecrets : []string {"pull-secret" },
1323+ Args : []string {"--fail-on-init-error=false" },
1324+ HostNetwork : newBoolPtr (false ),
1325+ Env : []gpuv1.EnvVar {
1326+ {Name : "foo" , Value : "bar" },
1327+ },
1328+ },
1329+ },
1330+ expectedDs : NewDaemonset ().WithContainer (corev1.Container {
1331+ Name : "dcgm-exporter" ,
1332+ Image : "nvcr.io/nvidia/cloud-native/dcgm-exporter:v1.0.0" ,
1333+ ImagePullPolicy : corev1 .PullIfNotPresent ,
1334+ Args : []string {"--fail-on-init-error=false" },
1335+ Env : []corev1.EnvVar {
1336+ {Name : "DCGM_REMOTE_HOSTENGINE_INFO" , Value : "nvidia-dcgm:5555" },
1337+ {Name : "foo" , Value : "bar" },
1338+ },
1339+ }).WithContainer (corev1.Container {Name : "dummy" }).WithPullSecret ("pull-secret" ).WithRuntimeClassName ("nvidia" ).WithHostNetwork (false ),
1340+ },
1341+ {
1342+ description : "transform dcgm exporter with hostNetwork unspecified" ,
1343+ ds : NewDaemonset ().
1344+ WithContainer (corev1.Container {Name : "dcgm-exporter" }).
1345+ WithContainer (corev1.Container {Name : "dummy" }),
1346+ cpSpec : & gpuv1.ClusterPolicySpec {
1347+ DCGMExporter : gpuv1.DCGMExporterSpec {
1348+ Repository : "nvcr.io/nvidia/cloud-native" ,
1349+ Image : "dcgm-exporter" ,
1350+ Version : "v1.0.0" ,
1351+ ImagePullPolicy : "IfNotPresent" ,
1352+ ImagePullSecrets : []string {"pull-secret" },
1353+ Args : []string {"--fail-on-init-error=false" },
1354+ Env : []gpuv1.EnvVar {
1355+ {Name : "DCGM_REMOTE_HOSTENGINE_INFO" , Value : "localhost:5555" },
1356+ {Name : "foo" , Value : "bar" },
1357+ },
1358+ },
1359+ },
1360+ expectedDs : NewDaemonset ().WithContainer (corev1.Container {
1361+ Name : "dcgm-exporter" ,
1362+ Image : "nvcr.io/nvidia/cloud-native/dcgm-exporter:v1.0.0" ,
1363+ ImagePullPolicy : corev1 .PullIfNotPresent ,
1364+ Args : []string {"--fail-on-init-error=false" },
1365+ Env : []corev1.EnvVar {
1366+ {Name : "DCGM_REMOTE_HOSTENGINE_INFO" , Value : "localhost:5555" },
1367+ {Name : "foo" , Value : "bar" },
1368+ },
1369+ }).WithContainer (corev1.Container {Name : "dummy" }).WithPullSecret ("pull-secret" ).WithRuntimeClassName ("nvidia" ).WithHostNetwork (false ),
1370+ },
1371+ {
1372+ description : "transform dcgm exporter with dcgm running on the host itself(DGX BaseOS)" ,
1373+ ds : NewDaemonset ().
1374+ WithContainer (corev1.Container {
1375+ Name : "dcgm-exporter" ,
1376+ Env : []corev1.EnvVar {{Name : "DCGM_REMOTE_HOSTENGINE_INFO" , Value : "localhost:5555" }},
1377+ }).
1378+ WithContainer (corev1.Container {Name : "dummy" }),
1379+ cpSpec : & gpuv1.ClusterPolicySpec {
1380+ DCGM : gpuv1.DCGMSpec {
1381+ Enabled : newBoolPtr (false ),
1382+ },
1383+ DCGMExporter : gpuv1.DCGMExporterSpec {
1384+ Repository : "nvcr.io/nvidia/cloud-native" ,
1385+ Image : "dcgm-exporter" ,
1386+ Version : "v1.0.0" ,
1387+ ImagePullPolicy : "IfNotPresent" ,
1388+ ImagePullSecrets : []string {"pull-secret" },
1389+ Args : []string {"--fail-on-init-error=false" },
1390+ Env : []gpuv1.EnvVar {
1391+ {Name : "DCGM_REMOTE_HOSTENGINE_INFO" , Value : "localhost:5555" },
1392+ {Name : "foo" , Value : "bar" },
1393+ },
1394+ },
1395+ },
1396+ expectedDs : NewDaemonset ().WithContainer (corev1.Container {
1397+ Name : "dcgm-exporter" ,
1398+ Image : "nvcr.io/nvidia/cloud-native/dcgm-exporter:v1.0.0" ,
1399+ ImagePullPolicy : corev1 .PullIfNotPresent ,
1400+ Args : []string {"--fail-on-init-error=false" },
1401+ Env : []corev1.EnvVar {
1402+ {Name : "DCGM_REMOTE_HOSTENGINE_INFO" , Value : "localhost:5555" },
1403+ {Name : "foo" , Value : "bar" },
1404+ },
1405+ }).WithContainer (corev1.Container {Name : "dummy" }).WithPullSecret ("pull-secret" ).WithRuntimeClassName ("nvidia" ).WithHostNetwork (true ).WithDNSPolicy (corev1 .DNSClusterFirstWithHostNet ),
1406+ },
12751407 {
12761408 description : "transform dcgm exporter, openshift" ,
12771409 openshiftVersion : "1.0.0" ,
0 commit comments