Skip to content

Commit f430a47

Browse files
authored
Merge pull request kubernetes#84339 from wojtek-t/fix_deployment_correctness_at_scale
Fix deployment e2e test at scale
2 parents a3560d3 + 5cd06d1 commit f430a47

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

test/e2e/apps/deployment.go

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ func testRollingUpdateDeploymentWithLocalTrafficLoadBalancer(f *framework.Framew
888888
// inter-pod affinity for pods of different rollouts and anti-affinity
889889
// for pods of the same rollout, so it will need to be updated when
890890
// performing a rollout.
891-
setAffinity(d)
891+
setAffinities(d, false)
892892
d.Spec.Strategy.RollingUpdate = &appsv1.RollingUpdateDeployment{
893893
MaxSurge: intOrStrP(1),
894894
MaxUnavailable: intOrStrP(0),
@@ -943,7 +943,7 @@ func testRollingUpdateDeploymentWithLocalTrafficLoadBalancer(f *framework.Framew
943943
framework.Logf("Updating label deployment %q pod spec (iteration #%d)", name, i)
944944
deployment, err = e2edeploy.UpdateDeploymentWithRetries(c, ns, d.Name, func(update *appsv1.Deployment) {
945945
update.Spec.Template.Labels["iteration"] = fmt.Sprintf("%d", i)
946-
setAffinity(update)
946+
setAffinities(update, true)
947947
})
948948
framework.ExpectNoError(err)
949949

@@ -963,33 +963,38 @@ func testRollingUpdateDeploymentWithLocalTrafficLoadBalancer(f *framework.Framew
963963
}
964964
}
965965

966-
func setAffinity(d *appsv1.Deployment) {
967-
d.Spec.Template.Spec.Affinity = &v1.Affinity{
968-
PodAffinity: &v1.PodAffinity{
969-
PreferredDuringSchedulingIgnoredDuringExecution: []v1.WeightedPodAffinityTerm{
966+
// setAffinities set PodAntiAffinity across pods from the same generation
967+
// of Deployment and if, explicitly requested, also affinity with pods
968+
// from other generations.
969+
// It is required to make those "Required" so that in large clusters where
970+
// scheduler may not score all nodes if a lot of them are feasible, the
971+
// test will also have a chance to pass.
972+
func setAffinities(d *appsv1.Deployment, setAffinity bool) {
973+
affinity := &v1.Affinity{
974+
PodAntiAffinity: &v1.PodAntiAffinity{
975+
RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{
970976
{
971-
Weight: int32(100),
972-
PodAffinityTerm: v1.PodAffinityTerm{
973-
TopologyKey: "kubernetes.io/hostname",
974-
LabelSelector: &metav1.LabelSelector{
975-
MatchExpressions: []metav1.LabelSelectorRequirement{
976-
{
977-
Key: "name",
978-
Operator: metav1.LabelSelectorOpIn,
979-
Values: []string{d.Spec.Template.Labels["name"]},
980-
},
981-
{
982-
Key: "iteration",
983-
Operator: metav1.LabelSelectorOpNotIn,
984-
Values: []string{d.Spec.Template.Labels["iteration"]},
985-
},
977+
TopologyKey: "kubernetes.io/hostname",
978+
LabelSelector: &metav1.LabelSelector{
979+
MatchExpressions: []metav1.LabelSelectorRequirement{
980+
{
981+
Key: "name",
982+
Operator: metav1.LabelSelectorOpIn,
983+
Values: []string{d.Spec.Template.Labels["name"]},
984+
},
985+
{
986+
Key: "iteration",
987+
Operator: metav1.LabelSelectorOpIn,
988+
Values: []string{d.Spec.Template.Labels["iteration"]},
986989
},
987990
},
988991
},
989992
},
990993
},
991994
},
992-
PodAntiAffinity: &v1.PodAntiAffinity{
995+
}
996+
if setAffinity {
997+
affinity.PodAffinity = &v1.PodAffinity{
993998
RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{
994999
{
9951000
TopologyKey: "kubernetes.io/hostname",
@@ -1002,13 +1007,14 @@ func setAffinity(d *appsv1.Deployment) {
10021007
},
10031008
{
10041009
Key: "iteration",
1005-
Operator: metav1.LabelSelectorOpIn,
1010+
Operator: metav1.LabelSelectorOpNotIn,
10061011
Values: []string{d.Spec.Template.Labels["iteration"]},
10071012
},
10081013
},
10091014
},
10101015
},
10111016
},
1012-
},
1017+
}
10131018
}
1019+
d.Spec.Template.Spec.Affinity = affinity
10141020
}

0 commit comments

Comments
 (0)