Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion utils/replicaset/replicaset.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func IfInjectedAntiAffinityRuleNeedsUpdate(affinity *corev1.Affinity, rollout v1
currentPodHash := hash.ComputePodTemplateHash(&rollout.Spec.Template, rollout.Status.CollisionCount)
if podAffinityTerm != nil && rollout.Status.StableRS != currentPodHash {
for _, labelSelectorRequirement := range podAffinityTerm.LabelSelector.MatchExpressions {
if labelSelectorRequirement.Key == v1alpha1.DefaultRolloutUniqueLabelKey && labelSelectorRequirement.Values[0] != rollout.Status.StableRS {
if labelSelectorRequirement.Key == v1alpha1.DefaultRolloutUniqueLabelKey && len(labelSelectorRequirement.Values) > 0 && labelSelectorRequirement.Values[0] != rollout.Status.StableRS {
return true
}
}
Expand Down
18 changes: 18 additions & 0 deletions utils/replicaset/replicaset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,24 @@ func TestIfInjectedAntiAffinityRuleNeedsUpdate(t *testing.T) {
}}

assert.True(t, IfInjectedAntiAffinityRuleNeedsUpdate(rsAffinity, ro))

// A pod affinity term keyed by the rollout unique label but with no Values
// (e.g. Operator: Exists) must not cause an index-out-of-range panic and
// should be treated as not needing an update.
rsAffinityExists := &corev1.Affinity{
PodAntiAffinity: &corev1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{{
Key: v1alpha1.DefaultRolloutUniqueLabelKey,
Operator: metav1.LabelSelectorOperator("Exists"),
}},
},
}},
},
}

assert.False(t, IfInjectedAntiAffinityRuleNeedsUpdate(rsAffinityExists, ro))
}

func TestNeedsRestart(t *testing.T) {
Expand Down
Loading