@@ -88,6 +88,11 @@ func NewDaemonset() Daemonset {
8888 return Daemonset {ds }
8989}
9090
91+ func (d Daemonset ) WithAnnotations (annotations map [string ]string ) Daemonset {
92+ d .Annotations = annotations
93+ return d
94+ }
95+
9196func (d Daemonset ) WithHostPathVolume (name string , path string , hostPathType * corev1.HostPathType ) Daemonset {
9297 volume := corev1.Volume {
9398 Name : name ,
@@ -1512,6 +1517,101 @@ func TestTransformDCGMExporter(t *testing.T) {
15121517 WithRuntimeClassName ("nvidia" ).
15131518 WithHostPathVolume ("hpc-job-mapping" , "/run/nvidia/dcgm-job-mapping" , ptr .To (corev1 .HostPathDirectoryOrCreate )),
15141519 },
1520+ {
1521+ description : "transform dcgm exporter with extra annotations adds it at pod template level" ,
1522+ ds : NewDaemonset ().
1523+ WithContainer (corev1.Container {Name : "dcgm-exporter" }),
1524+ cpSpec : & gpuv1.ClusterPolicySpec {
1525+ DCGMExporter : gpuv1.DCGMExporterSpec {
1526+ Repository : "nvcr.io/nvidia/k8s" ,
1527+ Image : "dcgm-exporter" ,
1528+ Version : "v1.0.0" ,
1529+ Annotations : map [string ]string {
1530+ "prometheus.io/scrape" : "true" ,
1531+ "prometheus.io/port" : "8080" ,
1532+ "prometheus.io/path" : "/metrics" ,
1533+ },
1534+ },
1535+ },
1536+ expectedDs : NewDaemonset ().
1537+ WithPodAnnotations (map [string ]string {
1538+ "prometheus.io/scrape" : "true" ,
1539+ "prometheus.io/port" : "8080" ,
1540+ "prometheus.io/path" : "/metrics" ,
1541+ }).
1542+ WithContainer (corev1.Container {
1543+ Name : "dcgm-exporter" ,
1544+ Image : "nvcr.io/nvidia/k8s/dcgm-exporter:v1.0.0" ,
1545+ ImagePullPolicy : corev1 .PullIfNotPresent ,
1546+ Env : []corev1.EnvVar {
1547+ {Name : "DCGM_REMOTE_HOSTENGINE_INFO" , Value : "nvidia-dcgm:5555" },
1548+ },
1549+ }).
1550+ WithRuntimeClassName ("nvidia" ),
1551+ },
1552+ {
1553+ description : "transform dcgm exporter appends extra annotations to existing ones at pod template level" ,
1554+ ds : NewDaemonset ().
1555+ WithPodAnnotations (map [string ]string {
1556+ "foo" : "bar" ,
1557+ }).
1558+ WithContainer (corev1.Container {Name : "dcgm-exporter" }),
1559+ cpSpec : & gpuv1.ClusterPolicySpec {
1560+ DCGMExporter : gpuv1.DCGMExporterSpec {
1561+ Repository : "nvcr.io/nvidia/k8s" ,
1562+ Image : "dcgm-exporter" ,
1563+ Version : "v1.0.0" ,
1564+ Annotations : map [string ]string {
1565+ "prometheus.io/scrape" : "true" ,
1566+ },
1567+ },
1568+ },
1569+ expectedDs : NewDaemonset ().
1570+ WithPodAnnotations (map [string ]string {
1571+ "foo" : "bar" ,
1572+ "prometheus.io/scrape" : "true" ,
1573+ }).
1574+ WithContainer (corev1.Container {
1575+ Name : "dcgm-exporter" ,
1576+ Image : "nvcr.io/nvidia/k8s/dcgm-exporter:v1.0.0" ,
1577+ ImagePullPolicy : corev1 .PullIfNotPresent ,
1578+ Env : []corev1.EnvVar {
1579+ {Name : "DCGM_REMOTE_HOSTENGINE_INFO" , Value : "nvidia-dcgm:5555" },
1580+ },
1581+ }).
1582+ WithRuntimeClassName ("nvidia" ),
1583+ },
1584+ {
1585+ description : "transform dcgm exporter overrides annotation with same key at pod template level" ,
1586+ ds : NewDaemonset ().
1587+ WithPodAnnotations (map [string ]string {
1588+ "foo" : "bar" ,
1589+ }).
1590+ WithContainer (corev1.Container {Name : "dcgm-exporter" }),
1591+ cpSpec : & gpuv1.ClusterPolicySpec {
1592+ DCGMExporter : gpuv1.DCGMExporterSpec {
1593+ Repository : "nvcr.io/nvidia/k8s" ,
1594+ Image : "dcgm-exporter" ,
1595+ Version : "v1.0.0" ,
1596+ Annotations : map [string ]string {
1597+ "foo" : "baz" ,
1598+ },
1599+ },
1600+ },
1601+ expectedDs : NewDaemonset ().
1602+ WithPodAnnotations (map [string ]string {
1603+ "foo" : "baz" ,
1604+ }).
1605+ WithContainer (corev1.Container {
1606+ Name : "dcgm-exporter" ,
1607+ Image : "nvcr.io/nvidia/k8s/dcgm-exporter:v1.0.0" ,
1608+ ImagePullPolicy : corev1 .PullIfNotPresent ,
1609+ Env : []corev1.EnvVar {
1610+ {Name : "DCGM_REMOTE_HOSTENGINE_INFO" , Value : "nvidia-dcgm:5555" },
1611+ },
1612+ }).
1613+ WithRuntimeClassName ("nvidia" ),
1614+ },
15151615 }
15161616
15171617 for _ , tc := range testCases {
0 commit comments