Skip to content

Commit 440fb14

Browse files
authored
fix(vmop): exit maintenance mode after restore failure (#2094)
Description When a restore operation fails, the VM remains in maintenance mode because the lifecycle handler ignores the Failed phase and never calls ExitMaintenanceStep. This fix adds a check: for restore operations (vmop.Spec.Restore != nil), continue processing after Failed phase to allow ExitMaintenanceStep to run and exit maintenance mode. Also adds handling when VirtualDisk is not found during restore - instead of failing, wait for disk to appear (watcher will trigger reconcile). --------- Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
1 parent 2638e77 commit 440fb14

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

images/virtualization-artifact/pkg/controller/vmop/snapshot/internal/handler/lifecycle.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ func (h LifecycleHandler) Handle(ctx context.Context, vmop *v1alpha2.VirtualMach
6262
return reconcile.Result{}, nil
6363
}
6464

65+
maintenanced, foundMaintenance := conditions.GetCondition(vmopcondition.TypeMaintenanceMode, vmop.Status.Conditions)
66+
6567
// Ignore if VMOP is in final state or failed.
6668
if vmop.Status.Phase == v1alpha2.VMOPPhaseCompleted || vmop.Status.Phase == v1alpha2.VMOPPhaseFailed {
67-
return reconcile.Result{}, nil
69+
// Skip: not a restore operation OR already exited maintenance
70+
if vmop.Spec.Restore == nil || !foundMaintenance || maintenanced.Status == metav1.ConditionFalse {
71+
return reconcile.Result{}, nil
72+
}
6873
}
6974

7075
completed, completedFound := conditions.GetCondition(vmopcondition.TypeCompleted, vmop.Status.Conditions)

images/virtualization-artifact/pkg/controller/vmop/snapshot/internal/step/waiting_disk_ready_step.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222

23+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
"k8s.io/apimachinery/pkg/types"
2526
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -75,6 +76,11 @@ func (s WaitingDisksReadyStep) Take(ctx context.Context, vmop *v1alpha2.VirtualM
7576
vdKey := types.NamespacedName{Namespace: vmop.Namespace, Name: status.Name}
7677
err := s.client.Get(ctx, vdKey, &vd)
7778
if err != nil {
79+
if k8serrors.IsNotFound(err) {
80+
cb.Message("Waiting for resource readiness.")
81+
conditions.SetCondition(cb, &vmop.Status.Conditions)
82+
return nil, nil
83+
}
7884
return &reconcile.Result{}, fmt.Errorf("failed to get the `VirtualDisk`: %w", err)
7985
}
8086

0 commit comments

Comments
 (0)