Skip to content

Commit d177e83

Browse files
committed
fix snapshot when vm has changes
Signed-off-by: Dmitry Lopatin <[email protected]>
1 parent 42fbf44 commit d177e83

File tree

3 files changed

+11
-32
lines changed

3 files changed

+11
-32
lines changed

api/core/v1alpha2/vmscondition/condition.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ const (
4141

4242
// WaitingForTheVirtualMachine signifies that the snapshot process is waiting for the virtual machine to become ready for snapshotting.
4343
WaitingForTheVirtualMachine VirtualMachineSnapshotReadyReason = "WaitingForTheVirtualMachine"
44-
// RestartAwaitingChanges signifies that the snapshotting process cannot begin because the virtual machine has awaiting changes.
45-
RestartAwaitingChanges VirtualMachineSnapshotReadyReason = "RestartAwaitingChanges"
4644
// BlockDevicesNotReady signifies that the snapshotting process cannot begin because the block devices of the virtual machine are not ready.
4745
BlockDevicesNotReady VirtualMachineSnapshotReadyReason = "BlockDevicesNotReady"
4846
// PotentiallyInconsistent signifies that the snapshotting process cannot begin because creating a snapshot of the running virtual machine might result in an inconsistent snapshot.

images/virtualization-artifact/pkg/controller/vmsnapshot/internal/life_cycle.go

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -190,25 +190,6 @@ func (h LifeCycleHandler) Handle(ctx context.Context, vmSnapshot *virtv2.Virtual
190190
return reconcile.Result{}, err
191191
}
192192

193-
// 2. Ensure there are no RestartAwaitingChanges.
194-
if len(vm.Status.RestartAwaitingChanges) > 0 {
195-
vmSnapshot.Status.Phase = virtv2.VirtualMachineSnapshotPhasePending
196-
msg := fmt.Sprintf(
197-
"Waiting for the restart and approval of changes to virtual machine %q before taking the snapshot.",
198-
vm.Name,
199-
)
200-
h.recorder.Event(
201-
vmSnapshot,
202-
corev1.EventTypeNormal,
203-
virtv2.ReasonVMSnapshottingPending,
204-
msg,
205-
)
206-
cb.
207-
Status(metav1.ConditionFalse).
208-
Reason(vmscondition.RestartAwaitingChanges).Message(msg)
209-
return reconcile.Result{}, nil
210-
}
211-
212193
needToFreeze := h.needToFreeze(vm, vmSnapshot.Spec.RequiredConsistency)
213194

214195
isAwaitingConsistency := needToFreeze && !h.snapshotter.CanFreeze(vm) && vmSnapshot.Spec.RequiredConsistency
@@ -260,7 +241,7 @@ func (h LifeCycleHandler) Handle(ctx context.Context, vmSnapshot *virtv2.Virtual
260241

261242
var hasFrozen bool
262243

263-
// 3. Ensure the virtual machine is consistent for snapshotting.
244+
// 2. Ensure the virtual machine is consistent for snapshotting.
264245
if needToFreeze {
265246
hasFrozen, err = h.freezeVirtualMachine(ctx, vm, vmSnapshot)
266247
if err != nil {
@@ -278,17 +259,17 @@ func (h LifeCycleHandler) Handle(ctx context.Context, vmSnapshot *virtv2.Virtual
278259
return reconcile.Result{}, nil
279260
}
280261

281-
// 4. Create secret.
262+
// 3. Create secret.
282263
err = h.ensureSecret(ctx, vm, vmSnapshot)
283264
if err != nil {
284265
h.setPhaseConditionToFailed(cb, vmSnapshot, err)
285266
return reconcile.Result{}, err
286267
}
287268

288-
// 5. Fill status.VirtualDiskSnapshotNames.
269+
// 4. Fill status.VirtualDiskSnapshotNames.
289270
h.fillStatusVirtualDiskSnapshotNames(vmSnapshot, vm)
290271

291-
// 6. Get or Create VirtualDiskSnapshots.
272+
// 5. Get or Create VirtualDiskSnapshots.
292273
vdSnapshots, err := h.ensureVirtualDiskSnapshots(ctx, vmSnapshot)
293274
switch {
294275
case err == nil:
@@ -314,7 +295,7 @@ func (h LifeCycleHandler) Handle(ctx context.Context, vmSnapshot *virtv2.Virtual
314295
return reconcile.Result{}, err
315296
}
316297

317-
// 7. Wait for VirtualDiskSnapshots to be Ready.
298+
// 6. Wait for VirtualDiskSnapshots to be Ready.
318299
readyCount := h.countReadyVirtualDiskSnapshots(vdSnapshots)
319300
msg := fmt.Sprintf(
320301
"Waiting for the virtual disk snapshots to be taken for "+
@@ -351,21 +332,21 @@ func (h LifeCycleHandler) Handle(ctx context.Context, vmSnapshot *virtv2.Virtual
351332
vmSnapshot.Status.Consistent = nil
352333
}
353334

354-
// 8. Unfreeze VirtualMachine if can.
335+
// 7. Unfreeze VirtualMachine if can.
355336
unfrozen, err := h.unfreezeVirtualMachineIfCan(ctx, vmSnapshot, vm)
356337
if err != nil {
357338
h.setPhaseConditionToFailed(cb, vmSnapshot, err)
358339
return reconcile.Result{}, err
359340
}
360341

361-
// 9. Fill status resources.
342+
// 8. Fill status resources.
362343
err = h.fillStatusResources(ctx, vmSnapshot, vm)
363344
if err != nil {
364345
h.setPhaseConditionToFailed(cb, vmSnapshot, err)
365346
return reconcile.Result{}, err
366347
}
367348

368-
// 10. Move to Ready phase.
349+
// 9. Move to Ready phase.
369350
log.Debug("The virtual disk snapshots are taken: the virtual machine snapshot is Ready now", "unfrozen", unfrozen)
370351

371352
vmSnapshot.Status.Phase = virtv2.VirtualMachineSnapshotPhaseReady

images/virtualization-artifact/pkg/controller/vmsnapshot/internal/life_cycle_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ var _ = Describe("LifeCycle handler", func() {
240240

241241
_, err := h.Handle(testContext(), vmSnapshot)
242242
Expect(err).To(BeNil())
243-
Expect(vmSnapshot.Status.Phase).To(Equal(virtv2.VirtualMachineSnapshotPhasePending))
243+
Expect(vmSnapshot.Status.Phase).To(Equal(virtv2.VirtualMachineSnapshotPhaseInProgress))
244244
ready, _ := conditions.GetCondition(vmscondition.VirtualMachineSnapshotReadyType, vmSnapshot.Status.Conditions)
245245
Expect(ready.Status).To(Equal(metav1.ConditionFalse))
246-
Expect(ready.Reason).To(Equal(vmscondition.RestartAwaitingChanges.String()))
247-
Expect(ready.Message).ToNot(BeEmpty())
246+
Expect(ready.Reason).To(Equal(vmscondition.FileSystemFreezing.String()))
247+
Expect(ready.Message).To(Equal("The snapshotting process has started."))
248248
})
249249

250250
It("The virtual machine is potentially inconsistent", func() {

0 commit comments

Comments
 (0)