@@ -974,6 +974,14 @@ func getDCGMExporterTestInput(testCase string) *gpuv1.ClusterPolicy {
974974 case "standalone-dcgm" :
975975 dcgmEnabled := true
976976 cp .Spec .DCGM .Enabled = & dcgmEnabled
977+ case "podLabelsAndAnnotations" :
978+ cp .Spec .DCGMExporter .PodAnnotations = map [string ]string {
979+ "prometheus.io/scrape" : "true" ,
980+ "prometheus.io/port" : "9400" ,
981+ }
982+ cp .Spec .DCGMExporter .PodLabels = map [string ]string {
983+ "team" : "test" ,
984+ }
977985 default :
978986 return nil
979987 }
@@ -989,15 +997,25 @@ func getDCGMExporterTestOutput(testCase string) map[string]interface{} {
989997 "numDaemonsets" : 1 ,
990998 "dcgmExporterImage" : "nvcr.io/nvidia/k8s/dcgm-exporter:3.3.0-3.2.0-ubuntu22.04" ,
991999 "imagePullSecret" : "ngc-secret" ,
1000+ "env" : map [string ]string {},
1001+ "podLabels" : map [string ]string {},
1002+ "podAnnotations" : map [string ]string {},
9921003 }
9931004
9941005 switch testCase {
9951006 case "default" :
996- output ["env" ] = map [string ]string {}
9971007 case "standalone-dcgm" :
9981008 output ["env" ] = map [string ]string {
9991009 "DCGM_REMOTE_HOSTENGINE_INFO" : "nvidia-dcgm:5555" ,
10001010 }
1011+ case "podLabelsAndAnnotations" :
1012+ output ["podLabels" ] = map [string ]string {
1013+ "team" : "test" ,
1014+ }
1015+ output ["podAnnotations" ] = map [string ]string {
1016+ "prometheus.io/scrape" : "true" ,
1017+ "prometheus.io/port" : "9400" ,
1018+ }
10011019 default :
10021020 return nil
10031021 }
@@ -1023,6 +1041,11 @@ func TestDCGMExporter(t *testing.T) {
10231041 getDCGMExporterTestInput ("standalone-dcgm" ),
10241042 getDCGMExporterTestOutput ("standalone-dcgm" ),
10251043 },
1044+ {
1045+ "podLabelsAndAnnotations" ,
1046+ getDCGMExporterTestInput ("podLabelsAndAnnotations" ),
1047+ getDCGMExporterTestOutput ("podLabelsAndAnnotations" ),
1048+ },
10261049 }
10271050
10281051 for _ , tc := range testCases {
@@ -1053,6 +1076,18 @@ func TestDCGMExporter(t *testing.T) {
10531076 t .Fatalf ("Expected env is not set for daemonset nvidia-dcgm-exporter %s->%s" , key , value )
10541077 }
10551078 }
1079+ for key , value := range tc .output ["podLabels" ].(map [string ]string ) {
1080+ objLabelvalue , ok := ds .Spec .Template .Labels [key ]
1081+ if ! ok || objLabelvalue != value {
1082+ t .Fatalf ("Expected label is not set for daemonset nvidia-dcgm-exporter %s->%s" , key , value )
1083+ }
1084+ }
1085+ for key , value := range tc .output ["podAnnotations" ].(map [string ]string ) {
1086+ objAnnotationValue , ok := ds .Spec .Template .Annotations [key ]
1087+ if ! ok || objAnnotationValue != value {
1088+ t .Fatalf ("Expected annotation is not set for daemonset nvidia-dcgm-exporter %s->%s" , key , value )
1089+ }
1090+ }
10561091
10571092 require .Equal (t , tc .output ["dcgmExporterImage" ], dcgmExporterImage , "Unexpected configuration for dcgm-exporter image" )
10581093
0 commit comments