@@ -68,9 +68,9 @@ var _ = Describe("VirtualMachineOperationRestore", func() {
6868 vmbda * v1alpha2.VirtualMachineBlockDeviceAttachment
6969 vmsnapshot * v1alpha2.VirtualMachineSnapshot
7070
71- vmoRestoreDryRun * v1alpha2.VirtualMachineOperation
72- vmoRestoreBestEffort * v1alpha2.VirtualMachineOperation
73- vmoRestoreStrict * v1alpha2.VirtualMachineOperation
71+ vmopRestoreDryRun * v1alpha2.VirtualMachineOperation
72+ vmopRestoreBestEffort * v1alpha2.VirtualMachineOperation
73+ vmopRestoreStrict * v1alpha2.VirtualMachineOperation
7474
7575 generatedValue string
7676 runningLastTransitionTime time.Time
@@ -101,6 +101,7 @@ var _ = Describe("VirtualMachineOperationRestore", func() {
101101 util .UntilVMBDAttached (crclient .ObjectKeyFromObject (vmbda ), framework .ShortTimeout )
102102 })
103103 By ("Create file on last disk" , func () {
104+ // Create a unique value on the disk to verify it's preserved after restore
104105 generatedValue = strconv .Itoa (time .Now ().UTC ().Second ())
105106 _ , err := f .SSHCommand (vm .Name , vm .Namespace , shellCreateFsAndSetValueOnDisk (generatedValue ))
106107 Expect (err ).NotTo (HaveOccurred ())
@@ -123,6 +124,7 @@ var _ = Describe("VirtualMachineOperationRestore", func() {
123124 util .UntilVMBDAttached (crclient .ObjectKeyFromObject (vmbda ), framework .ShortTimeout )
124125 })
125126 By ("Reboot VM" , func () {
127+ // Reboot VM to ensure configuration changes are applied and persisted
126128 err := f .UpdateFromCluster (context .Background (), vm )
127129 Expect (err ).NotTo (HaveOccurred ())
128130 runningCondition , _ := conditions .GetCondition (vmcondition .TypeRunning , vm .Status .Conditions )
@@ -134,33 +136,34 @@ var _ = Describe("VirtualMachineOperationRestore", func() {
134136 util .UntilVMBDAttached (crclient .ObjectKeyFromObject (vmbda ), framework .ShortTimeout )
135137 })
136138 By ("Create restore DryRun operation" , func () {
137- vmoRestoreDryRun = vmopbuilder .New (
139+ vmopRestoreDryRun = vmopbuilder .New (
138140 vmopbuilder .WithName ("restore-dry-run" ),
139141 vmopbuilder .WithNamespace (f .Namespace ().Name ),
140142 vmopbuilder .WithType (v1alpha2 .VMOPTypeRestore ),
141143 vmopbuilder .WithVirtualMachine (vm .Name ),
142144 vmopbuilder .WithVMOPRestoreMode (v1alpha2 .VMOPRestoreModeDryRun ),
143145 vmopbuilder .WithVirtualMachineSnapshotName (vmsnapshot .Name ),
144146 )
145- err := f .CreateWithDeferredDeletion (context .Background (), vmoRestoreDryRun )
147+ err := f .CreateWithDeferredDeletion (context .Background (), vmopRestoreDryRun )
146148 Expect (err ).NotTo (HaveOccurred ())
147- util .UntilVMOPCompleted (crclient .ObjectKeyFromObject (vmoRestoreDryRun ), framework .ShortTimeout )
149+ util .UntilVMOPCompleted (crclient .ObjectKeyFromObject (vmopRestoreDryRun ), framework .ShortTimeout )
148150 })
149151 By ("Check VM in changed state" , func () {
152+ // Verify that DryRun mode doesn't change the VM state
150153 checkVMInChangedState ()
151154 })
152155 By ("Create restore BestEffort operation" , func () {
153- vmoRestoreBestEffort = vmopbuilder .New (
156+ vmopRestoreBestEffort = vmopbuilder .New (
154157 vmopbuilder .WithName ("restore-best-effort" ),
155158 vmopbuilder .WithNamespace (f .Namespace ().Name ),
156159 vmopbuilder .WithType (v1alpha2 .VMOPTypeRestore ),
157160 vmopbuilder .WithVirtualMachine (vm .Name ),
158161 vmopbuilder .WithVMOPRestoreMode (v1alpha2 .VMOPRestoreModeBestEffort ),
159162 vmopbuilder .WithVirtualMachineSnapshotName (vmsnapshot .Name ),
160163 )
161- err := f .CreateWithDeferredDeletion (context .Background (), vmoRestoreBestEffort )
164+ err := f .CreateWithDeferredDeletion (context .Background (), vmopRestoreBestEffort )
162165 Expect (err ).NotTo (HaveOccurred ())
163- util .UntilVMOPCompleted (crclient .ObjectKeyFromObject (vmoRestoreBestEffort ), framework .LongTimeout )
166+ util .UntilVMOPCompleted (crclient .ObjectKeyFromObject (vmopRestoreBestEffort ), framework .LongTimeout )
164167 })
165168 By ("Check VM in restored state" , func () {
166169 util .UntilVMAgentReady (crclient .ObjectKeyFromObject (vm ), framework .LongTimeout )
@@ -185,20 +188,22 @@ var _ = Describe("VirtualMachineOperationRestore", func() {
185188 util .UntilVMBDAttached (crclient .ObjectKeyFromObject (vmbda ), framework .ShortTimeout )
186189 })
187190 By ("Remove resources" , func () {
191+ // Remove disks to simulate a scenario where resources from snapshot are missing.
192+ // Strict mode should still be able to restore by recreating missing resources.
188193 removeDisks ()
189194 })
190195 By ("Create restore Strict operation" , func () {
191- vmoRestoreStrict = vmopbuilder .New (
196+ vmopRestoreStrict = vmopbuilder .New (
192197 vmopbuilder .WithName ("restore-strict" ),
193198 vmopbuilder .WithNamespace (f .Namespace ().Name ),
194199 vmopbuilder .WithType (v1alpha2 .VMOPTypeRestore ),
195200 vmopbuilder .WithVirtualMachine (vm .Name ),
196201 vmopbuilder .WithVMOPRestoreMode (v1alpha2 .VMOPRestoreModeStrict ),
197202 vmopbuilder .WithVirtualMachineSnapshotName (vmsnapshot .Name ),
198203 )
199- err := f .CreateWithDeferredDeletion (context .Background (), vmoRestoreStrict )
204+ err := f .CreateWithDeferredDeletion (context .Background (), vmopRestoreStrict )
200205 Expect (err ).NotTo (HaveOccurred ())
201- util .UntilVMOPCompleted (crclient .ObjectKeyFromObject (vmoRestoreStrict ), framework .LongTimeout )
206+ util .UntilVMOPCompleted (crclient .ObjectKeyFromObject (vmopRestoreStrict ), framework .LongTimeout )
202207 })
203208 By ("Check VM in restored state" , func () {
204209 util .UntilVMAgentReady (crclient .ObjectKeyFromObject (vm ), framework .LongTimeout )
@@ -264,6 +269,11 @@ var _ = Describe("VirtualMachineOperationRestore", func() {
264269 }
265270
266271 changeVMConfiguration = func () {
272+ // Change VM configuration to verify restore functionality:
273+ // - Modify data on disk
274+ // - Change annotations and labels
275+ // - Update CPU and memory resources
276+ // After restore, all these should revert to original values from snapshot
267277 _ , err := f .SSHCommand (vm .Name , vm .Namespace , shellChangeValueOnDisk (changedValue ))
268278 Expect (err ).NotTo (HaveOccurred ())
269279 err = f .UpdateFromCluster (context .Background (), vm )
@@ -279,6 +289,10 @@ var _ = Describe("VirtualMachineOperationRestore", func() {
279289 }
280290
281291 checkVMInInitialState = func () {
292+ // Verify that VM has been restored to its initial state from snapshot:
293+ // - Disk contains the original value
294+ // - Annotations and labels match snapshot
295+ // - CPU and memory resources are restored to original values
282296 value , err := f .SSHCommand (vm .Name , vm .Namespace , shellMountAndGetValueFromDisk ())
283297 Expect (err ).NotTo (HaveOccurred ())
284298 Expect (strings .TrimSpace (value )).To (Equal (generatedValue ))
@@ -303,6 +317,7 @@ var _ = Describe("VirtualMachineOperationRestore", func() {
303317 }
304318
305319 removeDisks = func () {
320+ // Stop VM and remove all disks to test Strict restore mode.
306321 err := util .StopVirtualMachineFromOS (f , vm )
307322 Expect (err ).NotTo (HaveOccurred ())
308323 util .UntilVirtualMachineStopped (crclient .ObjectKeyFromObject (vm ), framework .ShortTimeout )
@@ -312,6 +327,7 @@ var _ = Describe("VirtualMachineOperationRestore", func() {
312327 err = f .Delete (context .Background (), vdBlank )
313328 Expect (err ).NotTo (HaveOccurred ())
314329
330+ // Wait for disks to be fully deleted before proceeding with restore
315331 Eventually (func (g Gomega ) {
316332 var vdRootLocal v1alpha2.VirtualDisk
317333 err = f .Clients .GenericClient ().Get (context .Background (), types.NamespacedName {
0 commit comments