fix: guard empty Values in injected anti-affinity check#4832
fix: guard empty Values in injected anti-affinity check#4832AruneshDwivedi wants to merge 1 commit into
Conversation
IfInjectedAntiAffinityRuleNeedsUpdate keyed a pod affinity term match by label only (via HasInjectedAntiAffinityRule) and then indexed Values[0]. A user-defined anti-affinity term using the rollouts-pod-template-hash key with Operator: Exists (no Values) made HasInjectedAntiAffinityRule match it, causing an index-out-of-range panic during reconcile. Guard the access with a length check so such terms are treated as not needing an update. Signed-off-by: Arunesh Dwivedi <arunesh.devops@gmail.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4832 +/- ##
==========================================
- Coverage 85.04% 85.01% -0.04%
==========================================
Files 166 166
Lines 19136 19136
==========================================
- Hits 16275 16269 -6
- Misses 2009 2012 +3
- Partials 852 855 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Published E2E Test Results 4 files 4 suites 3h 51m 35s ⏱️ For more details on these failures, see this check. Results for commit 3aa0c07. |
Published Unit Test Results2 516 tests 2 516 ✅ 3m 24s ⏱️ Results for commit 3aa0c07. |
kostis-codefresh
left a comment
There was a problem hiding this comment.
Is there an open issue about this?
Could you please post an example that showcases the problem first?
|
There isn't a separate issue open — this is the fix for a crash we hit in reconcile. Here's what triggers it.
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: rollouts-pod-template-hash
operator: Exists # no values
topologyKey: kubernetes.io/hostnameThen if labelSelectorRequirement.Key == v1alpha1.DefaultRolloutUniqueLabelKey && labelSelectorRequirement.Values[0] != rollout.Status.StableRS {
The fix guards with |



IfInjectedAntiAffinityRuleNeedsUpdate keyed a pod affinity term match by label only (via HasInjectedAntiAffinityRule) and then indexed Values[0]. A user-defined anti-affinity term using the rollouts-pod-template-hash key with Operator: Exists (no Values) made HasInjectedAntiAffinityRule match it, causing an index-out-of-range panic during reconcile.
Guard the access with a length check so such terms are treated as not needing an update.
Added a regression test in TestIfInjectedAntiAffinityRuleNeedsUpdate covering a term with no Values.