fix: preserve DCGM service compatibility #2918
<!-- devin-review-comment {"id": "BUG_pr-review-job-f3d2a3b0ed374506ad55addc59d30c0b_0001", "file_path": "manifests/state-dcgm-exporter/0490_service.yaml", "start_line": 8, "end_line": 19, "side": "RIGHT", "based_on_repo_rules": false, "kind": "bug"} -->
🟡 Compatibility services block later reconciliations
After either alias Service exists, createOrUpdateObjs replaces it from a manifest without API-assigned cluster IP fields. Kubernetes rejects the update, leaving each GPUCluster state NotReady and retrying indefinitely.
<details>
<summary>Learn more</summary>
Services receive immutable clusterIP and clusterIPs values from the API server when first created. The next sync reaches the AlreadyExists path and sends the rendered Service through a full update. mergeObjects preserves only resourceVersion, unlike the ClusterPolicy Service reconciliation, which also preserves clusterIP. The same failure affects the new DCGM alias Service.
Example: The first sync creates nvidia-dcgm-exporter with cluster IP 10.96.12.7. The next sync submits the rendered spec with no cluster IP, and the API server rejects removal of the immutable allocation instead of completing reconciliation.
Recommended fix: Preserve all API-assigned Service fields before updateObj, including clusterIP, clusterIPs, IP-family fields, and allocated node ports, or reconcile Services with a patch that leaves those fields untouched. Add a sync-twice regression test using an API server or a client that defaults and validates Service allocations.
</details>
<!-- devin-review-badge-begin -->
<a href="https://nvidia-cloud.devinenterprise.com/review/nvidia/gpu-operator/pull/2918" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->
---
Was this helpful? React with 👍 or 👎 to provide feedback.
<!-- devin-review-comment {"id": "ANALYSIS_pr-review-job-f3d2a3b0ed374506ad55addc59d30c0b_0001", "file_path": "controllers/object_controls.go", "start_line": 4805, "end_line": 4824, "side": "RIGHT", "kind": "analysis"} -->
🔍 ClusterPolicy enforcement remains untested
enforceDCGMCommonLabel changes ClusterPolicy reconciliation, but the added tests cover only GPUCluster rendering. Name matching and override ordering can regress unnoticed.
<!-- devin-review-badge-begin -->
<a href="https://nvidia-cloud.devinenterprise.com/review/nvidia/gpu-operator/pull/2918" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->
---
Was this helpful? React with 👍 or 👎 to provide feedback.
[!NOTE]
This report is out of date. Scroll down for Devin Review's latest report on this PR.
Devin Review found 2 potential issues.
<!-- devin-review-badge-begin -->
<a href="https://nvidia-cloud.devinenterprise.com/review/nvidia/gpu-operator/pull/2918" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->
✅ Resolved: The new Service merge path preserves cluster IPs, IP-family fields, NodePorts, and health-check ports before full updates.
✅ Resolved: TestDCGMCommonLabelEnforcement now exercises ClusterPolicy DCGM and exporter rendering, including an attempted common-label override.
<!-- devin-review-comment {"id": "BUG_pr-review-job-1a7cf13fb3a14850bb2113f7d73fb0d2_0001", "file_path": "manifests/state-dcgm-exporter/0490_service.yaml", "start_line": 3, "end_line": 7, "side": "RIGHT", "based_on_repo_rules": false, "kind": "bug"} -->
🟡 Legacy exporter service loses scrape discovery
Annotation-based discovery skips the compatibility Service because prometheus.io/scrape is absent. The legacy Service includes this annotation, so existing scrape configurations lose exporter metrics.
<details>
<summary>Learn more</summary>
The compatibility Service restores the legacy nvidia-dcgm-exporter name for DRA deployments. The prior Service carrying that name advertises prometheus.io/scrape: "true", but the replacement omits it. Prometheus configurations that filter discovered Services by this annotation therefore ignore the compatibility endpoint.
Example: A scrape job keeps only Services whose prometheus.io/scrape annotation equals true. It scraped nvidia-dcgm-exporter before migration, but drops the new compatibility Service and stops collecting GPU metrics.
Recommended fix: Add the legacy prometheus.io/scrape: "true" annotation to the compatibility Service, then regenerate the affected golden manifests.
</details>
<!-- devin-review-badge-begin -->
<a href="https://nvidia-cloud.devinenterprise.com/review/nvidia/gpu-operator/pull/2918" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->
---
Was this helpful? React with 👍 or 👎 to provide feedback.
[!NOTE]
This report is out of date. Scroll down for Devin Review's latest report on this PR.
Devin Review found 1 new potential issue.
<!-- devin-review-badge-begin -->
<a href="https://nvidia-cloud.devinenterprise.com/review/nvidia/gpu-operator/pull/2918" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->
✅ Resolved: The compatibility Service now includes the required scrape annotation.
<!-- devin-review-comment {"id": "BUG_pr-review-job-f9d4f042e18b469ab27331cbe23b5cb9_0001", "file_path": "manifests/state-dcgm-exporter/0490_service.yaml", "start_line": 8, "end_line": 9, "side": "RIGHT", "based_on_repo_rules": false, "kind": "bug"} -->
🟡 Duplicate DCGM metric scrape targets
Annotation-based discovery registers nvidia-dcgm-exporter as another scrape target. Both Services select the same exporter pods, so Prometheus ingests duplicate metrics.
<details>
<summary>Learn more</summary>
The GPUCluster path creates two Services for one DRA exporter DaemonSet. The compatibility Service uses the legacy name, while nvidia-dcgm-exporter-dra is the native DRA Service. Both Services select app: nvidia-dcgm-exporter-dra, expose port 9400, and now carry the standard Prometheus scrape annotation. Annotation-based service discovery therefore creates two targets for the same pod endpoint.
Example: One exporter pod exposes 10.0.0.8:9400. Service discovery finds that endpoint through both Service objects and scrapes it twice, producing duplicate samples and potentially duplicate alerts.
Recommended fix: Keep the scrape annotation on only one Service. If legacy annotation-based discovery requires the compatibility name, remove it from 0500_service.yaml; otherwise leave the compatibility alias unannotated.
</details>
<!-- devin-review-badge-begin -->
<a href="https://nvidia-cloud.devinenterprise.com/review/nvidia/gpu-operator/pull/2918" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->
---
Was this helpful? React with 👍 or 👎 to provide feedback.
[!NOTE]
Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.
Devin Review found 1 new potential issue.
<!-- devin-review-badge-begin -->
<a href="https://nvidia-cloud.devinenterprise.com/review/nvidia/gpu-operator/pull/2918" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->
✅ Resolved: The DRA-native Service no longer carries the scrape annotation, so annotation-based discovery creates only the compatibility Service target.
Question -- why is this needed now when it wasn't needed before? Is it because this commit is introducing a diff in the nvidia-dcgm-exporter-dra Service object?
This was flagged by LLMs. I believe we had this bug introduced recently but never caught it.
non-dra path uses:
https://github.com/NVIDIA/gpu-operator/blob/93c0ff560ca71e761d6c1782d904765bb88de3db/controllers/object_controls.go#L4952-L4956
It sets resourceVersion and clusterip allocated before calling update().
However, GPUCluster path uses generic unstructured reconciler which only preserves resourceVersion but not the clusterIP. Kubernetes can reject the update if clusterIP is omitted. This might be an existing bug in v26.7.0 not yet reported. Once service is created and ip is assigned, future reconcile updates might be failing but its not getting affected as it exists, just not getting updated.
<!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- review_stack_entry_start -->
<a href="https://app.coderabbit.ai/change-stack/NVIDIA/gpu-operator/pull/2918#gh-light-mode-only"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg" alt="Review Change Stack" width="202" height="32"></a><a href="https://app.coderabbit.ai/change-stack/NVIDIA/gpu-operator/pull/2918#gh-dark-mode-only"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg" alt="Review Change Stack" width="202" height="32"></a>
<!-- review_stack_entry_end -->
<!-- walkthrough_start -->
<details>
<summary>📝 Walkthrough</summary>
Walkthrough
The change adds reserved DCGM and DCGM Exporter labels to DaemonSets and pod templates. It prevents user labels from overriding those labels. GPUCluster manifests add stable DCGM and exporter Services while retaining DRA-specific Services. Service merging now preserves API-assigned networking fields, node ports, and health-check node ports. Tests cover labels, Services, selectors, annotations, overrides, and merge behavior.
</details>
<!-- walkthrough_end -->
<!-- change_assessment_start -->
Priority: ➖ Normal
<!-- change_assessment_commit:"3518aaca86c6e4369fd8aa36e961469e9ab268a6" -->
Severity of issue fixed: Medium
<!-- change_assessment_end -->
<!-- final_review_risk_start -->
Merge Risk: _🟡 Moderate_ · up to 3518a
<!-- final_review_risk_coverage:{"sourceCommitId":"3518aaca86c6e4369fd8aa36e961469e9ab268a6","coveredCommitId":"3518aaca86c6e4369fd8aa36e961469e9ab268a6","kind":"reviewed"} -->
A GPUCluster upgrade can remove legacy DCGM or exporter endpoints before DRA pods are ready, temporarily interrupting hostengine or metrics access. Preserve current selectors for existing Services before merging.
<!-- final_review_risk_end -->
<!-- tips_start -->
---
<sub>Comment @coderabbitai help to get the list of available commands.</sub>
<!-- tips_end -->
_🩺 Stability & Availability_ | _🟠 Major_ | _⚡ Quick win_
<details>
<summary>🔎 Supported by static analysis</summary>
🏁 Script executed:
sed -n '430,540p' internal/state/state_skel.go
sed -n '1,100p' manifests/state-dcgm/0550_service.yaml
sed -n '1,120p' manifests/state-dcgm-exporter/0490_service.yaml
sed -n '4910,5000p' controllers/object_controls.go
rg -n 'nvidia-dcgm(-exporter)?|selector|mergeObjects|mergeService' internal/state controllers manifests assets | head -240
Repository: NVIDIA/gpu-operator
Length of output: 31109
---
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- state skeleton reconciliation ---'
sed -n '280,390p' internal/state/state_skel.go
printf '%s\n' '--- state skeleton declarations and callers ---'
rg -n -C 3 'NewState|stateSkel|Reconcile|mergeObjects|GPUCluster|ClusterPolicy|State\(' internal/state controllers | head -320
printf '%s\n' '--- DCGM state definitions and registration ---'
rg -n -C 5 'func (.*DCGM|func DCGM|DCGMExporter|dcgm|state-dcgm|state-dcgm-exporter' internal/state controllers | head -360
printf '%s\n' '--- Service update paths and selector preservation ---'
rg -n -C 5 'Spec\.Selector|Selector.*current|current.*Selector|preserve.*selector|selector.*preserve|Service\(' internal/state controllers | head -360
printf '%s\n' '--- rollout/upgrade requirement evidence ---'
rg -n -i -C 4 'selector.*(preserv|rollout|upgrade)|preserv.*selector|endpoint|downtime|availability|DCGM' . --glob '!internal/state/testdata/golden/**' --glob '!vendor/**' | head -360
Repository: NVIDIA/gpu-operator
Length of output: 50375
---
🤖 get_repo_knowledge executed:
get_repo_knowledge NVIDIA/gpu-operator /tmp/coderabbit-repo-knowledge/nvidia-gpu-operator-eed98df4/conventions
Length of output: 4401
---
🏁 Script executed:
set -e
sed -n '280,390p' internal/state/state_skel.go
rg -n -C 4 'stateSkel|mergeObjects|GPUCluster|state-dcgm|state-dcgm-exporter|Spec\.Selector|preserve.*selector|selector.*preserv' internal/state controllers
Repository: NVIDIA/gpu-operator
Length of output: 50376
---
🏁 Script executed:
set -e
printf '%s\n' '--- changed state skeleton diff ---'
git diff -- internal/state/state_skel.go
printf '%s\n' '--- state manager/controller GPUCluster entrypoints ---'
rg -n -C 8 'GPUCluster|SyncState|Sync\(|NewStateDCGM|NewStateDCGMExporter|newStates|stateManager|Reconcile' controllers/state_manager.go internal/state/manager.go internal/state/*.go | head -500
printf '%s\n' '--- focused selector tests and requirements ---'
rg -n -C 8 'selector|endpoint|rollout|preserv|DRA' internal/state/state_skel*_test.go internal/state/dcgm*_test.go internal/state/*test.go controllers/*test.go docs README.md CONTRIBUTING.md 2>/dev/null | head -500
Repository: NVIDIA/gpu-operator
Length of output: 50375
---
🏁 Script executed:
set -e
printf '%s\n' '--- internal state manager ---'
cat -n internal/state/manager.go
printf '%s\n' '--- direct state manager invocations ---'
rg -n -C 10 'SyncState\(|\.Sync\(ctx|Sync\(.*GPUCluster|SyncState\(' controllers internal --glob '*.go' | head -320
printf '%s\n' '--- state factory registration ---'
rg -n -C 12 'NewStates|NewStateDCGM|NewStateDCGMExporter|GPUClusterCRDName|GPUCluster' internal/state/manager.go controllers | head -320
Repository: NVIDIA/gpu-operator
Length of output: 50375
---
</details>
Preserve existing Service selectors during GPUCluster updates. GPUClusterReconciler reaches the DCGM and DCGM exporter states, and createOrUpdateObjs updates existing Services through mergeService. That helper preserves allocated fields but leaves the desired Spec.Selector unchanged. An upgrade can therefore replace a selector for serving legacy pods with app: nvidia-dcgm-dra or app: nvidia-dcgm-exporter-dra before those pods are ready. Kubernetes then removes the legacy pods from the Service endpoints, causing a temporary hostengine or metrics outage.
Copy the current selector in mergeService for existing Services. Keep the DRA selector for newly created Services.
<!-- fingerprinting:phantom:medusa:tapir -->
<!-- cr-indicator-types:potential_issue -->
<!-- cr-comment:v1:e065fb4d794d58c4608ee0d6 -->
<!-- This is an auto-generated comment by CodeRabbit -->
Actionable comments posted: 1
---
<details>
<summary>ℹ️ Review info</summary>
<details>
<summary>⚙️ Run configuration</summary>
Configuration used: Path: .coderabbit.yaml
Review profile: QUIET
Plan: Enterprise
Run ID: 6c4f18da-82df-4dc8-89bc-2805492a802d
</details>
<details>
<summary>📥 Commits</summary>
Reviewing files that changed from the base of the PR and between 93c0ff560ca71e761d6c1782d904765bb88de3db and 3518aaca86c6e4369fd8aa36e961469e9ab268a6.
</details>
<details>
<summary>⛔ Files ignored due to path filters (4)</summary>
internal/state/testdata/golden/gpucluster-dcgm-exporter-embedded.yaml is excluded by !/testdata/
internal/state/testdata/golden/gpucluster-dcgm-exporter-pod-metadata.yaml is excluded by !/testdata/
internal/state/testdata/golden/gpucluster-dcgm-exporter-remote-engine.yaml is excluded by !/testdata/
internal/state/testdata/golden/gpucluster-dcgm.yaml is excluded by !/testdata/
</details>
<details>
<summary>📒 Files selected for processing (13)</summary>
assets/state-dcgm-exporter/0800_daemonset.yaml
assets/state-dcgm/0400_dcgm.yml
controllers/object_controls.go
controllers/object_controls_test.go
internal/state/dcgm_exporter_test.go
internal/state/dcgm_test.go
internal/state/state_skel.go
internal/state/state_skel_test.go
manifests/state-dcgm-exporter/0490_service.yaml
manifests/state-dcgm-exporter/0500_service.yaml
manifests/state-dcgm-exporter/0700_daemonset.yaml
manifests/state-dcgm/0500_daemonset.yaml
manifests/state-dcgm/0550_service.yaml
</details>
<details>
<summary>💤 Files with no reviewable changes (1)</summary>
manifests/state-dcgm-exporter/0500_service.yaml
</details>
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.
</details>
<!-- This is an auto-generated comment by CodeRabbit for review status -->
Can we look at alternate names for this label key?
The format of nvidia.com/gpu-operator.dcgm-exporter: "true" seems non-standard for labels.
Maybe app.kubernetes.io/component: nvidia-dcgm-exporter?
Yes, that could work. It is a standardised label
Sure, we can. This label was selected so that we use the same scheme we used before like here: https://github.com/NVIDIA/gpu-operator/blob/93c0ff560ca71e761d6c1782d904765bb88de3db/internal/consts/consts.go#L71
Looks like app.kubernetes.io/component has a specific meaning as per this K8s docs
How about app.kubernetes.io/name instead?
@rahulait I missed to mention this earlier, using a boolean as the label value typed seemed a bit off to me.
I've split the change of adding common label to PR https://github.com/NVIDIA/gpu-operator/pull/3017
This PR will be rebased once we have decided on the approach and the common label is merged.
@tariq1890 I still used app.kubernetes.io/component: as key as we have used the same for nvidia-driver as well.
Devin Review found 1 new potential issue.
<details><summary>⚠️ 1 issue in files not directly in the diff</summary>
<!-- devin-review-comment {"id": "BUG_pr-review-job-e1f9b5bdaeb64ad789fe6e86c0a24742_0001", "file_path": "manifests/state-dcgm/0500_daemonset.yaml", "start_line": 8, "end_line": 8, "side": "RIGHT", "based_on_repo_rules": false, "kind": "bug"} -->
⚠️ DCGM operands lose common discovery labels
DCGM deployments omit nvidia.com/gpu-operator.dcgm and nvidia.com/gpu-operator.dcgm-exporter from their DaemonSets and pods. Consumers selecting either common label cannot discover the corresponding operand.
</details>
<!-- devin-review-badge-begin -->
<a href="https://nvidia-cloud.devinenterprise.com/review/nvidia/gpu-operator/pull/2918" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->
cdesiniotis
rahulait
Description
<!-- Brief description of the change, including context or motivation -->
Partially fixes https://github.com/NVIDIA/gpu-operator/issues/2917
Restore stable DCGM and DCGM Exporter identities for GPUCluster/DRA deployments while retaining the released DRA-specific Services.
Changes
-
nvidia-dcgm-
nvidia-dcgm-exporter-
nvidia-dcgm-dra-
nvidia-dcgm-exporter-dranvidia-dcgm-exporterfor Prometheus scraping to avoid duplicate targets.Checklist
make lint)make validate-generated-assets)make validate-modules)Testing
<!-- How was this tested? e.g., unit tests, manual testing on cluster -->