feat(utils): sort and unify map iteration in NodeSelector and affinity generation sites #6234
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 479 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.369
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #6234"
general
weight: 0.35
cheyang
Ⅰ. Describe what this PR does
Direct follow-up to #6217 and fixes #6220.
In #6216 and #6217,
MergeNodeSelectorAndNodeAffinitywas updated to sortnodeSelectorkeys alphabetically to ensure deterministic output order and prevent spurious status updates. During review of #6217, several other sites were identified where map iteration without key sorting caused non-deterministic ordering:1. Volume creation sites:
-
pkg/utils/dataset/volume/create.go:CreatePersistentVolumeForRuntimeiterated overnodeSelectormap directly when building PV node affinityMatchExpressions.-
pkg/ddc/efc/create_volume.go:createPersistentVolumeForRuntimeiterated overnodeSelectormap directly when building PV node affinityMatchExpressions.2. Webhook sites:
-
pkg/webhook/plugins/requirenodewithfuse/require_node_with_fuse.go:getRequiredSchedulingTermiterated overselectorsmap directly to appendMatchExpressions.-
pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache.go:getTieredLocalityPreferredSchedulingTermsandgetTieredLocalityNodeSelectorTermsiterated overpreferredRuntimesandruntimeInfosmaps directly, producing non-deterministic term order in mutated pod specs for pods bound to multiple datasets/runtimes.This PR addresses all these sites:
utils.ToNodeSelectorRequirements(selectors map[string]string) []corev1.NodeSelectorRequirementinpkg/utils/affinity.go, which converts selector maps into[]corev1.NodeSelectorRequirementsorted alphabetically by key.MergeNodeSelectorAndNodeAffinity(pkg/utils/kubeclient/pod.go),CreatePersistentVolumeForRuntime(pkg/utils/dataset/volume/create.go),createPersistentVolumeForRuntime(pkg/ddc/efc/create_volume.go), andRequireNodeWithFusewebhook (pkg/webhook/plugins/requirenodewithfuse) to useutils.ToNodeSelectorRequirements.NodeAffinityWithCachewebhook (pkg/webhook/plugins/nodeaffinitywithcache) to iterate overutils.OrderedKeys(preferredRuntimes)andutils.OrderedKeys(runtimeInfos), guaranteeing deterministic term order.Ⅱ. Does this pull request fix one issue?
fixes #6220
Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.
pkg/utils/affinity_test.go:- Added unit test
TestToNodeSelectorRequirementscovering nil map, empty map, single entry, multi-entry sorted, and 100 repeated iterations asserting deterministic ordering.pkg/webhook/plugins/requirenodewithfuse/require_node_with_fuse_test.go:- Added test case for multi-label fuse node selector verifying sorted
MatchExpressionsacross 50 iterations.pkg/utils/dataset/volume/create_test.go:- Added test case verifying PV node affinity match expressions are sorted alphabetically for multi-label selectors.
pkg/ddc/efc/create_volume_test.go:- Added test
TestEFCEngine_createFusePersistentVolumeWithNodeSelectorverifying PV node affinity match expressions are sorted alphabetically.pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache_test.go:- Added test
TestTieredLocalityDeterministicOrderingverifying that both preferred and required scheduling terms for multi-runtime pods are strictly sorted and deterministic across 50 iterations.Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews
None.