-
Notifications
You must be signed in to change notification settings - Fork 500
Add DCGM exporter pod metadata enrichment API #2406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: nvidia-dcgm-exporter-read-pods | ||
| labels: | ||
| app: nvidia-dcgm-exporter | ||
| # TODO: Add resourceSlices permissions when GPU Operator exposes DRA exporter support. | ||
| rules: | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - pods | ||
| verbs: | ||
| - get | ||
| - list | ||
| - watch | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| metadata: | ||
| name: nvidia-dcgm-exporter-read-pods | ||
| labels: | ||
| app: nvidia-dcgm-exporter | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: ClusterRole | ||
| name: nvidia-dcgm-exporter-read-pods | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: nvidia-dcgm-exporter | ||
| namespace: "FILLED BY THE OPERATOR" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -466,6 +466,19 @@ func ClusterRole(n ClusterPolicyController) (gpuv1.State, error) { | |
| return gpuv1.Disabled, nil | ||
| } | ||
|
|
||
| // For state-dcgm-exporter, cluster-scoped pod-read RBAC is only needed | ||
| // when pod-metadata enrichment is opted in. | ||
| if n.stateNames[n.idx] == "state-dcgm-exporter" && | ||
| obj.Name == "nvidia-dcgm-exporter-read-pods" && | ||
| !n.singleton.Spec.DCGMExporter.IsKubernetesPodMetadataEnabled() { | ||
| err := n.client.Delete(ctx, obj) | ||
| if err != nil && !apierrors.IsNotFound(err) { | ||
| logger.Error(err, "Couldn't delete") | ||
| return gpuv1.NotReady, err | ||
| } | ||
| return gpuv1.Disabled, nil | ||
| } | ||
|
|
||
| if err := controllerutil.SetControllerReference(n.singleton, obj, n.scheme); err != nil { | ||
| return gpuv1.NotReady, err | ||
| } | ||
|
|
@@ -507,6 +520,18 @@ func ClusterRoleBinding(n ClusterPolicyController) (gpuv1.State, error) { | |
| return gpuv1.Disabled, nil | ||
| } | ||
|
|
||
| // Mirror the ClusterRole gate. | ||
| if n.stateNames[n.idx] == "state-dcgm-exporter" && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In daemonsets, we have state-specific (or operand-specific) methods that are called through the |
||
| obj.Name == "nvidia-dcgm-exporter-read-pods" && | ||
| !n.singleton.Spec.DCGMExporter.IsKubernetesPodMetadataEnabled() { | ||
| err := n.client.Delete(ctx, obj) | ||
| if err != nil && !apierrors.IsNotFound(err) { | ||
| logger.Error(err, "Couldn't delete") | ||
| return gpuv1.NotReady, err | ||
| } | ||
| return gpuv1.Disabled, nil | ||
| } | ||
|
|
||
| for idx := range obj.Subjects { | ||
| obj.Subjects[idx].Namespace = n.operatorNamespace | ||
| } | ||
|
|
@@ -1828,6 +1853,26 @@ func TransformDCGMExporter(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpe | |
| obj.Spec.Template.Spec.Volumes = append(obj.Spec.Template.Spec.Volumes, jobMappingVol) | ||
| } | ||
|
|
||
| // Inject pod-metadata enrichment env vars; RBAC is provisioned via the | ||
| // 0210/0310 assets and the SA token is mounted below. | ||
| if config.DCGMExporter.IsPodLabelsEnabled() { | ||
| setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), "DCGM_EXPORTER_KUBERNETES_ENABLE_POD_LABELS", "true") | ||
| } | ||
| if config.DCGMExporter.IsPodUIDEnabled() { | ||
| setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), "DCGM_EXPORTER_KUBERNETES_ENABLE_POD_UID", "true") | ||
| } | ||
| if len(config.DCGMExporter.PodLabelAllowlistRegex) > 0 { | ||
| setContainerEnv(&(obj.Spec.Template.Spec.Containers[0]), | ||
| "DCGM_EXPORTER_KUBERNETES_POD_LABEL_ALLOWLIST_REGEX", | ||
| strings.Join(config.DCGMExporter.PodLabelAllowlistRegex, ",")) | ||
| } | ||
|
|
||
| // Override the base asset's automountServiceAccountToken=false when | ||
| // enrichment is on so the pod informer has client-go credentials. | ||
| if config.DCGMExporter.IsKubernetesPodMetadataEnabled() { | ||
| obj.Spec.Template.Spec.AutomountServiceAccountToken = ptr.To(true) | ||
| } | ||
|
|
||
| // mount configmap for custom metrics if provided by user | ||
| if config.DCGMExporter.MetricsConfig != nil && config.DCGMExporter.MetricsConfig.Name != "" { | ||
| metricsConfigVolMount := corev1.VolumeMount{Name: "metrics-config", ReadOnly: true, MountPath: MetricsConfigMountPath, SubPath: MetricsConfigFileName} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.