← Back to Pull requests

fix(utils): sort nodeSelector keys in MergeNodeSelectorAndNodeAffinity to guarantee deterministic order #6217

Open
unknown opened this pull request with 217 lines diff across 2 files
View on GitHub
unknown unknown commented on Oct 21, 2026 05:23 UTC
Author

Ⅰ. Describe what this PR does


In pkg/utils/kubeclient/pod.go, MergeNodeSelectorAndNodeAffinity converts nodeSelector map entries into corev1.NodeSelectorRequirement match expressions. Because Go map iteration order is non-deterministic, multi-label nodeSelector maps resulted in MatchExpressions slices in arbitrary order across reconciliation cycles.

When controllers construct or compare status (such as status.CacheAffinity), the fluctuating slice order caused status equality checks (reflect.DeepEqual) to detect spurious differences, triggering unnecessary API server status writes and re-reconciliation loops on every cycle.

This PR sorts the keys of nodeSelector alphabetically before building MatchExpressions, guaranteeing deterministic output order across all cycles and runtimes (CacheRuntime, Alluxio, Jindo, JuiceFS, Thin, etc.).

Ⅱ. Does this pull request fix one issue?


fixes #6216

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.


  • pkg/utils/kubeclient/pod_test.go:

  • - Added test cases in DescribeTable for multi-label node selector (both with and without existing NodeSelectorTerms) verifying sorted MatchExpressions order.
    - Added regression tests running 100 repeated invocations on multi-label maps verifying byte-identical and order-identical output across calls for both fresh terms and appended terms.

    Ⅳ. Describe how to verify it


    go test -v ./pkg/utils/kubeclient -ginkgo.focus="MergeNodeSelectorAndNodeAffinity"
    

    Ⅴ. Special notes for reviews


  • Noted by @cheyang during review of #6200.

  • Pre-existing unsorted map-range sites across affinity webhooks and PV volume creation are tracked in #6220.
  • Diff: 217 lines (+162 / -55) across 2 files Reviewer: cheyang Review duration: 6836m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.37) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 217 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.322
    Real PR Conversation Timeline
    1 comments
    "Review active on #6217"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% 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: 36.7% (MEDIUM) · Higher = larger blast radius
    36.7%
    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: 43.0% · Lower = rushed or shallow review
    43.0%
    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: 20.9% · Safe to merge
    20.9%