@@ -888,7 +888,7 @@ func testRollingUpdateDeploymentWithLocalTrafficLoadBalancer(f *framework.Framew
888
888
// inter-pod affinity for pods of different rollouts and anti-affinity
889
889
// for pods of the same rollout, so it will need to be updated when
890
890
// performing a rollout.
891
- setAffinity ( d )
891
+ setAffinities ( d , false )
892
892
d .Spec .Strategy .RollingUpdate = & appsv1.RollingUpdateDeployment {
893
893
MaxSurge : intOrStrP (1 ),
894
894
MaxUnavailable : intOrStrP (0 ),
@@ -943,7 +943,7 @@ func testRollingUpdateDeploymentWithLocalTrafficLoadBalancer(f *framework.Framew
943
943
framework .Logf ("Updating label deployment %q pod spec (iteration #%d)" , name , i )
944
944
deployment , err = e2edeploy .UpdateDeploymentWithRetries (c , ns , d .Name , func (update * appsv1.Deployment ) {
945
945
update .Spec .Template .Labels ["iteration" ] = fmt .Sprintf ("%d" , i )
946
- setAffinity (update )
946
+ setAffinities (update , true )
947
947
})
948
948
framework .ExpectNoError (err )
949
949
@@ -963,33 +963,38 @@ func testRollingUpdateDeploymentWithLocalTrafficLoadBalancer(f *framework.Framew
963
963
}
964
964
}
965
965
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 {
970
976
{
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" ]},
986
989
},
987
990
},
988
991
},
989
992
},
990
993
},
991
994
},
992
- PodAntiAffinity : & v1.PodAntiAffinity {
995
+ }
996
+ if setAffinity {
997
+ affinity .PodAffinity = & v1.PodAffinity {
993
998
RequiredDuringSchedulingIgnoredDuringExecution : []v1.PodAffinityTerm {
994
999
{
995
1000
TopologyKey : "kubernetes.io/hostname" ,
@@ -1002,13 +1007,14 @@ func setAffinity(d *appsv1.Deployment) {
1002
1007
},
1003
1008
{
1004
1009
Key : "iteration" ,
1005
- Operator : metav1 .LabelSelectorOpIn ,
1010
+ Operator : metav1 .LabelSelectorOpNotIn ,
1006
1011
Values : []string {d .Spec .Template .Labels ["iteration" ]},
1007
1012
},
1008
1013
},
1009
1014
},
1010
1015
},
1011
1016
},
1012
- },
1017
+ }
1013
1018
}
1019
+ d .Spec .Template .Spec .Affinity = affinity
1014
1020
}
0 commit comments