Skip to content

Commit

Permalink
Merge branch 'main' into feat/vmop/impl-op-migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslavborbat authored Sep 26, 2024
2 parents b7f4673 + 21db1f7 commit 65293de
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func (h *ProtectionHandler) Handle(ctx context.Context, state state.VMIPState) (
return reconcile.Result{}, err
}

attachedVMs, err := h.getAttachedVM(ctx, vmip)
configuredVms, err := h.getConfiguredVM(ctx, vmip)
if err != nil {
return reconcile.Result{}, err
}

switch {
case len(attachedVMs) == 0:
case len(configuredVms) == 0:
log.Debug("Allow VirtualMachineIPAddress deletion")
controllerutil.RemoveFinalizer(vmip, virtv2.FinalizerIPAddressProtection)
case vmip.DeletionTimestamp == nil:
Expand All @@ -81,7 +81,7 @@ func (h *ProtectionHandler) Name() string {
return ProtectionHandlerName
}

func (h *ProtectionHandler) getAttachedVM(ctx context.Context, vmip *virtv2.VirtualMachineIPAddress) ([]virtv2.VirtualMachine, error) {
func (h *ProtectionHandler) getConfiguredVM(ctx context.Context, vmip *virtv2.VirtualMachineIPAddress) ([]virtv2.VirtualMachine, error) {
var vms virtv2.VirtualMachineList
err := h.client.List(ctx, &vms, &client.ListOptions{
Namespace: vmip.Namespace,
Expand All @@ -90,12 +90,12 @@ func (h *ProtectionHandler) getAttachedVM(ctx context.Context, vmip *virtv2.Virt
return nil, err
}

var attachedVMs []virtv2.VirtualMachine
var configuredVms []virtv2.VirtualMachine
for _, vm := range vms.Items {
if vm.Spec.VirtualMachineIPAddress == vmip.Name || vm.Status.VirtualMachineIPAddress == vmip.Name {
attachedVMs = append(attachedVMs, vm)
if vm.Spec.VirtualMachineIPAddress == vmip.Name && vm.Status.Phase != virtv2.MachineTerminating {
configuredVms = append(configuredVms, vm)
}
}

return attachedVMs, nil
return configuredVms, nil
}

0 comments on commit 65293de

Please sign in to comment.