Skip to content

Commit 9f261d5

Browse files
srm09zhanggbj
authored andcommitted
Removes cluster-name label from affinity rules
Signed-off-by: Sagar Muchhal <sagar.muchhal@broadcom.com>
1 parent 124623a commit 9f261d5

File tree

2 files changed

+309
-19
lines changed

2 files changed

+309
-19
lines changed

pkg/services/vmoperator/vmopmachine.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23+
"sort"
2324

2425
"github.com/pkg/errors"
2526
vmoprv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
@@ -164,13 +165,11 @@ func (v *VmopMachineService) SyncFailureReason(_ context.Context, machineCtx cap
164165
return supervisorMachineCtx.VSphereMachine.Status.FailureReason != nil || supervisorMachineCtx.VSphereMachine.Status.FailureMessage != nil, nil
165166
}
166167

168+
// affinityInfo is an internal to store VM affinity information.
167169
type affinityInfo struct {
168170
affinitySpec *vmoprv1.AffinitySpec
169171
vmGroupName string
170172
failureDomain *string
171-
172-
// TODO: is this needed for the single zone case?
173-
// zones []topologyv1.Zone
174173
}
175174

176175
// ReconcileNormal reconciles create and update events for VM Operator VMs.
@@ -197,7 +196,6 @@ func (v *VmopMachineService) ReconcileNormal(ctx context.Context, machineCtx cap
197196
var affInfo affinityInfo
198197
if feature.Gates.Enabled(feature.NodeAutoPlacement) &&
199198
!infrautilv1.IsControlPlaneMachine(machineCtx.GetVSphereMachine()) {
200-
// Check for the presence of a VirtualMachineGroup with the name and namespace same as the name of the Cluster
201199
vmOperatorVMGroup := &vmoprv1.VirtualMachineGroup{}
202200
key := client.ObjectKey{
203201
Namespace: supervisorMachineCtx.Cluster.Namespace,
@@ -214,26 +212,24 @@ func (v *VmopMachineService) ReconcileNormal(ctx context.Context, machineCtx cap
214212
}
215213
}
216214

217-
// Check if the current machine is a member of the boot order
218-
// in the VirtualMachineGroup.
215+
// Proceed only if the machine is a member of the VirtualMachineGroup.
219216
if !v.checkVirtualMachineGroupMembership(vmOperatorVMGroup, supervisorMachineCtx) {
220217
log.V(4).Info("Waiting for VirtualMachineGroup membership, requeueing")
221218
return true, nil
222219
}
223220

224-
// Initialize the affinityInfo for the VM
225221
affInfo = affinityInfo{
226222
vmGroupName: vmOperatorVMGroup.Name,
227223
}
228224

229-
// Check the presence of the node-pool label on the VirtualMachineGroup object
225+
// Reuse the label from the node pool -> zone mapping.
230226
nodePool := supervisorMachineCtx.Machine.Labels[clusterv1.MachineDeploymentNameLabel]
231227
if zone, ok := vmOperatorVMGroup.Labels[fmt.Sprintf("zone.cluster.x-k8s.io/%s", nodePool)]; ok && zone != "" {
232228
affInfo.failureDomain = ptr.To(zone)
233229
}
234230

235231
// Fetch machine deployments without explicit failureDomain specified
236-
// to use when setting the anti-affinity rules
232+
// to use when setting the anti-affinity rules.
237233
machineDeployments := &clusterv1.MachineDeploymentList{}
238234
if err := v.Client.List(ctx, machineDeployments,
239235
client.InNamespace(supervisorMachineCtx.Cluster.Namespace),
@@ -242,14 +238,11 @@ func (v *VmopMachineService) ReconcileNormal(ctx context.Context, machineCtx cap
242238
}
243239
mdNames := []string{}
244240
for _, machineDeployment := range machineDeployments.Items {
245-
// Not adding node pool with explicit failureDomain specified to propose anti-affinity behavior
246-
// among node pools with automatic placement only.
247241
if machineDeployment.Spec.Template.Spec.FailureDomain == "" && machineDeployment.Name != nodePool {
248242
mdNames = append(mdNames, machineDeployment.Name)
249243
}
250244
}
251-
// turn to v4 log
252-
log.V(2).Info("Gathered anti-affine MDs", "mdNames", mdNames)
245+
sort.Strings(mdNames)
253246

254247
affInfo.affinitySpec = &vmoprv1.AffinitySpec{
255248
VMAffinity: &vmoprv1.VMAffinitySpec{
@@ -258,7 +251,6 @@ func (v *VmopMachineService) ReconcileNormal(ctx context.Context, machineCtx cap
258251
LabelSelector: &metav1.LabelSelector{
259252
MatchLabels: map[string]string{
260253
clusterv1.MachineDeploymentNameLabel: nodePool,
261-
clusterv1.ClusterNameLabel: supervisorMachineCtx.Cluster.Name,
262254
},
263255
},
264256
TopologyKey: corev1.LabelTopologyZone,
@@ -271,16 +263,12 @@ func (v *VmopMachineService) ReconcileNormal(ctx context.Context, machineCtx cap
271263
LabelSelector: &metav1.LabelSelector{
272264
MatchLabels: map[string]string{
273265
clusterv1.MachineDeploymentNameLabel: nodePool,
274-
clusterv1.ClusterNameLabel: supervisorMachineCtx.Cluster.Name,
275266
},
276267
},
277268
TopologyKey: corev1.LabelHostname,
278269
},
279270
{
280271
LabelSelector: &metav1.LabelSelector{
281-
MatchLabels: map[string]string{
282-
clusterv1.ClusterNameLabel: supervisorMachineCtx.Cluster.Name,
283-
},
284272
MatchExpressions: []metav1.LabelSelectorRequirement{
285273
{
286274
Key: clusterv1.MachineDeploymentNameLabel,
@@ -926,7 +914,9 @@ func getVMLabels(supervisorMachineCtx *vmware.SupervisorMachineContext, vmLabels
926914
vmLabels[clusterv1.ClusterNameLabel] = supervisorMachineCtx.GetClusterContext().Cluster.Name
927915

928916
// Ensure the VM has the machine deployment name label
929-
vmLabels[clusterv1.MachineDeploymentNameLabel] = supervisorMachineCtx.Machine.Labels[clusterv1.MachineDeploymentNameLabel]
917+
if !infrautilv1.IsControlPlaneMachine(supervisorMachineCtx.Machine) {
918+
vmLabels[clusterv1.MachineDeploymentNameLabel] = supervisorMachineCtx.Machine.Labels[clusterv1.MachineDeploymentNameLabel]
919+
}
930920

931921
return vmLabels
932922
}

0 commit comments

Comments
 (0)