Skip to content

Commit 8474942

Browse files
zhanggbjsrm09
andcommitted
Refine VMG controller when generate per-MD zone labels (#71)
* Refine VMG controller when generate per-MD zone labels - Skip legacy already-placed VM which do not have placement info - Skip VM which do not have zone info * Apply suggestions from code review --------- Co-authored-by: Sagar Muchhal <sagar.muchhal@broadcom.com>
1 parent 22d7db0 commit 8474942

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

controllers/vmware/virtualmachinegroup_reconciler.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ func (r *VirtualMachineGroupReconciler) createOrUpdateVMG(ctx context.Context, c
243243
// Do not update per-md-zone label once set, as placement decision should not change without user explicitly
244244
// ask.
245245
placementDecisionLabels, err := GenerateVMGPlacementLabels(ctx, desiredVMG, mdNames)
246+
if err != nil {
247+
return err
248+
}
246249
if len(placementDecisionLabels) > 0 {
247250
for k, v := range placementDecisionLabels {
248251
if _, exists := desiredVMG.Labels[k]; exists {
@@ -445,14 +448,17 @@ func GenerateVMGPlacementLabels(ctx context.Context, vmg *vmoprv1.VirtualMachine
445448
// TODO: Establish membership via the machine deployment name label
446449
if strings.Contains(member.Name, md) {
447450
// Get the VM placement information by member status.
451+
// VMs that have undergone placement do not have Placement info set, skip.
448452
if member.Placement == nil {
449-
return nil, errors.Errorf("VM %s in VMG %s/%s has no placement info. Placement is nil)", member.Name, vmg.Namespace, vmg.Name)
453+
log.V(4).Info("VM in VMG has no placement info. Placement is nil", "VM", member.Name, "VMG", vmg.Name, "Namespace", vmg.Namespace)
454+
continue
450455
}
451456

452-
// Get the VM placement information by member status.
457+
// Skip to next member if Zone is empty.
453458
zone := member.Placement.Zone
454459
if zone == "" {
455-
return nil, errors.Errorf("VM %s in VMG %s/%s has no placement info. Zone is empty", member.Name, vmg.Namespace, vmg.Name)
460+
log.V(4).Info("VM in VMG has no placement info. Zone is empty", "VM", member.Name, "VMG", vmg.Name, "Namespace", vmg.Namespace)
461+
continue
456462
}
457463

458464
log.Info(fmt.Sprintf("VM %s in VMG %s/%s has been placed in zone %s", member.Name, vmg.Namespace, vmg.Name, zone))

0 commit comments

Comments
 (0)