Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/nvidia/v1/clusterpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,11 @@ type DCGMExporterSpec struct {
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:advanced,urn:alm:descriptor:com.tectonic.ui:text"
Args []string `json:"args,omitempty"`

// Optional: Annotations is an unstructured key value map stored with a resource that may be
// set by external tools to store and retrieve arbitrary metadata. They are not
// queryable and should be preserved when modifying objects.
Annotations map[string]string `json:"annotations,omitempty"`

// Optional: List of environment variables
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Environment Variables"
Expand Down
7 changes: 7 additions & 0 deletions api/nvidia/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions bundle/manifests/nvidia.com_clusterpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,14 @@ spec:
dcgmExporter:
description: DCGMExporter spec
properties:
annotations:
additionalProperties:
type: string
description: |-
Optional: Annotations is an unstructured key value map stored with a resource that may be
set by external tools to store and retrieve arbitrary metadata. They are not
queryable and should be preserved when modifying objects.
type: object
args:
description: 'Optional: List of arguments'
items:
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/nvidia.com_clusterpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,14 @@ spec:
dcgmExporter:
description: DCGMExporter spec
properties:
annotations:
additionalProperties:
type: string
description: |-
Optional: Annotations is an unstructured key value map stored with a resource that may be
set by external tools to store and retrieve arbitrary metadata. They are not
queryable and should be preserved when modifying objects.
type: object
args:
description: 'Optional: List of arguments'
items:
Expand Down
15 changes: 15 additions & 0 deletions controllers/object_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,12 @@ func TransformDCGMExporter(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpe
if len(config.DCGMExporter.ImagePullSecrets) > 0 {
addPullSecrets(&obj.Spec.Template.Spec, config.DCGMExporter.ImagePullSecrets)
}

// merge extra annotations at the pod template level
if len(config.DCGMExporter.Annotations) > 0 {
addExtraAnnotations(obj, config.DCGMExporter.Annotations)
}

// set resource limits
if config.DCGMExporter.Resources != nil {
// apply resource limits to all containers
Expand Down Expand Up @@ -1851,6 +1857,15 @@ func TransformDCGMExporter(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpe
return nil
}

func addExtraAnnotations(obj *appsv1.DaemonSet, annotations map[string]string) {
if obj.Spec.Template.Annotations == nil {
obj.Spec.Template.Annotations = make(map[string]string)
}
for k, v := range annotations {
obj.Spec.Template.Annotations[k] = v
}
}

// TransformDCGM transforms dcgm daemonset with required config as per ClusterPolicy
func TransformDCGM(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec, n ClusterPolicyController) error {
// update validation container
Expand Down
95 changes: 95 additions & 0 deletions controllers/transforms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,101 @@ func TestTransformDCGMExporter(t *testing.T) {
WithRuntimeClassName("nvidia").
WithHostPathVolume("hpc-job-mapping", "/run/nvidia/dcgm-job-mapping", ptr.To(corev1.HostPathDirectoryOrCreate)),
},
{
description: "transform dcgm exporter with extra annotations adds it at pod template level",
ds: NewDaemonset().
WithContainer(corev1.Container{Name: "dcgm-exporter"}),
cpSpec: &gpuv1.ClusterPolicySpec{
DCGMExporter: gpuv1.DCGMExporterSpec{
Repository: "nvcr.io/nvidia/k8s",
Image: "dcgm-exporter",
Version: "v1.0.0",
Annotations: map[string]string{
"prometheus.io/scrape": "true",
"prometheus.io/port": "8080",
"prometheus.io/path": "/metrics",
},
},
},
expectedDs: NewDaemonset().
WithPodAnnotations(map[string]string{
"prometheus.io/scrape": "true",
"prometheus.io/port": "8080",
"prometheus.io/path": "/metrics",
}).
WithContainer(corev1.Container{
Name: "dcgm-exporter",
Image: "nvcr.io/nvidia/k8s/dcgm-exporter:v1.0.0",
ImagePullPolicy: corev1.PullIfNotPresent,
Env: []corev1.EnvVar{
{Name: "DCGM_REMOTE_HOSTENGINE_INFO", Value: "nvidia-dcgm:5555"},
},
}).
WithRuntimeClassName("nvidia"),
},
{
description: "transform dcgm exporter appends extra annotations to existing ones at pod template level",
ds: NewDaemonset().
WithPodAnnotations(map[string]string{
"foo": "bar",
}).
WithContainer(corev1.Container{Name: "dcgm-exporter"}),
cpSpec: &gpuv1.ClusterPolicySpec{
DCGMExporter: gpuv1.DCGMExporterSpec{
Repository: "nvcr.io/nvidia/k8s",
Image: "dcgm-exporter",
Version: "v1.0.0",
Annotations: map[string]string{
"prometheus.io/scrape": "true",
},
},
},
expectedDs: NewDaemonset().
WithPodAnnotations(map[string]string{
"foo": "bar",
"prometheus.io/scrape": "true",
}).
WithContainer(corev1.Container{
Name: "dcgm-exporter",
Image: "nvcr.io/nvidia/k8s/dcgm-exporter:v1.0.0",
ImagePullPolicy: corev1.PullIfNotPresent,
Env: []corev1.EnvVar{
{Name: "DCGM_REMOTE_HOSTENGINE_INFO", Value: "nvidia-dcgm:5555"},
},
}).
WithRuntimeClassName("nvidia"),
},
{
description: "transform dcgm exporter overrides annotation with same key at pod template level",
ds: NewDaemonset().
WithPodAnnotations(map[string]string{
"foo": "bar",
}).
WithContainer(corev1.Container{Name: "dcgm-exporter"}),
cpSpec: &gpuv1.ClusterPolicySpec{
DCGMExporter: gpuv1.DCGMExporterSpec{
Repository: "nvcr.io/nvidia/k8s",
Image: "dcgm-exporter",
Version: "v1.0.0",
Annotations: map[string]string{
"foo": "baz",
},
},
},
expectedDs: NewDaemonset().
WithPodAnnotations(map[string]string{
"foo": "baz",
}).
WithContainer(corev1.Container{
Name: "dcgm-exporter",
Image: "nvcr.io/nvidia/k8s/dcgm-exporter:v1.0.0",
ImagePullPolicy: corev1.PullIfNotPresent,
Env: []corev1.EnvVar{
{Name: "DCGM_REMOTE_HOSTENGINE_INFO", Value: "nvidia-dcgm:5555"},
},
}).
WithRuntimeClassName("nvidia"),
},
}

for _, tc := range testCases {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,14 @@ spec:
dcgmExporter:
description: DCGMExporter spec
properties:
annotations:
additionalProperties:
type: string
description: |-
Optional: Annotations is an unstructured key value map stored with a resource that may be
set by external tools to store and retrieve arbitrary metadata. They are not
queryable and should be preserved when modifying objects.
type: object
args:
description: 'Optional: List of arguments'
items:
Expand Down
3 changes: 3 additions & 0 deletions deployments/gpu-operator/templates/clusterpolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ spec:
{{- end }}
dcgmExporter:
enabled: {{ .Values.dcgmExporter.enabled }}
{{- if .Values.dcgmExporter.annotations }}
annotations: {{ toYaml .Values.dcgmExporter.annotations | nindent 6 }}
{{- end }}
{{- if .Values.dcgmExporter.repository }}
repository: {{ .Values.dcgmExporter.repository }}
{{- end }}
Expand Down
1 change: 1 addition & 0 deletions deployments/gpu-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ dcgm:

dcgmExporter:
enabled: true
annotations: {}
repository: nvcr.io/nvidia/k8s
image: dcgm-exporter
version: 4.5.1-4.8.0-distroless
Expand Down
Loading