Skip to content
Open
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
6 changes: 6 additions & 0 deletions api/nvidia/v1/clusterpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,12 @@ type DCGMExporterServiceConfig struct {
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Internal Traffic Policy for the DCGM Exporter K8s Service"
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:text"
InternalTrafficPolicy *corev1.ServiceInternalTrafficPolicy `json:"internalTrafficPolicy,omitempty"`

// Annotations to be added to the DCGM Exporter service
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Annotations for the DCGM Exporter K8s Service"
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:text"
Annotations map[string]string `json:"annotations,omitempty"`
}

// DCGMExporterServiceMonitorConfig defines configuration options for the ServiceMonitor
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.

6 changes: 6 additions & 0 deletions bundle/manifests/nvidia.com_clusterpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@ spec:
description: 'Optional: Service configuration for NVIDIA DCGM
Exporter'
properties:
annotations:
additionalProperties:
type: string
description: Annotations to be added to the DCGM Exporter
service
type: object
internalTrafficPolicy:
description: InternalTrafficPolicy describes how nodes distribute
service traffic they receive on the ClusterIP.
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/nvidia.com_clusterpolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@ spec:
description: 'Optional: Service configuration for NVIDIA DCGM
Exporter'
properties:
annotations:
additionalProperties:
type: string
description: Annotations to be added to the DCGM Exporter
service
type: object
internalTrafficPolicy:
description: InternalTrafficPolicy describes how nodes distribute
service traffic they receive on the ClusterIP.
Expand Down
10 changes: 10 additions & 0 deletions controllers/object_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,16 @@ func TransformDCGMExporterService(obj *corev1.Service, config *gpuv1.ClusterPoli
if serviceConfig.InternalTrafficPolicy != nil {
obj.Spec.InternalTrafficPolicy = serviceConfig.InternalTrafficPolicy
}

// set annotations if specified for dcgm-exporter service
if len(serviceConfig.Annotations) > 0 {
if obj.ObjectMeta.Annotations == nil {
obj.ObjectMeta.Annotations = make(map[string]string)
}
for annKey, annValue := range serviceConfig.Annotations {
obj.ObjectMeta.Annotations[annKey] = annValue
}
}
}
return nil
}
Expand Down
118 changes: 118 additions & 0 deletions controllers/transforms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,124 @@ func TestTransformNodeStatusExporter(t *testing.T) {
}
}

func TestTransformDCGMExporterService(t *testing.T) {
testCases := []struct {
description string
service *corev1.Service
cpSpec *gpuv1.ClusterPolicySpec
expectedService *corev1.Service
}{
{
description: "service without annotations",
service: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "nvidia-dcgm-exporter",
Annotations: map[string]string{
"prometheus.io/scrape": "true",
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
},
},
cpSpec: &gpuv1.ClusterPolicySpec{
DCGMExporter: gpuv1.DCGMExporterSpec{
ServiceSpec: &gpuv1.DCGMExporterServiceConfig{
Type: corev1.ServiceTypeNodePort,
},
},
},
expectedService: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "nvidia-dcgm-exporter",
Annotations: map[string]string{
"prometheus.io/scrape": "true",
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeNodePort,
},
},
},
{
description: "service with custom annotations",
service: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "nvidia-dcgm-exporter",
Annotations: map[string]string{
"prometheus.io/scrape": "true",
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
},
},
cpSpec: &gpuv1.ClusterPolicySpec{
DCGMExporter: gpuv1.DCGMExporterSpec{
ServiceSpec: &gpuv1.DCGMExporterServiceConfig{
Type: corev1.ServiceTypeNodePort,
Annotations: map[string]string{
"custom.annotation/key": "custom-value",
"another.annotation": "another-value",
},
},
},
},
expectedService: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "nvidia-dcgm-exporter",
Annotations: map[string]string{
"prometheus.io/scrape": "true",
"custom.annotation/key": "custom-value",
"another.annotation": "another-value",
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeNodePort,
},
},
},
{
description: "service with nil service spec",
service: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "nvidia-dcgm-exporter",
Annotations: map[string]string{
"prometheus.io/scrape": "true",
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
},
},
cpSpec: &gpuv1.ClusterPolicySpec{
DCGMExporter: gpuv1.DCGMExporterSpec{
ServiceSpec: nil,
},
},
expectedService: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "nvidia-dcgm-exporter",
Annotations: map[string]string{
"prometheus.io/scrape": "true",
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
},
},
},
}

for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
err := TransformDCGMExporterService(tc.service, tc.cpSpec)
require.NoError(t, err)
require.EqualValues(t, tc.expectedService, tc.service)
})
}
}

func TestTransformDriver(t *testing.T) {
initMockK8sClients()
testCases := []struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@ spec:
description: 'Optional: Service configuration for NVIDIA DCGM
Exporter'
properties:
annotations:
additionalProperties:
type: string
description: Annotations to be added to the DCGM Exporter
service
type: object
internalTrafficPolicy:
description: InternalTrafficPolicy describes how nodes distribute
service traffic they receive on the ClusterIP.
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 @@ -295,6 +295,7 @@ dcgmExporter:
resources: {}
service:
internalTrafficPolicy: Cluster
annotations: {}
serviceMonitor:
enabled: false
interval: 15s
Expand Down