← Back to Pull requests

fix: preserve DCGM service compatibility #2918

Open
rahulait opened this pull request with 361 lines diff across 11 files
View on GitHub
rahulait rahulait commented on Sep 17, 2026 16:49 UTC
Author

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

  • Add DRA compatibility Services:

  • - nvidia-dcgm
    - nvidia-dcgm-exporter
  • Retain:

  • - nvidia-dcgm-dra
    - nvidia-dcgm-exporter-dra
  • Prevent ClusterPolicy custom labels from overriding the common labels.

  • Preserve Kubernetes-assigned Service fields during GPUCluster updates, including ClusterIPs and NodePorts.

  • Annotate only nvidia-dcgm-exporter for Prometheus scraping to avoid duplicate targets.

  • Add tests and update golden manifests.
  • Checklist

  • No secrets, sensitive information, or unrelated changes

  • Lint checks passing (make lint)

  • Generated assets in-sync (make validate-generated-assets)

  • Go mod artifacts in-sync (make validate-modules)

  • Test cases are added for new code paths
  • Testing

    <!-- How was this tested? e.g., unit tests, manual testing on cluster -->

    Diff: 361 lines (+335 / -26) across 11 files Reviewer: cdesiniotis Review duration: 59893m
    All Vouch review confidence checks passed
    Residual risk 0.06 = Change Risk (0.60) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.60 · 361 lines diff across 11 files
    0.60
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.92 · 5 substantive comment(s)
    0.92
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    89%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.352
    Real PR Conversation Timeline
    27 items
    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Sep 17, 2026 16:55 UTC
    Code Review
    manifests/state-dcgm-exporter/0490_service.yaml:1
    @@ -0,0 +1,19 @@
    +apiVersion: v1
    +kind: Service
    +metadata:
    +  name: nvidia-dcgm-exporter
    +  namespace: {{ .Namespace }}
    +  labels:
    +    app: nvidia-dcgm-exporter
    +spec:
    +  type: {{ .ServiceType }}
    +  {{- if .ServiceInternalTrafficPolicy }}
    +  internalTrafficPolicy: {{ .ServiceInternalTrafficPolicy }}
    +  {{- end }}
    +  selector:
    +    app: nvidia-dcgm-exporter-dra
    +  ports:
    +  - name: gpu-metrics
    +    port: 9400
    +    targetPort: 9400
    +    protocol: TCP

    <!-- 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-ai-integration[bot] devin-ai-integration[bot] commented on code on Sep 17, 2026 16:55 UTC
    Code Review
    controllers/object_controls.go:1
    @@ -4788,6 +4789,27 @@ func DaemonSet(n ClusterPolicyController) (gpuv1.State, error) {
     	return isDaemonSetReady(obj.Name, n), nil
     }
     
    +func enforceDCGMCommonLabel(obj *appsv1.DaemonSet) {
    +	var key string
    +	switch obj.Name {
    +	case "nvidia-dcgm", "nvidia-dcgm-dra":
    +		key = "nvidia.com/gpu-operator.dcgm"
    +	case "nvidia-dcgm-exporter", "nvidia-dcgm-exporter-dra":
    +		key = "nvidia.com/gpu-operator.dcgm-exporter"
    +	default:
    +		return
    +	}
    +
    +	if obj.Labels == nil {
    +		obj.Labels = make(map[string]string)
    +	}
    +	obj.Labels[key] = "true"
    +	if obj.Spec.Template.Labels == nil {
    +		obj.Spec.Template.Labels = make(map[string]string)
    +	}
    +	obj.Spec.Template.Labels[key] = "true"
    +}

    <!-- 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.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on Sep 17, 2026 16:55 UTC
    Reviewer

    [!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 -->

    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Sep 17, 2026 18:36 UTC
    Code Review
    manifests/state-dcgm-exporter/0490_service.yaml:1
    @@ -0,0 +1,19 @@
    +apiVersion: v1
    +kind: Service
    +metadata:
    +  name: nvidia-dcgm-exporter
    +  namespace: {{ .Namespace }}
    +  labels:
    +    app: nvidia-dcgm-exporter
    +spec:
    +  type: {{ .ServiceType }}
    +  {{- if .ServiceInternalTrafficPolicy }}
    +  internalTrafficPolicy: {{ .ServiceInternalTrafficPolicy }}
    +  {{- end }}
    +  selector:
    +    app: nvidia-dcgm-exporter-dra
    +  ports:
    +  - name: gpu-metrics
    +    port: 9400
    +    targetPort: 9400
    +    protocol: TCP

    ✅ Resolved: The new Service merge path preserves cluster IPs, IP-family fields, NodePorts, and health-check ports before full updates.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Sep 17, 2026 18:36 UTC
    Code Review
    controllers/object_controls.go:1
    @@ -4788,6 +4789,27 @@ func DaemonSet(n ClusterPolicyController) (gpuv1.State, error) {
     	return isDaemonSetReady(obj.Name, n), nil
     }
     
    +func enforceDCGMCommonLabel(obj *appsv1.DaemonSet) {
    +	var key string
    +	switch obj.Name {
    +	case "nvidia-dcgm", "nvidia-dcgm-dra":
    +		key = "nvidia.com/gpu-operator.dcgm"
    +	case "nvidia-dcgm-exporter", "nvidia-dcgm-exporter-dra":
    +		key = "nvidia.com/gpu-operator.dcgm-exporter"
    +	default:
    +		return
    +	}
    +
    +	if obj.Labels == nil {
    +		obj.Labels = make(map[string]string)
    +	}
    +	obj.Labels[key] = "true"
    +	if obj.Spec.Template.Labels == nil {
    +		obj.Spec.Template.Labels = make(map[string]string)
    +	}
    +	obj.Spec.Template.Labels[key] = "true"
    +}

    ✅ Resolved: TestDCGMCommonLabelEnforcement now exercises ClusterPolicy DCGM and exporter rendering, including an attempted common-label override.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Sep 17, 2026 18:36 UTC
    Code Review
    manifests/state-dcgm-exporter/0490_service.yaml:1
    @@ -0,0 +1,19 @@
    +apiVersion: v1
    +kind: Service
    +metadata:
    +  name: nvidia-dcgm-exporter
    +  namespace: {{ .Namespace }}
    +  labels:
    +    app: nvidia-dcgm-exporter

    <!-- 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.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on Sep 17, 2026 18:36 UTC
    Reviewer

    [!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 -->

    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Sep 17, 2026 19:07 UTC
    Code Review
    manifests/state-dcgm-exporter/0490_service.yaml:1
    @@ -0,0 +1,19 @@
    +apiVersion: v1
    +kind: Service
    +metadata:
    +  name: nvidia-dcgm-exporter
    +  namespace: {{ .Namespace }}
    +  labels:
    +    app: nvidia-dcgm-exporter

    ✅ Resolved: The compatibility Service now includes the required scrape annotation.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Sep 17, 2026 19:08 UTC
    Code Review
    manifests/state-dcgm-exporter/0490_service.yaml:1
    @@ -0,0 +1,21 @@
    +apiVersion: v1
    +kind: Service
    +metadata:
    +  name: nvidia-dcgm-exporter
    +  namespace: {{ .Namespace }}
    +  labels:
    +    app: nvidia-dcgm-exporter
    +  annotations:
    +    prometheus.io/scrape: "true"

    <!-- 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.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on Sep 17, 2026 19:08 UTC
    Reviewer

    [!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 -->

    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Sep 17, 2026 19:14 UTC
    Code Review
    manifests/state-dcgm-exporter/0490_service.yaml:1
    @@ -0,0 +1,21 @@
    +apiVersion: v1
    +kind: Service
    +metadata:
    +  name: nvidia-dcgm-exporter
    +  namespace: {{ .Namespace }}
    +  labels:
    +    app: nvidia-dcgm-exporter
    +  annotations:
    +    prometheus.io/scrape: "true"

    ✅ Resolved: The DRA-native Service no longer carries the scrape annotation, so annotation-based discovery creates only the compatibility Service target.

    cdesiniotis cdesiniotis commented on code on Sep 17, 2026 19:32 UTC
    Code Review
    internal/state/state_skel.go:1
    @@ -442,9 +443,86 @@ func (s *stateSkel) mergeObjects(updated, current *unstructured.Unstructured) er
     	if gvk.Group == "" && gvk.Kind == "ServiceAccount" {
     		return s.mergeServiceAccount(updated, current)
     	}
    +	if gvk.Group == "" && gvk.Kind == "Service" {
    +		return s.mergeService(updated, current)
    +	}
    +	return nil
    +}
    +
    +// mergeService preserves fields allocated by the API server. Clearing these fields in a full
    +// update is rejected because their values are immutable or must remain allocated.
    +func (s *stateSkel) mergeService(updated, current *unstructured.Unstructured) error {

    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?

    rahulait rahulait commented on code on Sep 17, 2026 20:34 UTC
    Code Review
    internal/state/state_skel.go:1
    @@ -442,9 +443,86 @@ func (s *stateSkel) mergeObjects(updated, current *unstructured.Unstructured) er
     	if gvk.Group == "" && gvk.Kind == "ServiceAccount" {
     		return s.mergeServiceAccount(updated, current)
     	}
    +	if gvk.Group == "" && gvk.Kind == "Service" {
    +		return s.mergeService(updated, current)
    +	}
    +	return nil
    +}
    +
    +// mergeService preserves fields allocated by the API server. Clearing these fields in a full
    +// update is rejected because their values are immutable or must remain allocated.
    +func (s *stateSkel) mergeService(updated, current *unstructured.Unstructured) error {

    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.

    coderabbitai[bot] coderabbitai[bot] commented on Sep 17, 2026 20:59 UTC
    Bot

    <!-- 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 -->

    coderabbitai[bot] coderabbitai[bot] commented on code on Sep 17, 2026 20:59 UTC
    Code Review
    internal/state/state_skel.go:1
    @@ -442,9 +443,86 @@ func (s *stateSkel) mergeObjects(updated, current *unstructured.Unstructured) er
     	if gvk.Group == "" && gvk.Kind == "ServiceAccount" {
     		return s.mergeServiceAccount(updated, current)
     	}
    +	if gvk.Group == "" && gvk.Kind == "Service" {
    +		return s.mergeService(updated, current)
    +	}
    +	return nil
    +}
    +
    +// mergeService preserves fields allocated by the API server. Clearing these fields in a full
    +// update is rejected because their values are immutable or must remain allocated.
    +func (s *stateSkel) mergeService(updated, current *unstructured.Unstructured) error {
    +	updatedService := &corev1.Service{}
    +	if err := runtime.DefaultUnstructuredConverter.FromUnstructured(updated.Object, updatedService); err != nil {
    +		return fmt.Errorf("failed to convert updated Service: %w", err)
    +	}
    +	currentService := &corev1.Service{}
    +	if err := runtime.DefaultUnstructuredConverter.FromUnstructured(current.Object, currentService); err != nil {
    +		return fmt.Errorf("failed to convert current Service: %w", err)
    +	}
    +
    +	if updatedService.Spec.ClusterIP == "" && len(updatedService.Spec.ClusterIPs) == 0 {
    +		updatedService.Spec.ClusterIP = currentService.Spec.ClusterIP
    +		updatedService.Spec.ClusterIPs = currentService.Spec.ClusterIPs
    +	}
    +	if len(updatedService.Spec.IPFamilies) == 0 {
    +		updatedService.Spec.IPFamilies = currentService.Spec.IPFamilies
    +	}
    +	if updatedService.Spec.IPFamilyPolicy == nil {
    +		updatedService.Spec.IPFamilyPolicy = currentService.Spec.IPFamilyPolicy
    +	}
    +
    +	if serviceAllocatesNodePorts(updatedService) {
    +		for i := range updatedService.Spec.Ports {
    +			if updatedService.Spec.Ports[i].NodePort != 0 {
    +				continue
    +			}
    +			if currentPort := findMatchingServicePort(updatedService.Spec.Ports[i], currentService.Spec.Ports); currentPort != nil {
    +				updatedService.Spec.Ports[i].NodePort = currentPort.NodePort
    +			}
    +		}
    +	}
    +	if updatedService.Spec.Type == corev1.ServiceTypeLoadBalancer &&
    +		updatedService.Spec.ExternalTrafficPolicy == corev1.ServiceExternalTrafficPolicyLocal &&
    +		updatedService.Spec.HealthCheckNodePort == 0 {
    +		updatedService.Spec.HealthCheckNodePort = currentService.Spec.HealthCheckNodePort
    +	}
    +
    +	merged, err := runtime.DefaultUnstructuredConverter.ToUnstructured(updatedService)
    +	if err != nil {
    +		return fmt.Errorf("failed to convert merged Service: %w", err)
    +	}
    +	updated.Object = merged
    +	return nil
    +}
    +
    +func serviceAllocatesNodePorts(service *corev1.Service) bool {
    +	if service.Spec.Type == corev1.ServiceTypeNodePort {
    +		return true
    +	}
    +	return service.Spec.Type == corev1.ServiceTypeLoadBalancer &&
    +		(service.Spec.AllocateLoadBalancerNodePorts == nil || *service.Spec.AllocateLoadBalancerNodePorts)
    +}
    +
    +func findMatchingServicePort(updated corev1.ServicePort, current []corev1.ServicePort) *corev1.ServicePort {
    +	for i := range current {
    +		if updated.Name != "" && updated.Name == current[i].Name {
    +			return &current[i]
    +		}
    +		if updated.Name == "" && current[i].Name == "" && servicePortProtocol(updated) == servicePortProtocol(current[i]) {
    +			return &current[i]
    +		}
    +	}
     	return nil
     }
     
    +func servicePortProtocol(port corev1.ServicePort) corev1.Protocol {
    +	if port.Protocol == "" {
    +		return corev1.ProtocolTCP
    +	}
    +	return port.Protocol
    +}
    +
     // For Service Account, keep secrets if exists
     func (s *stateSkel) mergeServiceAccount(updated, current *unstructured.Unstructured) error {
     	curSecrets, ok, err := unstructured.NestedSlice(current.Object, "secrets")

    _🩺 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 -->

    coderabbitai[bot] coderabbitai[bot] commented on Sep 17, 2026 20:59 UTC
    Reviewer

    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 -->

    tariq1890 tariq1890 commented on code on Sep 17, 2026 21:05 UTC
    Code Review
    assets/state-dcgm-exporter/0800_daemonset.yaml:1
    @@ -3,6 +3,7 @@ kind: DaemonSet
     metadata:
       labels:
         app: nvidia-dcgm-exporter
    +    nvidia.com/gpu-operator.dcgm-exporter: "true"

    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.

    cdesiniotis cdesiniotis commented on code on Sep 17, 2026 21:31 UTC
    Code Review
    assets/state-dcgm-exporter/0800_daemonset.yaml:1
    @@ -3,6 +3,7 @@ kind: DaemonSet
     metadata:
       labels:
         app: nvidia-dcgm-exporter
    +    nvidia.com/gpu-operator.dcgm-exporter: "true"

    Maybe app.kubernetes.io/component: nvidia-dcgm-exporter?

    tariq1890 tariq1890 commented on code on Sep 17, 2026 21:38 UTC
    Code Review
    assets/state-dcgm-exporter/0800_daemonset.yaml:1
    @@ -3,6 +3,7 @@ kind: DaemonSet
     metadata:
       labels:
         app: nvidia-dcgm-exporter
    +    nvidia.com/gpu-operator.dcgm-exporter: "true"

    Yes, that could work. It is a standardised label

    rahulait rahulait commented on code on Sep 17, 2026 21:46 UTC
    Code Review
    assets/state-dcgm-exporter/0800_daemonset.yaml:1
    @@ -3,6 +3,7 @@ kind: DaemonSet
     metadata:
       labels:
         app: nvidia-dcgm-exporter
    +    nvidia.com/gpu-operator.dcgm-exporter: "true"

    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

    tariq1890 tariq1890 commented on code on Sep 17, 2026 23:39 UTC
    Code Review
    assets/state-dcgm-exporter/0800_daemonset.yaml:1
    @@ -3,6 +3,7 @@ kind: DaemonSet
     metadata:
       labels:
         app: nvidia-dcgm-exporter
    +    nvidia.com/gpu-operator.dcgm-exporter: "true"

    Looks like app.kubernetes.io/component has a specific meaning as per this K8s docs

    How about app.kubernetes.io/name instead?

    tariq1890 tariq1890 commented on code on Sep 17, 2026 23:42 UTC
    Code Review
    assets/state-dcgm-exporter/0800_daemonset.yaml:1
    @@ -3,6 +3,7 @@ kind: DaemonSet
     metadata:
       labels:
         app: nvidia-dcgm-exporter
    +    nvidia.com/gpu-operator.dcgm-exporter: "true"

    @rahulait I missed to mention this earlier, using a boolean as the label value typed seemed a bit off to me.

    rahulait rahulait commented on code on Oct 06, 2026 15:19 UTC
    Code Review
    assets/state-dcgm-exporter/0800_daemonset.yaml:1
    @@ -3,6 +3,7 @@ kind: DaemonSet
     metadata:
       labels:
         app: nvidia-dcgm-exporter
    +    nvidia.com/gpu-operator.dcgm-exporter: "true"

    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.

    rahulait rahulait commented on code on Oct 06, 2026 15:21 UTC
    Code Review
    assets/state-dcgm-exporter/0800_daemonset.yaml:1
    @@ -3,6 +3,7 @@ kind: DaemonSet
     metadata:
       labels:
         app: nvidia-dcgm-exporter
    +    nvidia.com/gpu-operator.dcgm-exporter: "true"

    @tariq1890 I still used app.kubernetes.io/component: as key as we have used the same for nvidia-driver as well.

    copy-pr-bot[bot] copy-pr-bot[bot] commented on Oct 23, 2026 14:40 UTC
    Bot

    This pull request requires additional validation before any workflows can run on NVIDIA's runners.

    Pull request vetters can view their responsibilities here.

    Contributors can view more details about this message here.

    devin-ai-integration[bot] devin-ai-integration[bot] commented on Oct 23, 2026 14:48 UTC
    Reviewer

    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 -->

    Reviewers
    Assignees
    rahulait rahulait
    Labels
    risk: low confidence: 89.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 59.9% (MEDIUM) · Higher = larger blast radius
    59.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 89.7% · Lower = rushed or shallow review
    89.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 6.2% · Safe to merge
    6.2%