@@ -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,78 @@ 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" ,
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+ WithAnnotations (map [string ]string {
1538+ "prometheus.io/scrape" : "true" ,
1539+ "prometheus.io/port" : "8080" ,
1540+ "prometheus.io/path" : "/metrics" ,
1541+ }).
1542+ WithPodAnnotations (map [string ]string {
1543+ "prometheus.io/scrape" : "true" ,
1544+ "prometheus.io/port" : "8080" ,
1545+ "prometheus.io/path" : "/metrics" ,
1546+ }).
1547+ WithContainer (corev1.Container {
1548+ Name : "dcgm-exporter" ,
1549+ Image : "nvcr.io/nvidia/k8s/dcgm-exporter:v1.0.0" ,
1550+ ImagePullPolicy : corev1 .PullIfNotPresent ,
1551+ Env : []corev1.EnvVar {
1552+ {Name : "DCGM_REMOTE_HOSTENGINE_INFO" , Value : "nvidia-dcgm:5555" },
1553+ },
1554+ }).
1555+ WithRuntimeClassName ("nvidia" ),
1556+ },
1557+ {
1558+ description : "transform dcgm exporter appends extra annotations to existing ones" ,
1559+ ds : NewDaemonset ().
1560+ WithAnnotations (map [string ]string {
1561+ "existing-key" : "existing-value" ,
1562+ }).
1563+ WithContainer (corev1.Container {Name : "dcgm-exporter" }),
1564+ cpSpec : & gpuv1.ClusterPolicySpec {
1565+ DCGMExporter : gpuv1.DCGMExporterSpec {
1566+ Repository : "nvcr.io/nvidia/k8s" ,
1567+ Image : "dcgm-exporter" ,
1568+ Version : "v1.0.0" ,
1569+ Annotations : map [string ]string {
1570+ "prometheus.io/scrape" : "true" ,
1571+ },
1572+ },
1573+ },
1574+ expectedDs : NewDaemonset ().
1575+ WithAnnotations (map [string ]string {
1576+ "existing-key" : "existing-value" ,
1577+ "prometheus.io/scrape" : "true" ,
1578+ }).
1579+ WithPodAnnotations (map [string ]string {
1580+ "prometheus.io/scrape" : "true" ,
1581+ }).
1582+ WithContainer (corev1.Container {
1583+ Name : "dcgm-exporter" ,
1584+ Image : "nvcr.io/nvidia/k8s/dcgm-exporter:v1.0.0" ,
1585+ ImagePullPolicy : corev1 .PullIfNotPresent ,
1586+ Env : []corev1.EnvVar {
1587+ {Name : "DCGM_REMOTE_HOSTENGINE_INFO" , Value : "nvidia-dcgm:5555" },
1588+ },
1589+ }).
1590+ WithRuntimeClassName ("nvidia" ),
1591+ },
15151592 }
15161593
15171594 for _ , tc := range testCases {
0 commit comments