@@ -194,7 +194,6 @@ func (v *VmopMachineService) ReconcileNormal(ctx context.Context, machineCtx cap
194
194
// Set the VM state. Will get reset throughout the reconcile
195
195
supervisorMachineCtx .VSphereMachine .Status .VMStatus = vmwarev1 .VirtualMachineStatePending
196
196
197
- // var vmAffinitySpec *vmoprv1.VirtualMachineAffinitySpec
198
197
var affInfo affinityInfo
199
198
if feature .Gates .Enabled (feature .NodeAutoPlacement ) &&
200
199
! infrautilv1 .IsControlPlaneMachine (machineCtx .GetVSphereMachine ()) {
@@ -233,6 +232,21 @@ func (v *VmopMachineService) ReconcileNormal(ctx context.Context, machineCtx cap
233
232
affInfo .failureDomain = ptr .To (zone )
234
233
}
235
234
235
+ // Fetch machine deployments without explicit failureDomain specified
236
+ // to use when setting the anti-affinity rules
237
+ machineDeployments := & clusterv1.MachineDeploymentList {}
238
+ if err := v .Client .List (ctx , machineDeployments ,
239
+ client .InNamespace (supervisorMachineCtx .Cluster .Namespace ),
240
+ client.MatchingLabels {clusterv1 .ClusterNameLabel : supervisorMachineCtx .Cluster .Name }); err != nil {
241
+ return false , err
242
+ }
243
+ mdNames := []string {}
244
+ for _ , machineDeployment := range machineDeployments .Items {
245
+ if machineDeployment .Spec .Template .Spec .FailureDomain == "" && machineDeployment .Name != nodePool {
246
+ mdNames = append (mdNames , machineDeployment .Name )
247
+ }
248
+ }
249
+
236
250
affInfo .vmAffinitySpec = & vmoprv1.VirtualMachineAffinitySpec {
237
251
VMAffinity : & vmoprv1.VirtualMachineAffinityVMAffinitySpec {
238
252
RequiredDuringSchedulingIgnoredDuringExecution : []vmoprv1.VMAffinityTerm {
@@ -242,7 +256,7 @@ func (v *VmopMachineService) ReconcileNormal(ctx context.Context, machineCtx cap
242
256
clusterv1 .MachineDeploymentNameLabel : nodePool ,
243
257
},
244
258
},
245
- TopologyKey : kubeTopologyZoneLabelKey ,
259
+ TopologyKey : corev1 . LabelTopologyZone ,
246
260
},
247
261
},
248
262
},
@@ -253,14 +267,8 @@ func (v *VmopMachineService) ReconcileNormal(ctx context.Context, machineCtx cap
253
267
MatchLabels : map [string ]string {
254
268
clusterv1 .MachineDeploymentNameLabel : nodePool ,
255
269
},
256
- MatchExpressions : []metav1.LabelSelectorRequirement {
257
- {
258
- Key : clusterv1 .MachineControlPlaneLabel ,
259
- Operator : metav1 .LabelSelectorOpDoesNotExist ,
260
- },
261
- },
262
270
},
263
- TopologyKey : kubeHostNameLabelKey ,
271
+ TopologyKey : corev1 . LabelHostname ,
264
272
},
265
273
},
266
274
PreferredDuringSchedulingIgnoredDuringExecution : []vmoprv1.VMAffinityTerm {
@@ -269,16 +277,12 @@ func (v *VmopMachineService) ReconcileNormal(ctx context.Context, machineCtx cap
269
277
MatchExpressions : []metav1.LabelSelectorRequirement {
270
278
{
271
279
Key : clusterv1 .MachineDeploymentNameLabel ,
272
- Operator : metav1 .LabelSelectorOpNotIn ,
273
- Values : []string {nodePool },
274
- },
275
- {
276
- Key : clusterv1 .MachineControlPlaneLabel ,
277
- Operator : metav1 .LabelSelectorOpDoesNotExist ,
280
+ Operator : metav1 .LabelSelectorOpIn ,
281
+ Values : mdNames ,
278
282
},
279
283
},
280
284
},
281
- TopologyKey : kubeTopologyZoneLabelKey ,
285
+ TopologyKey : corev1 . LabelTopologyZone ,
282
286
},
283
287
},
284
288
},
@@ -845,7 +849,7 @@ func (v *VmopMachineService) addVolumes(ctx context.Context, supervisorMachineCt
845
849
846
850
if zone := supervisorMachineCtx .VSphereMachine .Spec .FailureDomain ; zonal && zone != nil {
847
851
topology := []map [string ]string {
848
- {kubeTopologyZoneLabelKey : * zone },
852
+ {corev1 . LabelTopologyZone : * zone },
849
853
}
850
854
b , err := json .Marshal (topology )
851
855
if err != nil {
@@ -930,12 +934,12 @@ func getTopologyLabels(supervisorMachineCtx *vmware.SupervisorMachineContext, fa
930
934
// TODO: Make it so that we always set the zone label, might require enquiring the zones present (when unset)
931
935
if fd := supervisorMachineCtx .VSphereMachine .Spec .FailureDomain ; fd != nil && * fd != "" {
932
936
return map [string ]string {
933
- kubeTopologyZoneLabelKey : * fd ,
937
+ corev1 . LabelTopologyZone : * fd ,
934
938
}
935
939
}
936
940
if failureDomain != nil && * failureDomain != "" {
937
941
return map [string ]string {
938
- kubeTopologyZoneLabelKey : * failureDomain ,
942
+ corev1 . LabelTopologyZone : * failureDomain ,
939
943
}
940
944
}
941
945
return nil
0 commit comments