@@ -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
}
@@ -1106,7 +1108,95 @@ func TestUnschedulablePodBecomesSchedulable(t *testing.T) {
1106
1108
return nil
1107
1109
},
1108
1110
},
1109
- // TODO(#91111): Add more test cases.
1111
+ {
1112
+ name : "pod with pod-affinity gets added" ,
1113
+ init : func (cs kubernetes.Interface , _ string ) error {
1114
+ node , err := createNode (cs , "node-1" , nil )
1115
+ if err != nil {
1116
+ return fmt .Errorf ("cannot create node: %v" , err )
1117
+ }
1118
+ // TODO(nodo): Use PodWrapper to directly initialize node with labels.
1119
+ if err := utils .AddLabelsToNode (cs , node .Name , map [string ]string {"region" : "test" }); err != nil {
1120
+ return fmt .Errorf ("cannot add labels to node: %v" , err )
1121
+ }
1122
+ return nil
1123
+ },
1124
+ pod : & pausePodConfig {
1125
+ Name : "pod-1" ,
1126
+ Affinity : & v1.Affinity {
1127
+ PodAffinity : & v1.PodAffinity {
1128
+ RequiredDuringSchedulingIgnoredDuringExecution : []v1.PodAffinityTerm {
1129
+ {
1130
+ LabelSelector : & metav1.LabelSelector {
1131
+ MatchLabels : map [string ]string {
1132
+ "pod-with-affinity" : "true" ,
1133
+ },
1134
+ },
1135
+ TopologyKey : "region" ,
1136
+ },
1137
+ },
1138
+ },
1139
+ },
1140
+ },
1141
+ update : func (cs kubernetes.Interface , ns string ) error {
1142
+ podConfig := & pausePodConfig {
1143
+ Name : "pod-with-affinity" ,
1144
+ Namespace : ns ,
1145
+ Labels : map [string ]string {
1146
+ "pod-with-affinity" : "true" ,
1147
+ },
1148
+ }
1149
+ if _ , err := createPausePod (cs , initPausePod (podConfig )); err != nil {
1150
+ return fmt .Errorf ("cannot create pod: %v" , err )
1151
+ }
1152
+ return nil
1153
+ },
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
+ },
1110
1200
}
1111
1201
for _ , tt := range tests {
1112
1202
t .Run (tt .name , func (t * testing.T ) {
0 commit comments