Skip to content

Commit 7d27a74

Browse files
authored
Merge pull request #850 from csauoss/servicemonitor-custom-labels
changes to allow custom labels for ServiceMonitor
2 parents 2abdb7a + 0c866da commit 7d27a74

9 files changed

Lines changed: 598 additions & 114 deletions

File tree

api/nvidia/v1/clusterpolicy_types.go

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,44 @@ const (
136136
Kata SandboxWorkloadsMode = "kata"
137137
)
138138

139+
// ServiceMonitorConfig defines configuration options for the ServiceMonitor
140+
// deployed for NVIDIA GPU Operator resources
141+
type ServiceMonitorConfig struct {
142+
// Enabled indicates if ServiceMonitor is deployed
143+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
144+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Enable deployment of ServiceMonitor"
145+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch"
146+
Enabled *bool `json:"enabled,omitempty"`
147+
148+
// Interval at which metrics should be scraped. If not specified, Prometheus’ global scrape interval is used.
149+
// Supported units: y, w, d, h, m, s, ms
150+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
151+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Interval at which metrics should be scraped"
152+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:text"
153+
Interval promv1.Duration `json:"interval,omitempty"`
154+
155+
// HonorLabels chooses the metric’s labels on collisions with target labels.
156+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
157+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Choose the metric's label on collisions with target labels"
158+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch"
159+
HonorLabels *bool `json:"honorLabels,omitempty"`
160+
161+
// AdditionalLabels to add to ServiceMonitor instance
162+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
163+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Additional labels to add to ServiceMonitor instance"
164+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:text"
165+
AdditionalLabels map[string]string `json:"additionalLabels,omitempty"`
166+
167+
// Relabelings allows to rewrite labels on metric sets
168+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
169+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Relabelings allows to rewrite labels on metric sets"
170+
Relabelings []*promv1.RelabelConfig `json:"relabelings,omitempty"`
171+
}
172+
173+
// The Alias for backward compatibility
174+
// This points the old name to the new struct definition
175+
type DCGMExporterServiceMonitorConfig = ServiceMonitorConfig
176+
139177
// OperatorSpec describes configuration options for the operator
140178
type OperatorSpec struct {
141179
// Deprecated: DefaultRuntime is no longer used by the gpu-operator. This is instead, detected at runtime.
@@ -155,13 +193,23 @@ type OperatorSpec struct {
155193
// queryable and should be preserved when modifying objects.
156194
Annotations map[string]string `json:"annotations,omitempty"`
157195

196+
// Metrics configuration for NVIDIA GPU Operator
197+
Metrics OperatorMetricsSpec `json:"metrics,omitempty"`
198+
158199
// UseOpenShiftDriverToolkit indicates if DriverToolkit image should be used on OpenShift to build and install driver modules
159200
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
160201
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="On OpenShift, enable DriverToolkit image to build and install driver modules"
161202
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch"
162203
UseOpenShiftDriverToolkit *bool `json:"use_ocp_driver_toolkit,omitempty"`
163204
}
164205

206+
type OperatorMetricsSpec struct {
207+
// Optional: ServiceMonitor configuration for NVIDIA GPU Operator
208+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
209+
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="ServiceMonitor configuration for NVIDIA GPU Operator"
210+
ServiceMonitor *ServiceMonitorConfig `json:"serviceMonitor,omitempty"`
211+
}
212+
165213
// HostPathsSpec defines various paths on the host needed by GPU Operator components
166214
type HostPathsSpec struct {
167215
// RootFS represents the path to the root filesystem of the host.
@@ -994,7 +1042,7 @@ type DCGMExporterSpec struct {
9941042
// Optional: ServiceMonitor configuration for NVIDIA DCGM Exporter
9951043
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
9961044
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="ServiceMonitor configuration for NVIDIA DCGM Exporter"
997-
ServiceMonitor *DCGMExporterServiceMonitorConfig `json:"serviceMonitor,omitempty"`
1045+
ServiceMonitor *ServiceMonitorConfig `json:"serviceMonitor,omitempty"`
9981046

9991047
// Optional: Service configuration for NVIDIA DCGM Exporter
10001048
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
@@ -1066,40 +1114,6 @@ type DCGMExporterServiceConfig struct {
10661114
InternalTrafficPolicy *corev1.ServiceInternalTrafficPolicy `json:"internalTrafficPolicy,omitempty"`
10671115
}
10681116

1069-
// DCGMExporterServiceMonitorConfig defines configuration options for the ServiceMonitor
1070-
// deployed for DCGM Exporter
1071-
type DCGMExporterServiceMonitorConfig struct {
1072-
// Enabled indicates if ServiceMonitor is deployed for NVIDIA DCGM Exporter
1073-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
1074-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Enable deployment of NVIDIA DCGM Exporter ServiceMonitor"
1075-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch"
1076-
Enabled *bool `json:"enabled,omitempty"`
1077-
1078-
// Interval which metrics should be scraped from NVIDIA DCGM Exporter. If not specified Prometheus’ global scrape interval is used.
1079-
// Supported units: y, w, d, h, m, s, ms
1080-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
1081-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Interval which metrics should be scraped from NVDIA DCGM Exporter"
1082-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:text"
1083-
Interval promv1.Duration `json:"interval,omitempty"`
1084-
1085-
// HonorLabels chooses the metric’s labels on collisions with target labels.
1086-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
1087-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Choose the metric's label on collisions with target labels"
1088-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch"
1089-
HonorLabels *bool `json:"honorLabels,omitempty"`
1090-
1091-
// AdditionalLabels to add to ServiceMonitor instance for NVIDIA DCGM Exporter
1092-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
1093-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Additional labels to add to ServiceMonitor instance for NVIDIA DCGM Exporter"
1094-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:text"
1095-
AdditionalLabels map[string]string `json:"additionalLabels,omitempty"`
1096-
1097-
// Relabelings allows to rewrite labels on metric sets for NVIDIA DCGM Exporter
1098-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
1099-
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Relabelings allows to rewrite labels on metric sets for NVIDIA DCGM Exporter"
1100-
Relabelings []*promv1.RelabelConfig `json:"relabelings,omitempty"`
1101-
}
1102-
11031117
// DCGMSpec defines the properties for NVIDIA DCGM deployment
11041118
type DCGMSpec struct {
11051119
// Enabled indicates if deployment of NVIDIA DCGM Hostengine as a separate pod is enabled.
@@ -2371,10 +2385,10 @@ func (dcgm *DCGMSpec) IsEnabled() bool {
23712385
return *dcgm.Enabled
23722386
}
23732387

2374-
// IsEnabled returns true if ServiceMonitor for DCGM Exporter is enabled through gpu-operator
2375-
func (sm *DCGMExporterServiceMonitorConfig) IsEnabled() bool {
2388+
// IsEnabled returns true if ServiceMonitor is enabled through gpu-operator
2389+
func (sm *ServiceMonitorConfig) IsEnabled() bool {
23762390
if sm.Enabled == nil {
2377-
// ServiceMonitor for DCGM Exporter is disabled by default
2391+
// ServiceMonitor is disabled by default
23782392
return false
23792393
}
23802394
return *sm.Enabled

api/nvidia/v1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)