Skip to content

Commit

Permalink
fix(vm): unfreeze fs after snapshot (#561)
Browse files Browse the repository at this point in the history
* fix(vm): unfreeze fs after snapshot

Signed-off-by: Daniil Antoshin <[email protected]>
  • Loading branch information
danilrwx authored Dec 9, 2024
1 parent d2b7a8f commit fb2423c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ func (s *SnapshotService) CanUnfreeze(ctx context.Context, vdSnapshotName string
}

_, ok := vdByName[vdSnapshot.Spec.VirtualDiskName]
if ok {
if ok &&
vdSnapshot.Status.Phase != virtv2.VirtualDiskSnapshotPhaseReady &&
vdSnapshot.Status.Phase != virtv2.VirtualDiskSnapshotPhaseFailed &&
vdSnapshot.Status.Phase != virtv2.VirtualDiskSnapshotPhaseTerminating {
return false, nil
}
}
Expand All @@ -118,7 +121,10 @@ func (s *SnapshotService) CanUnfreeze(ctx context.Context, vdSnapshotName string
}

for _, vmSnapshot := range vmSnapshots.Items {
if vmSnapshot.Spec.VirtualMachineName == vm.Name {
if vmSnapshot.Spec.VirtualMachineName == vm.Name &&
vmSnapshot.Status.Phase != virtv2.VirtualMachineSnapshotPhaseReady &&
vmSnapshot.Status.Phase != virtv2.VirtualMachineSnapshotPhaseFailed &&
vmSnapshot.Status.Phase != virtv2.VirtualMachineSnapshotPhaseTerminating {
return false, nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ func (h LifeCycleHandler) Handle(ctx context.Context, vdSnapshot *virtv2.Virtual
switch vdSnapshot.Status.Phase {
case "":
vdSnapshot.Status.Phase = virtv2.VirtualDiskSnapshotPhasePending

case virtv2.VirtualDiskSnapshotPhaseFailed:
vdSnapshotCondition, _ := conditions.GetCondition(vdscondition.VirtualDiskSnapshotReadyType, vdSnapshot.Status.Conditions)

cb.
Status(metav1.ConditionFalse).
Reason(conditions.CommonReason(vdSnapshotCondition.Reason)).
Message(vdSnapshotCondition.Message)

return reconcile.Result{}, nil
case virtv2.VirtualDiskSnapshotPhaseReady:
if vs == nil || vs.Status == nil || vs.Status.ReadyToUse == nil || !*vs.Status.ReadyToUse {
vdSnapshot.Status.Phase = virtv2.VirtualDiskSnapshotPhaseFailed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ func (h LifeCycleHandler) Handle(ctx context.Context, vmSnapshot *virtv2.Virtual
switch vmSnapshot.Status.Phase {
case "":
vmSnapshot.Status.Phase = virtv2.VirtualMachineSnapshotPhasePending
case virtv2.VirtualMachineSnapshotPhaseFailed:
vmSnapshotCondition, _ := conditions.GetCondition(vmscondition.VirtualMachineSnapshotReadyType, vmSnapshot.Status.Conditions)

cb.
Status(metav1.ConditionFalse).
Reason(conditions.CommonReason(vmSnapshotCondition.Reason)).
Message(vmSnapshotCondition.Message)

return reconcile.Result{}, nil
case virtv2.VirtualMachineSnapshotPhaseReady:
// Ensure vd snapshots aren't lost.
var lostVDSnapshots []string
Expand Down

0 comments on commit fb2423c

Please sign in to comment.