@@ -54,6 +54,7 @@ func TestInterPodAffinity(t *testing.T) {
54
54
"zone" : "z11" ,
55
55
}
56
56
for _ , node := range nodes {
57
+ // TODO(nodo): Use PodWrapper to directly initialize node with labels.
57
58
if err = utils .AddLabelsToNode (testCtx .ClientSet , node .Name , labels1 ); err != nil {
58
59
t .Fatalf ("Cannot add labels to node: %v" , err )
59
60
}
@@ -895,6 +896,7 @@ func TestEvenPodsSpreadPredicate(t *testing.T) {
895
896
"zone" : fmt .Sprintf ("zone-%d" , i / 2 ),
896
897
"node" : node .Name ,
897
898
}
899
+ // TODO(nodo): Use PodWrapper to directly initialize node with labels.
898
900
if err = utils .AddLabelsToNode (cs , node .Name , labels ); err != nil {
899
901
t .Fatalf ("Cannot add labels to node: %v" , err )
900
902
}
@@ -1113,6 +1115,7 @@ func TestUnschedulablePodBecomesSchedulable(t *testing.T) {
1113
1115
if err != nil {
1114
1116
return fmt .Errorf ("cannot create node: %v" , err )
1115
1117
}
1118
+ // TODO(nodo): Use PodWrapper to directly initialize node with labels.
1116
1119
if err := utils .AddLabelsToNode (cs , node .Name , map [string ]string {"region" : "test" }); err != nil {
1117
1120
return fmt .Errorf ("cannot add labels to node: %v" , err )
1118
1121
}
@@ -1149,6 +1152,51 @@ func TestUnschedulablePodBecomesSchedulable(t *testing.T) {
1149
1152
return nil
1150
1153
},
1151
1154
},
1155
+ {
1156
+ name : "scheduled pod gets updated to match affinity" ,
1157
+ init : func (cs kubernetes.Interface , ns string ) error {
1158
+ node , err := createNode (cs , "node-1" , nil )
1159
+ if err != nil {
1160
+ return fmt .Errorf ("cannot create node: %v" , err )
1161
+ }
1162
+ // TODO(nodo): Use PodWrapper to directly initialize node with labels.
1163
+ if err := utils .AddLabelsToNode (cs , node .Name , map [string ]string {"region" : "test" }); err != nil {
1164
+ return fmt .Errorf ("cannot add labels to node: %v" , err )
1165
+ }
1166
+ if _ , err := createPausePod (cs , initPausePod (& pausePodConfig {Name : "pod-to-be-updated" , Namespace : ns })); err != nil {
1167
+ return fmt .Errorf ("cannot create pod: %v" , err )
1168
+ }
1169
+ return nil
1170
+ },
1171
+ pod : & pausePodConfig {
1172
+ Name : "pod-1" ,
1173
+ Affinity : & v1.Affinity {
1174
+ PodAffinity : & v1.PodAffinity {
1175
+ RequiredDuringSchedulingIgnoredDuringExecution : []v1.PodAffinityTerm {
1176
+ {
1177
+ LabelSelector : & metav1.LabelSelector {
1178
+ MatchLabels : map [string ]string {
1179
+ "pod-with-affinity" : "true" ,
1180
+ },
1181
+ },
1182
+ TopologyKey : "region" ,
1183
+ },
1184
+ },
1185
+ },
1186
+ },
1187
+ },
1188
+ update : func (cs kubernetes.Interface , ns string ) error {
1189
+ pod , err := getPod (cs , "pod-to-be-updated" , ns )
1190
+ if err != nil {
1191
+ return fmt .Errorf ("cannot get pod: %v" , err )
1192
+ }
1193
+ pod .Labels = map [string ]string {"pod-with-affinity" : "true" }
1194
+ if _ , err := cs .CoreV1 ().Pods (pod .Namespace ).Update (context .TODO (), pod , metav1.UpdateOptions {}); err != nil {
1195
+ return fmt .Errorf ("cannot update pod: %v" , err )
1196
+ }
1197
+ return nil
1198
+ },
1199
+ },
1152
1200
}
1153
1201
for _ , tt := range tests {
1154
1202
t .Run (tt .name , func (t * testing.T ) {
0 commit comments