Skip to content

Commit c2e0c1f

Browse files
committed
feat(dcgm-exporter): adding annotation property specific to the exporter daemonset
Signed-off-by: Julien Klaer <klaer.julien@gmail.com>
1 parent afda1f7 commit c2e0c1f

9 files changed

Lines changed: 136 additions & 0 deletions

File tree

api/nvidia/v1/clusterpolicy_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,11 @@ type DCGMExporterSpec struct {
970970
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:advanced,urn:alm:descriptor:com.tectonic.ui:text"
971971
Args []string `json:"args,omitempty"`
972972

973+
// Optional: Annotations is an unstructured key value map stored with a resource that may be
974+
// set by external tools to store and retrieve arbitrary metadata. They are not
975+
// queryable and should be preserved when modifying objects.
976+
Annotations map[string]string `json:"annotations,omitempty"`
977+
973978
// Optional: List of environment variables
974979
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
975980
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Environment Variables"

api/nvidia/v1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/manifests/nvidia.com_clusterpolicies.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,14 @@ spec:
553553
dcgmExporter:
554554
description: DCGMExporter spec
555555
properties:
556+
annotations:
557+
additionalProperties:
558+
type: string
559+
description: |-
560+
Optional: Annotations is an unstructured key value map stored with a resource that may be
561+
set by external tools to store and retrieve arbitrary metadata. They are not
562+
queryable and should be preserved when modifying objects.
563+
type: object
556564
args:
557565
description: 'Optional: List of arguments'
558566
items:

config/crd/bases/nvidia.com_clusterpolicies.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,14 @@ spec:
553553
dcgmExporter:
554554
description: DCGMExporter spec
555555
properties:
556+
annotations:
557+
additionalProperties:
558+
type: string
559+
description: |-
560+
Optional: Annotations is an unstructured key value map stored with a resource that may be
561+
set by external tools to store and retrieve arbitrary metadata. They are not
562+
queryable and should be preserved when modifying objects.
563+
type: object
556564
args:
557565
description: 'Optional: List of arguments'
558566
items:

controllers/object_controls.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,12 @@ func TransformDCGMExporter(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpe
17551755
if len(config.DCGMExporter.ImagePullSecrets) > 0 {
17561756
addPullSecrets(&obj.Spec.Template.Spec, config.DCGMExporter.ImagePullSecrets)
17571757
}
1758+
1759+
// set extra annotations for the DS
1760+
if len(config.DCGMExporter.Annotations) > 0 {
1761+
addExtraAnnotations(obj, config.DCGMExporter.Annotations)
1762+
}
1763+
17581764
// set resource limits
17591765
if config.DCGMExporter.Resources != nil {
17601766
// apply resource limits to all containers
@@ -1851,6 +1857,19 @@ func TransformDCGMExporter(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpe
18511857
return nil
18521858
}
18531859

1860+
func addExtraAnnotations(obj *appsv1.DaemonSet, annotations map[string]string) {
1861+
if obj.Annotations == nil {
1862+
obj.Annotations = make(map[string]string)
1863+
}
1864+
if obj.Spec.Template.Annotations == nil {
1865+
obj.Spec.Template.Annotations = make(map[string]string)
1866+
}
1867+
for k, v := range annotations {
1868+
obj.Annotations[k] = v
1869+
obj.Spec.Template.Annotations[k] = v
1870+
}
1871+
}
1872+
18541873
// TransformDCGM transforms dcgm daemonset with required config as per ClusterPolicy
18551874
func TransformDCGM(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n ClusterPolicyController) error {
18561875
// update validation container

controllers/transforms_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
9196
func (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 {

deployments/gpu-operator/crds/nvidia.com_clusterpolicies.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,14 @@ spec:
553553
dcgmExporter:
554554
description: DCGMExporter spec
555555
properties:
556+
annotations:
557+
additionalProperties:
558+
type: string
559+
description: |-
560+
Optional: Annotations is an unstructured key value map stored with a resource that may be
561+
set by external tools to store and retrieve arbitrary metadata. They are not
562+
queryable and should be preserved when modifying objects.
563+
type: object
556564
args:
557565
description: 'Optional: List of arguments'
558566
items:

deployments/gpu-operator/templates/clusterpolicy.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@ spec:
540540
{{- end }}
541541
dcgmExporter:
542542
enabled: {{ .Values.dcgmExporter.enabled }}
543+
{{- if .Values.dcgmExporter.annotations }}
544+
annotations: {{ toYaml .Values.dcgmExporter.annotations | nindent 6 }}
545+
{{- end }}
543546
{{- if .Values.dcgmExporter.repository }}
544547
repository: {{ .Values.dcgmExporter.repository }}
545548
{{- end }}

deployments/gpu-operator/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ dcgm:
279279

280280
dcgmExporter:
281281
enabled: true
282+
annotations: {}
282283
repository: nvcr.io/nvidia/k8s
283284
image: dcgm-exporter
284285
version: 4.5.1-4.8.0-distroless

0 commit comments

Comments
 (0)