Skip to content

Commit e5e2783

Browse files
author
Valeriy Khorunzhin
committed
rebase
Signed-off-by: Valeriy Khorunzhin <[email protected]>
1 parent e0dfe02 commit e5e2783

File tree

3 files changed

+38
-65
lines changed

3 files changed

+38
-65
lines changed

images/virtualization-artifact/pkg/builder/vmop/option.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func WithForce(force *bool) Option {
5252
}
5353
}
5454

55-
func WithVMOPRestoreMode(mode v1alpha2.VMOPRestoreMode) Option {
55+
func WithVMOPRestoreMode(mode v1alpha2.SnapshotOperationMode) Option {
5656
return func(vmop *v1alpha2.VirtualMachineOperation) {
5757
if vmop.Spec.Restore == nil {
5858
vmop.Spec.Restore = &v1alpha2.VirtualMachineOperationRestoreSpec{}

images/virtualization-artifact/pkg/builder/vmsnapshot/vdsnapshot.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

test/e2e/vmop/restore.go

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ const (
6060
vmLabelName = "vmLabelName"
6161
vmLabelOriginalValue = "vmLabelOriginalValue"
6262
vmLabelChangedValue = "vmLabelChangedValue"
63+
resourceAnnotationName = "resourceAnnotation"
64+
resourceAnnotationValue = "resourceAnnotationValue"
6365
changedValueOnDisk = "changedValueOnDisk"
6466
initialCPUCores = 1
6567
initialMemorySize = "256Mi"
@@ -68,7 +70,7 @@ const (
6870
)
6971

7072
var _ = Describe("VirtualMachineOperationRestore", func() {
71-
DescribeTable("restores a virtual machine from a snapshot", func(restoreMode v1alpha2.VMOPRestoreMode, restartApprovalMode v1alpha2.RestartApprovalMode, runPolicy v1alpha2.RunPolicy, removeRecoverableResources bool) {
73+
DescribeTable("restores a virtual machine from a snapshot", func(restoreMode v1alpha2.SnapshotOperationMode, restartApprovalMode v1alpha2.RestartApprovalMode, runPolicy v1alpha2.RunPolicy, removeRecoverableResources bool) {
7274
f := framework.NewFramework(fmt.Sprintf("vmop-restore-%s", strings.ToLower(string(restoreMode))))
7375
DeferCleanup(f.After)
7476
f.Before()
@@ -140,7 +142,7 @@ var _ = Describe("VirtualMachineOperationRestore", func() {
140142
err := f.CreateWithDeferredDeletion(context.Background(), t.VMOPRestore)
141143
Expect(err).NotTo(HaveOccurred())
142144
util.UntilObjectPhase(string(v1alpha2.VMOPPhaseCompleted), framework.LongTimeout, t.VMOPRestore)
143-
if restoreMode != v1alpha2.VMOPRestoreModeDryRun {
145+
if restoreMode != v1alpha2.SnapshotOperationModeDryRun {
144146
// after restore, the VM is in the Stopped state
145147
// if runPolicy == ManualPolicy, the VM should be started
146148
if runPolicy == v1alpha2.ManualPolicy {
@@ -156,7 +158,7 @@ var _ = Describe("VirtualMachineOperationRestore", func() {
156158
err := f.Clients.GenericClient().Get(context.Background(), crclient.ObjectKeyFromObject(t.VM), t.VM)
157159
Expect(err).NotTo(HaveOccurred())
158160

159-
if restoreMode == v1alpha2.VMOPRestoreModeDryRun {
161+
if restoreMode == v1alpha2.SnapshotOperationModeDryRun {
160162
err := f.Clients.GenericClient().Get(context.Background(), crclient.ObjectKeyFromObject(t.VMOPRestore), t.VMOPRestore)
161163
Expect(err).NotTo(HaveOccurred())
162164
restoreCompletedCondition, _ := conditions.GetCondition(vmopcondition.TypeRestoreCompleted, t.VMOPRestore.Status.Conditions)
@@ -182,14 +184,30 @@ var _ = Describe("VirtualMachineOperationRestore", func() {
182184
Expect(t.VM.Status.Resources.Memory.Size).To(Equal(resource.MustParse(initialMemorySize)))
183185
}
184186
})
187+
By("After restoration, verify that labels and annotations are preserved on the resources", func() {
188+
err := f.Clients.GenericClient().Get(context.Background(), crclient.ObjectKeyFromObject(t.VDRoot), t.VDRoot)
189+
Expect(err).NotTo(HaveOccurred())
190+
Expect(t.VDRoot.Annotations[resourceAnnotationName]).To(Equal(resourceAnnotationValue))
191+
Expect(t.VDRoot.Labels[resourceAnnotationName]).To(Equal(resourceAnnotationValue))
192+
193+
err = f.Clients.GenericClient().Get(context.Background(), crclient.ObjectKeyFromObject(t.VDBlank), t.VDBlank)
194+
Expect(err).NotTo(HaveOccurred())
195+
Expect(t.VDBlank.Annotations[resourceAnnotationName]).To(Equal(resourceAnnotationValue))
196+
Expect(t.VDBlank.Labels[resourceAnnotationName]).To(Equal(resourceAnnotationValue))
197+
198+
err = f.Clients.GenericClient().Get(context.Background(), crclient.ObjectKeyFromObject(t.VMBDA), t.VMBDA)
199+
Expect(err).NotTo(HaveOccurred())
200+
Expect(t.VMBDA.Annotations[resourceAnnotationName]).To(Equal(resourceAnnotationValue))
201+
Expect(t.VMBDA.Labels[resourceAnnotationName]).To(Equal(resourceAnnotationValue))
202+
})
185203
},
186-
Entry("DryRun restore mode with VM manual restart approval mode, always on unless stopped manually run policy", v1alpha2.VMOPRestoreModeDryRun, v1alpha2.Manual, v1alpha2.AlwaysOnUnlessStoppedManually, false),
187-
Entry("BestEffort restore mode with VM manual restart approval mode, always on unless stopped manually run policy", v1alpha2.VMOPRestoreModeBestEffort, v1alpha2.Manual, v1alpha2.AlwaysOnUnlessStoppedManually, false),
188-
Entry("Strict restore mode with VM manual restart approval mode, always on unless stopped manually run policy", v1alpha2.VMOPRestoreModeStrict, v1alpha2.Manual, v1alpha2.AlwaysOnUnlessStoppedManually, false),
189-
Entry("BestEffort restore mode with VM manual restart approval mode, always on unless stopped manually run policy with resource deletion", v1alpha2.VMOPRestoreModeBestEffort, v1alpha2.Manual, v1alpha2.AlwaysOnUnlessStoppedManually, true),
190-
Entry("Strict restore mode with VM manual restart approval mode, always on unless stopped manually run policy with resource deletion", v1alpha2.VMOPRestoreModeStrict, v1alpha2.Manual, v1alpha2.AlwaysOnUnlessStoppedManually, true),
191-
Entry("BestEffort restore mode with VM automatic restart approval mode, always on unless stopped manually run policy", v1alpha2.VMOPRestoreModeBestEffort, v1alpha2.Automatic, v1alpha2.AlwaysOnUnlessStoppedManually, false),
192-
Entry("BestEffort restore mode with VM automatic restart approval mode, manual run policy", v1alpha2.VMOPRestoreModeBestEffort, v1alpha2.Automatic, v1alpha2.ManualPolicy, false),
204+
Entry("DryRun restore mode with VM manual restart approval mode, always on unless stopped manually run policy", v1alpha2.SnapshotOperationModeDryRun, v1alpha2.Manual, v1alpha2.AlwaysOnUnlessStoppedManually, false),
205+
Entry("BestEffort restore mode with VM manual restart approval mode, always on unless stopped manually run policy", v1alpha2.SnapshotOperationModeBestEffort, v1alpha2.Manual, v1alpha2.AlwaysOnUnlessStoppedManually, false),
206+
Entry("Strict restore mode with VM manual restart approval mode, always on unless stopped manually run policy", v1alpha2.SnapshotOperationModeStrict, v1alpha2.Manual, v1alpha2.AlwaysOnUnlessStoppedManually, false),
207+
Entry("BestEffort restore mode with VM manual restart approval mode, always on unless stopped manually run policy with resource deletion", v1alpha2.SnapshotOperationModeBestEffort, v1alpha2.Manual, v1alpha2.AlwaysOnUnlessStoppedManually, true),
208+
Entry("Strict restore mode with VM manual restart approval mode, always on unless stopped manually run policy with resource deletion", v1alpha2.SnapshotOperationModeStrict, v1alpha2.Manual, v1alpha2.AlwaysOnUnlessStoppedManually, true),
209+
Entry("BestEffort restore mode with VM automatic restart approval mode, always on unless stopped manually run policy", v1alpha2.SnapshotOperationModeBestEffort, v1alpha2.Automatic, v1alpha2.AlwaysOnUnlessStoppedManually, false),
210+
Entry("BestEffort restore mode with VM automatic restart approval mode, manual run policy", v1alpha2.SnapshotOperationModeBestEffort, v1alpha2.Automatic, v1alpha2.ManualPolicy, false),
193211
)
194212
})
195213

@@ -214,7 +232,7 @@ func newRestoreTest(f *framework.Framework) *restoreModeTest {
214232
}
215233
}
216234

217-
func (t *restoreModeTest) GenerateEnvironmentResources(restoreMode v1alpha2.VMOPRestoreMode, restartApprovalMode v1alpha2.RestartApprovalMode, runPolicy v1alpha2.RunPolicy) {
235+
func (t *restoreModeTest) GenerateEnvironmentResources(restoreMode v1alpha2.SnapshotOperationMode, restartApprovalMode v1alpha2.RestartApprovalMode, runPolicy v1alpha2.RunPolicy) {
218236
t.CVI = cvibuilder.New(
219237
cvibuilder.WithName(fmt.Sprintf("%s-cvi", t.Framework.Namespace().Name)),
220238
cvibuilder.WithDataSourceHTTP(minimalCVIURL, nil, nil),
@@ -233,12 +251,16 @@ func (t *restoreModeTest) GenerateEnvironmentResources(restoreMode v1alpha2.VMOP
233251
vdbuilder.WithDataSourceHTTP(&v1alpha2.DataSourceHTTP{
234252
URL: object.ImageURLUbuntu,
235253
}),
254+
vdbuilder.WithAnnotation(resourceAnnotationName, resourceAnnotationValue),
255+
vdbuilder.WithLabel(resourceAnnotationName, resourceAnnotationValue),
236256
)
237257

238258
t.VDBlank = vdbuilder.New(
239259
vdbuilder.WithName("vd-blank"),
240260
vdbuilder.WithNamespace(t.Framework.Namespace().Name),
241261
vdbuilder.WithPersistentVolumeClaim(nil, ptr.To(resource.MustParse("51Mi"))),
262+
vdbuilder.WithAnnotation(resourceAnnotationName, resourceAnnotationValue),
263+
vdbuilder.WithLabel(resourceAnnotationName, resourceAnnotationValue),
242264
)
243265

244266
t.VM = vmbuilder.New(
@@ -278,6 +300,8 @@ func (t *restoreModeTest) GenerateEnvironmentResources(restoreMode v1alpha2.VMOP
278300
vmbdabuilder.WithNamespace(t.VDBlank.Namespace),
279301
vmbdabuilder.WithVirtualMachineName(t.VM.Name),
280302
vmbdabuilder.WithBlockDeviceRef(v1alpha2.VMBDAObjectRefKindVirtualDisk, t.VDBlank.Name),
303+
vmbdabuilder.WithAnnotation(resourceAnnotationName, resourceAnnotationValue),
304+
vmbdabuilder.WithLabel(resourceAnnotationName, resourceAnnotationValue),
281305
)
282306

283307
t.VMSnapshot = vmsnapshotbuilder.New(
@@ -396,11 +420,11 @@ func (t *restoreModeTest) CheckResourceReadyForRestore(kind, name string) {
396420

397421
resourceForRestore := t.getResourceInfoFromVMOP(kind, name)
398422
Expect(resourceForRestore).ShouldNot(BeNil())
399-
Expect(resourceForRestore.Status).Should(Equal(v1alpha2.VMOPResourceStatusCompleted))
423+
Expect(resourceForRestore.Status).Should(Equal(v1alpha2.SnapshotResourceStatusCompleted))
400424
Expect(resourceForRestore.Message).Should(ContainSubstring("is valid for restore"))
401425
}
402426

403-
func (t *restoreModeTest) getResourceInfoFromVMOP(kind, name string) *v1alpha2.VirtualMachineOperationResource {
427+
func (t *restoreModeTest) getResourceInfoFromVMOP(kind, name string) *v1alpha2.SnapshotResourceStatus {
404428
for _, resourceForRestore := range t.VMOPRestore.Status.Resources {
405429
if resourceForRestore.Name == name && resourceForRestore.Kind == kind {
406430
return &resourceForRestore

0 commit comments

Comments
 (0)