Skip to content

Commit d238bb1

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 d238bb1

9 files changed

Lines changed: 155 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: 15 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,15 @@ 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.Spec.Template.Annotations == nil {
1862+
obj.Spec.Template.Annotations = make(map[string]string)
1863+
}
1864+
for k, v := range annotations {
1865+
obj.Spec.Template.Annotations[k] = v
1866+
}
1867+
}
1868+
18541869
// TransformDCGM transforms dcgm daemonset with required config as per ClusterPolicy
18551870
func TransformDCGM(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n ClusterPolicyController) error {
18561871
// update validation container

controllers/transforms_test.go

Lines changed: 100 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,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 {

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)