Skip to content

Commit

Permalink
fix(vmip): fix deleting unattached vmip (#405)
Browse files Browse the repository at this point in the history
Signed-off-by: dmitry.lopatin <[email protected]>
  • Loading branch information
LopatinDmitr committed Sep 25, 2024
1 parent 46816b0 commit 21db1f7
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 21db1f7

Please sign in to comment.