← Back to Pull requests

reconcile nvidiadriver when any nodeselector label changes #3003

Merged
rahulait merged 2 files (261 lines) on Oct 05, 2026 13:12 UTC
View on GitHub
rahulait rahulait commented on Oct 02, 2026 15:24 UTC
Author

Description

Fixes https://github.com/NVIDIA/gpu-operator/issues/3004
<!-- Brief description of the change, including context or motivation -->
Fix node reconciliation when labels used by any NVIDIADriver selector change. Previously, only the current owner’s selector was checked, so unowned or default-owned nodes could remain assigned incorrectly.

Added regression tests for selector label changes and driver pool transitions.

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

    <!-- devin-review-badge-begin -->

    ---

    <a href="https://nvidia-cloud.devinenterprise.com/review/nvidia/gpu-operator/pull/3003" 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 -->

    Diff: 261 lines (+206 / -55) across 2 files Reviewer: tariq1890 Review duration: 4188m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.43) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 261 lines diff across 2 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.86 · 5 substantive comment(s)
    0.86
    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.333
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    18 items
    tariq1890 tariq1890 commented on code on Oct 02, 2026 16:42 UTC
    Code Review
    controllers/nodelabeling_controller.go:1
    @@ -125,6 +126,34 @@ func getNodeLabelUpdateReasons(oldLabels, newLabels map[string]string) nodeLabel
     	}
     }
     
    +func (r *NodeLabelingReconciler) driverNodeSelectorLabelsChanged(ctx context.Context, nodeName string, oldLabels, newLabels map[string]string) bool {
    +	if maps.Equal(oldLabels, newLabels) {
    +		return false
    +	}
    +
    +	// A node can enter another driver's pool even when its current owner is
    +	// the default driver or it has no owner, so inspect every live selector.
    +	drivers := &nvidiav1alpha1.NVIDIADriverList{}
    +	if err := r.List(ctx, drivers); err != nil {
    +		r.Log.Error(err, "failed to list NVIDIADrivers for node label update", "node", nodeName)
    +		// Enqueue reconciliation so a transient cache error cannot drop the update.
    +		return true
    +	}
    +	for _, driver := range drivers.Items {
    +		if driver.HasDeletionTimestamp() {
    +			continue
    +		}
    +		for key := range driver.Spec.NodeSelector {
    +			oldValue, oldPresent := oldLabels[key]
    +			newValue, newPresent := newLabels[key]
    +			if oldValue != newValue || oldPresent != newPresent {

    I don't understand the point of comparing the key presence here. If key is present in one, but absent in the other, won't the values be unequal anyway?

    tariq1890 tariq1890 commented on code on Oct 02, 2026 16:54 UTC
    Code Review
    controllers/nodelabeling_controller.go:1
    @@ -125,6 +126,34 @@ func getNodeLabelUpdateReasons(oldLabels, newLabels map[string]string) nodeLabel
     	}
     }
     
    +func (r *NodeLabelingReconciler) driverNodeSelectorLabelsChanged(ctx context.Context, nodeName string, oldLabels, newLabels map[string]string) bool {
    +	if maps.Equal(oldLabels, newLabels) {
    +		return false
    +	}
    +
    +	// A node can enter another driver's pool even when its current owner is
    +	// the default driver or it has no owner, so inspect every live selector.
    +	drivers := &nvidiav1alpha1.NVIDIADriverList{}
    +	if err := r.List(ctx, drivers); err != nil {
    +		r.Log.Error(err, "failed to list NVIDIADrivers for node label update", "node", nodeName)
    +		// Enqueue reconciliation so a transient cache error cannot drop the update.
    +		return true
    +	}
    +	for _, driver := range drivers.Items {

    Naive question. Why do we need this for loop L142-153? It's only checking a subset of the labels in oldLabels and newLabels, right? Isn't the L130 equality check more comprehensive thus making this for loop check redundant?

    tariq1890 tariq1890 commented on code on Oct 02, 2026 20:57 UTC
    Code Review
    controllers/nodelabeling_controller.go:1
    @@ -690,24 +719,10 @@ func (r *NodeLabelingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.
     			reasons := getNodeLabelUpdateReasons(oldLabels, newLabels)
     			needsUpdate := reasons.needsUpdate()
     
    -			// When an NVIDIADriver daemonset pod is running on the node, check if any
    -			// label which is configured in the NVIDIADriver's node selector has changed.
     			nvidiaDriverNodeSelectorLabelChanged := false
    -			if !needsUpdate && newLabels[consts.NVIDIADriverOwnerLabel] != "" {
    -				name := newLabels[consts.NVIDIADriverOwnerLabel]
    -				nvidiaDriver := &nvidiav1alpha1.NVIDIADriver{}
    -				err := r.Get(ctx, types.NamespacedName{Name: name}, nvidiaDriver)
    -				if err != nil {
    -					r.Log.Error(err, "failed to get NVIDIADriver object that owns this node", "name", name, "node", nodeName)
    -					return false
    -				}
    -				for key := range nvidiaDriver.Spec.NodeSelector {
    -					if oldLabels[key] != newLabels[key] {
    -						nvidiaDriverNodeSelectorLabelChanged = true
    -						needsUpdate = true
    -						break
    -					}
    -				}
    +			if !needsUpdate {
    +				nvidiaDriverNodeSelectorLabelChanged = r.driverNodeSelectorLabelsChanged(ctx, nodeName, oldLabels, newLabels)

    Can we OR this with reasons.needsUpdate() ?

    devin-ai-integration[bot] devin-ai-integration[bot] commented on code on Oct 02, 2026 21:31 UTC
    Code Review
    controllers/nodelabeling_controller.go:1
    @@ -123,6 +126,63 @@ func getNodeLabelUpdateReasons(oldLabels, newLabels map[string]string) nodeLabel
     		osTreeLabelChanged:           oldLabels[nfdOSTreeVersionLabelKey] != newLabels[nfdOSTreeVersionLabelKey],
     		nvidiaDriverOwnerLabelChange: oldLabels[consts.NVIDIADriverOwnerLabel] != newLabels[consts.NVIDIADriverOwnerLabel],
     	}
    +
    +	// A node can enter another driver's pool even when its current owner is
    +	// the default driver or it has no owner, so inspect every live selector.
    +	if !reasons.needsUpdate() && !maps.Equal(oldLabels, newLabels) {
    +		drivers := &nvidiav1alpha1.NVIDIADriverList{}
    +		if err := r.List(ctx, drivers); err != nil {

    <!-- devin-review-comment {"id": "ANALYSIS_pr-review-job-2ecc357b8faf429ea7224e9588e2fe99_0001", "file_path": "controllers/nodelabeling_controller.go", "start_line": 130, "end_line": 132, "side": "RIGHT", "kind": "analysis"} -->

    🔍 Driver lookup on unrelated node updates

    Every otherwise untracked node label change lists all NVIDIADrivers, even on non-GPU nodes or when no driver uses that label. Review the event rate before adding this cluster-wide lookup to the predicate.

    <!-- devin-review-badge-begin -->
    <a href="https://nvidia-cloud.devinenterprise.com/review/nvidia/gpu-operator/pull/3003" 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 Oct 02, 2026 21:31 UTC
    Reviewer

    Devin Review found 1 potential issue.

    <!-- devin-review-badge-begin -->
    <a href="https://nvidia-cloud.devinenterprise.com/review/nvidia/gpu-operator/pull/3003" 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 -->

    tariq1890 tariq1890 commented on code on Oct 02, 2026 21:37 UTC
    Code Review
    controllers/nodelabeling_controller.go:1
    @@ -123,6 +126,63 @@ func getNodeLabelUpdateReasons(oldLabels, newLabels map[string]string) nodeLabel
     		osTreeLabelChanged:           oldLabels[nfdOSTreeVersionLabelKey] != newLabels[nfdOSTreeVersionLabelKey],
     		nvidiaDriverOwnerLabelChange: oldLabels[consts.NVIDIADriverOwnerLabel] != newLabels[consts.NVIDIADriverOwnerLabel],
     	}
    +
    +	// A node can enter another driver's pool even when its current owner is
    +	// the default driver or it has no owner, so inspect every live selector.
    +	if !reasons.needsUpdate() && !maps.Equal(oldLabels, newLabels) {
    +		drivers := &nvidiav1alpha1.NVIDIADriverList{}
    +		if err := r.List(ctx, drivers); err != nil {
    +			return reasons, err
    +		}
    +		for _, driver := range drivers.Items {
    +			if driver.HasDeletionTimestamp() {
    +				continue
    +			}
    +			for key := range driver.Spec.NodeSelector {
    +				oldValue, oldPresent := oldLabels[key]
    +				newValue, newPresent := newLabels[key]
    +				if oldValue != newValue || oldPresent != newPresent {
    +					reasons.nvidiaDriverNodeSelectorLabelChanged = true
    +					break

    instead of having to break twice, why not return from here instead?

    					return reasons, nil
    

    rahulait rahulait commented on code on Oct 02, 2026 22:01 UTC
    Code Review
    controllers/nodelabeling_controller.go:1
    @@ -125,6 +126,34 @@ func getNodeLabelUpdateReasons(oldLabels, newLabels map[string]string) nodeLabel
     	}
     }
     
    +func (r *NodeLabelingReconciler) driverNodeSelectorLabelsChanged(ctx context.Context, nodeName string, oldLabels, newLabels map[string]string) bool {
    +	if maps.Equal(oldLabels, newLabels) {
    +		return false
    +	}
    +
    +	// A node can enter another driver's pool even when its current owner is
    +	// the default driver or it has no owner, so inspect every live selector.
    +	drivers := &nvidiav1alpha1.NVIDIADriverList{}
    +	if err := r.List(ctx, drivers); err != nil {
    +		r.Log.Error(err, "failed to list NVIDIADrivers for node label update", "node", nodeName)
    +		// Enqueue reconciliation so a transient cache error cannot drop the update.
    +		return true
    +	}
    +	for _, driver := range drivers.Items {

    Here, we are getting node selectors configured in all non-deleting nvds, since changes to those selector labels can affect node ownership. oldLabels and newLabels are just for the node; they don’t tell us which labels are used by nvidiadriver's nodeSelectors. We need those selectors to determine whether the label change should trigger reconciliation.

    tariq1890 tariq1890 commented on code on Oct 02, 2026 23:10 UTC
    Code Review
    controllers/nodelabeling_controller.go:1
    @@ -123,6 +126,60 @@ func getNodeLabelUpdateReasons(oldLabels, newLabels map[string]string) nodeLabel
     		osTreeLabelChanged:           oldLabels[nfdOSTreeVersionLabelKey] != newLabels[nfdOSTreeVersionLabelKey],
     		nvidiaDriverOwnerLabelChange: oldLabels[consts.NVIDIADriverOwnerLabel] != newLabels[consts.NVIDIADriverOwnerLabel],
     	}
    +
    +	// A node can enter another driver's pool even when its current owner is
    +	// the default driver or it has no owner, so inspect every live selector.
    +	if !reasons.needsUpdate() && !maps.Equal(oldLabels, newLabels) {

    Would this work? It feels a bit off to perform a needsUpdate() check on a reasons object that isn't completely filled up.

    	if !nvidiaDriverOwnerLabelChange && !maps.Equal(oldLabels, newLabels) {
    

    tariq1890 tariq1890 commented on code on Oct 02, 2026 23:13 UTC
    Code Review
    controllers/nodelabeling_controller.go:1
    @@ -125,6 +126,34 @@ func getNodeLabelUpdateReasons(oldLabels, newLabels map[string]string) nodeLabel
     	}
     }
     
    +func (r *NodeLabelingReconciler) driverNodeSelectorLabelsChanged(ctx context.Context, nodeName string, oldLabels, newLabels map[string]string) bool {
    +	if maps.Equal(oldLabels, newLabels) {
    +		return false
    +	}
    +
    +	// A node can enter another driver's pool even when its current owner is
    +	// the default driver or it has no owner, so inspect every live selector.
    +	drivers := &nvidiav1alpha1.NVIDIADriverList{}
    +	if err := r.List(ctx, drivers); err != nil {
    +		r.Log.Error(err, "failed to list NVIDIADrivers for node label update", "node", nodeName)
    +		// Enqueue reconciliation so a transient cache error cannot drop the update.
    +		return true
    +	}
    +	for _, driver := range drivers.Items {

    Ah yes, that makes sense. Thank you for the explanation!

    rahulait rahulait commented on code on Oct 02, 2026 23:47 UTC
    Code Review
    controllers/nodelabeling_controller.go:1
    @@ -123,6 +126,60 @@ func getNodeLabelUpdateReasons(oldLabels, newLabels map[string]string) nodeLabel
     		osTreeLabelChanged:           oldLabels[nfdOSTreeVersionLabelKey] != newLabels[nfdOSTreeVersionLabelKey],
     		nvidiaDriverOwnerLabelChange: oldLabels[consts.NVIDIADriverOwnerLabel] != newLabels[consts.NVIDIADriverOwnerLabel],
     	}
    +
    +	// A node can enter another driver's pool even when its current owner is
    +	// the default driver or it has no owner, so inspect every live selector.
    +	if !reasons.needsUpdate() && !maps.Equal(oldLabels, newLabels) {

    fair point, updated the code to return early and make it bit cleaner.

    tariq1890 tariq1890 commented on code on Oct 03, 2026 00:52 UTC
    Code Review
    controllers/nodelabeling_controller.go:1
    @@ -123,6 +126,64 @@ func getNodeLabelUpdateReasons(oldLabels, newLabels map[string]string) nodeLabel
     		osTreeLabelChanged:           oldLabels[nfdOSTreeVersionLabelKey] != newLabels[nfdOSTreeVersionLabelKey],
     		nvidiaDriverOwnerLabelChange: oldLabels[consts.NVIDIADriverOwnerLabel] != newLabels[consts.NVIDIADriverOwnerLabel],
     	}
    +
    +	if reasons.needsUpdate() || maps.Equal(oldLabels, newLabels) {
    +		return reasons, nil
    +	}
    +
    +	// A node can enter another driver's pool even when its current owner is
    +	// the default driver or it has no owner, so inspect every live selector.
    +	drivers := &nvidiav1alpha1.NVIDIADriverList{}
    +	if err := r.List(ctx, drivers); err != nil {
    +		return reasons, err

    nit: Better to log the error here as opposed to logging at the method call site. From the perspective of the method call site, the error wouldn't be specific.

    tariq1890 tariq1890 commented on Oct 03, 2026 00:53 UTC
    Reviewer

    Thanks @rahulait ! Just one minor comment and it should be good to go after

    rahulait rahulait commented on code on Oct 03, 2026 02:46 UTC
    Code Review
    controllers/nodelabeling_controller.go:1
    @@ -123,6 +126,64 @@ func getNodeLabelUpdateReasons(oldLabels, newLabels map[string]string) nodeLabel
     		osTreeLabelChanged:           oldLabels[nfdOSTreeVersionLabelKey] != newLabels[nfdOSTreeVersionLabelKey],
     		nvidiaDriverOwnerLabelChange: oldLabels[consts.NVIDIADriverOwnerLabel] != newLabels[consts.NVIDIADriverOwnerLabel],
     	}
    +
    +	if reasons.needsUpdate() || maps.Equal(oldLabels, newLabels) {
    +		return reasons, nil
    +	}
    +
    +	// A node can enter another driver's pool even when its current owner is
    +	// the default driver or it has no owner, so inspect every live selector.
    +	drivers := &nvidiav1alpha1.NVIDIADriverList{}
    +	if err := r.List(ctx, drivers); err != nil {
    +		return reasons, err

    updated.

    rahulait rahulait commented on Oct 03, 2026 02:49 UTC
    Author

    /cherry-pick release-26.7

    coderabbitai[bot] coderabbitai[bot] commented on Oct 03, 2026 02:50 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/3003?cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a>

    Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

    <!-- review_stack_entry_end -->
    <details>
    <summary>🧰 Additional context used</summary>

    <details>
    <summary>📚 Code guidelines (1)</summary>

    AGENTS.md — auto-discovered
    

    </details>

    </details>
    <!-- recent_review_start -->

    No actionable comments were generated in the recent review. 🎉

    <details>
    <summary>ℹ️ Recent review info</summary>

    <details>
    <summary>⚙️ Run configuration</summary>

  • Configuration used: Repository: NVIDIA/gpu-operator/.coderabbit.yaml

  • Review profile: QUIET

  • Plan: Enterprise

  • Run ID: 47f7b26d-8774-40a4-b5b5-099644c79fad
  • </details>

    <details>
    <summary>📥 Commits</summary>

    Reviewing files that changed from the base of the PR and between 3e1873a25ef46219f9b2db6f19a0b90818729586 and 787b23d589b6bc2b7ebda154c0c2fedf1c3e6fc9.

    </details>

    <details>
    <summary>📒 Files selected for processing (2)</summary>

    controllers/nodelabeling_controller.go
    controllers/nodelabeling_controller_test.go

    </details>

    Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

    </details>

    ---

    <!-- recent_review_end -->
    <!-- walkthrough_start -->

    <details>
    <summary>📝 Walkthrough</summary>

    Walkthrough

    Node update detection now checks changed node labels against selector keys from all non-deleting NVIDIADriver resources, rather than only the current owner. It skips driver listing when labels are unchanged or another update reason applies. A driver-list error causes the update to be enqueued. Tests cover selector-label additions, removals, and value changes, as well as deleting drivers and list-call conditions.

    </details>

    <!-- walkthrough_end -->
    <!-- change_assessment_start -->
    Priority: ➖ Normal

    <!-- change_assessment_commit:"787b23d589b6bc2b7ebda154c0c2fedf1c3e6fc9" -->
    Severity of issue fixed: Medium
    <!-- change_assessment_end -->
    <!-- final_review_risk_start -->
    Merge Risk: _⚪ Minimal_ · up to 787b2
    <!-- final_review_risk_coverage:{"sourceCommitId":"787b23d589b6bc2b7ebda154c0c2fedf1c3e6fc9","coveredCommitId":"787b23d589b6bc2b7ebda154c0c2fedf1c3e6fc9","kind":"reviewed"} -->

    The reviewed label-change detection covers the supported driver selectors, with no actionable merge risk identified. The change is ready for normal merge checks.
    <!-- final_review_risk_end -->
    <!-- autopilot:start -->

  • <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

  • <!-- autopilot:end -->
    <!-- tips_start -->

    ---

    <sub>Comment @coderabbitai help to get the list of available commands.</sub>

    <!-- tips_end -->

    tariq1890 tariq1890 approved these changes on Oct 03, 2026 02:57 UTC
    Approved Reviewer

    Approved these changes.

    github-actions[bot] github-actions[bot] commented on Oct 05, 2026 13:13 UTC
    Bot

    🤖 Backport PR created for release-26.7: #3007 ✅

    Reviewers
    Assignees
    rahulait rahulait
    Labels
    risk: low confidence: 89% 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: 42.8% (MEDIUM) · Higher = larger blast radius
    42.8%
    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% · Lower = rushed or shallow review
    89%
    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: 4.7% · Safe to merge
    4.7%