diff --git a/api/core/v1alpha2/events.go b/api/core/v1alpha2/events.go index f0c3dfc2dc..4c1b878918 100644 --- a/api/core/v1alpha2/events.go +++ b/api/core/v1alpha2/events.go @@ -105,6 +105,8 @@ const ( // ReasonVIStorageClassNotFound is event reason that VIStorageClass not found. ReasonVIStorageClassNotFound = "VirtualImageStorageClassNotFound" + // ReasonMetadataSyncStarted is event reason that Metadata sync is started. + ReasonMetadataSyncStarted = "MetadataSyncStarted" // ReasonDataSourceSyncStarted is event reason that DataSource sync is started. ReasonDataSourceSyncStarted = "DataSourceImportStarted" // ReasonDataSourceSyncInProgress is event reason that DataSource sync is in progress. diff --git a/images/virtualization-artifact/pkg/common/vdsnapshot/vdsnapshot.go b/images/virtualization-artifact/pkg/common/vdsnapshot/vdsnapshot.go deleted file mode 100644 index fcbd908cf4..0000000000 --- a/images/virtualization-artifact/pkg/common/vdsnapshot/vdsnapshot.go +++ /dev/null @@ -1,72 +0,0 @@ -/* -Copyright 2025 Flant JSC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package vdsnapshot - -import ( - "encoding/json" - "fmt" - - vsv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1" - - "github.com/deckhouse/virtualization-controller/pkg/common/annotations" - "github.com/deckhouse/virtualization/api/core/v1alpha2" -) - -// AddOriginalMetadata adds original annotations and labels from VolumeSnapshot to VirtualDisk, -// without overwriting existing values -func AddOriginalMetadata(vd *v1alpha2.VirtualDisk, vs *vsv1.VolumeSnapshot) error { - var ( - labelsMap map[string]string - annotationsMap map[string]string - ) - - if vs != nil && vs.Annotations != nil { - if vs.Annotations[annotations.AnnVirtualDiskOriginalLabels] != "" { - err := json.Unmarshal([]byte(vs.Annotations[annotations.AnnVirtualDiskOriginalLabels]), &labelsMap) - if err != nil { - return fmt.Errorf("failed to unmarshal the original labels: %w", err) - } - } - - if vd.Labels == nil { - vd.Labels = make(map[string]string) - } - for key, value := range labelsMap { - if _, exists := vd.Labels[key]; !exists { - vd.Labels[key] = value - } - } - - if vs.Annotations[annotations.AnnVirtualDiskOriginalAnnotations] != "" { - err := json.Unmarshal([]byte(vs.Annotations[annotations.AnnVirtualDiskOriginalAnnotations]), &annotationsMap) - if err != nil { - return fmt.Errorf("failed to unmarshal the original annotations: %w", err) - } - } - - if vd.Annotations == nil { - vd.Annotations = make(map[string]string) - } - for key, value := range annotationsMap { - if _, exists := vd.Annotations[key]; !exists { - vd.Annotations[key] = value - } - } - } - - return nil -} diff --git a/images/virtualization-artifact/pkg/controller/service/restorer/snapshot_resources.go b/images/virtualization-artifact/pkg/controller/service/restorer/snapshot_resources.go index 1b825b8481..fdb401e470 100644 --- a/images/virtualization-artifact/pkg/controller/service/restorer/snapshot_resources.go +++ b/images/virtualization-artifact/pkg/controller/service/restorer/snapshot_resources.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" - vsv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -29,7 +28,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "github.com/deckhouse/virtualization-controller/pkg/common/object" - commonvdsnapshot "github.com/deckhouse/virtualization-controller/pkg/common/vdsnapshot" "github.com/deckhouse/virtualization-controller/pkg/controller/service/restorer/common" restorer "github.com/deckhouse/virtualization-controller/pkg/controller/service/restorer/restorers" "github.com/deckhouse/virtualization/api/core/v1alpha2" @@ -365,23 +363,6 @@ func getVirtualDisks(ctx context.Context, client client.Client, vmSnapshot *v1al }, } - if vdSnapshot.Status.VolumeSnapshotName != "" { - vsKey := types.NamespacedName{ - Namespace: vdSnapshot.Namespace, - Name: vdSnapshot.Status.VolumeSnapshotName, - } - - vs, err := object.FetchObject(ctx, vsKey, client, &vsv1.VolumeSnapshot{}) - if err != nil { - return nil, fmt.Errorf("failed to fetch the volume snapshot %q: %w", vsKey.Name, err) - } - - err = commonvdsnapshot.AddOriginalMetadata(&vd, vs) - if err != nil { - return nil, fmt.Errorf("failed to add original metadata: %w", err) - } - } - vds = append(vds, &vd) } diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/source/object_ref_vdsnapshot.go b/images/virtualization-artifact/pkg/controller/vd/internal/source/object_ref_vdsnapshot.go index 66f210f75e..dda9aebf71 100644 --- a/images/virtualization-artifact/pkg/controller/vd/internal/source/object_ref_vdsnapshot.go +++ b/images/virtualization-artifact/pkg/controller/vd/internal/source/object_ref_vdsnapshot.go @@ -69,6 +69,7 @@ func (ds ObjectRefVirtualDiskSnapshot) Sync(ctx context.Context, vd *v1alpha2.Vi return steptaker.NewStepTakers[*v1alpha2.VirtualDisk]( step.NewReadyStep(ds.diskService, pvc, cb), step.NewTerminatingStep(pvc), + step.NewAddOriginalMetadataStep(ds.recorder, ds.client, cb), step.NewCreatePVCFromVDSnapshotStep(pvc, ds.recorder, ds.client, cb), step.NewWaitForPVCStep(pvc, ds.client, cb), ).Run(ctx, vd) diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/source/object_ref_vdsnapshot_test.go b/images/virtualization-artifact/pkg/controller/vd/internal/source/object_ref_vdsnapshot_test.go index 53dbe96689..8c3fd3a071 100644 --- a/images/virtualization-artifact/pkg/controller/vd/internal/source/object_ref_vdsnapshot_test.go +++ b/images/virtualization-artifact/pkg/controller/vd/internal/source/object_ref_vdsnapshot_test.go @@ -18,6 +18,7 @@ package source import ( "context" + "fmt" "log/slog" "testing" @@ -34,6 +35,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" "sigs.k8s.io/controller-runtime/pkg/client/interceptor" + "github.com/deckhouse/virtualization-controller/pkg/common/annotations" "github.com/deckhouse/virtualization-controller/pkg/controller/conditions" "github.com/deckhouse/virtualization-controller/pkg/controller/supplements" "github.com/deckhouse/virtualization-controller/pkg/eventrecord" @@ -185,7 +187,7 @@ var _ = Describe("ObjectRef VirtualDiskSnapshot", func() { It("waits for the first consumer", func() { pvc.Status.Phase = corev1.ClaimPending sc.VolumeBindingMode = ptr.To(storagev1.VolumeBindingWaitForFirstConsumer) - client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(pvc, sc).Build() + client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(pvc, sc, vdSnapshot, vs).Build() syncer := NewObjectRefVirtualDiskSnapshot(recorder, svc, client) @@ -200,7 +202,7 @@ var _ = Describe("ObjectRef VirtualDiskSnapshot", func() { It("is in provisioning", func() { pvc.Status.Phase = corev1.ClaimPending sc.VolumeBindingMode = ptr.To(storagev1.VolumeBindingImmediate) - client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(pvc, sc).Build() + client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(pvc, sc, vdSnapshot, vs).Build() syncer := NewObjectRefVirtualDiskSnapshot(recorder, svc, client) @@ -273,6 +275,30 @@ var _ = Describe("ObjectRef VirtualDiskSnapshot", func() { Expect(vd.Status.Target.PersistentVolumeClaim).NotTo(BeEmpty()) }) }) + + Context("Virtual disk has annotations and labels", func() { + It("checks that the restored virtual disk has its original metadata", func() { + key := "key" + value := "value" + originalMetadata := fmt.Sprintf("{\"%s\":\"%s\"}", key, value) + + vs.Annotations = map[string]string{ + annotations.AnnVirtualDiskOriginalAnnotations: originalMetadata, + annotations.AnnVirtualDiskOriginalLabels: originalMetadata, + } + + client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(vdSnapshot, vs).Build() + + syncer := NewObjectRefVirtualDiskSnapshot(recorder, svc, client) + + res, err := syncer.Sync(ctx, vd) + Expect(err).ToNot(HaveOccurred()) + Expect(res.IsZero()).To(BeTrue()) + + Expect(vd.Annotations).To(HaveKeyWithValue(key, value)) + Expect(vd.Labels).To(HaveKeyWithValue(key, value)) + }) + }) }) func ExpectStats(vd *v1alpha2.VirtualDisk) { diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/source/step/add_original_metadata_step.go b/images/virtualization-artifact/pkg/controller/vd/internal/source/step/add_original_metadata_step.go new file mode 100644 index 0000000000..e3d4806079 --- /dev/null +++ b/images/virtualization-artifact/pkg/controller/vd/internal/source/step/add_original_metadata_step.go @@ -0,0 +1,193 @@ +/* +Copyright 2025 Flant JSC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package step + +import ( + "context" + "encoding/json" + "fmt" + + vsv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + + "github.com/deckhouse/virtualization-controller/pkg/common/annotations" + "github.com/deckhouse/virtualization-controller/pkg/common/object" + "github.com/deckhouse/virtualization-controller/pkg/controller/conditions" + "github.com/deckhouse/virtualization-controller/pkg/controller/service" + "github.com/deckhouse/virtualization-controller/pkg/eventrecord" + "github.com/deckhouse/virtualization/api/core/v1alpha2" + "github.com/deckhouse/virtualization/api/core/v1alpha2/vdcondition" +) + +const lastAppliedConfigAnnotation = "kubectl.kubernetes.io/last-applied-configuration" + +type AddOriginalMetadataStep struct { + recorder eventrecord.EventRecorderLogger + client client.Client + cb *conditions.ConditionBuilder +} + +func NewAddOriginalMetadataStep( + recorder eventrecord.EventRecorderLogger, + client client.Client, + cb *conditions.ConditionBuilder, +) *AddOriginalMetadataStep { + return &AddOriginalMetadataStep{ + recorder: recorder, + client: client, + cb: cb, + } +} + +func (s AddOriginalMetadataStep) Take(ctx context.Context, vd *v1alpha2.VirtualDisk) (*reconcile.Result, error) { + vdSnapshot, err := object.FetchObject(ctx, types.NamespacedName{Name: vd.Spec.DataSource.ObjectRef.Name, Namespace: vd.Namespace}, s.client, &v1alpha2.VirtualDiskSnapshot{}) + if err != nil { + err = fmt.Errorf("failed to fetch the virtual disk snapshot: %w", err) + vd.Status.Phase = v1alpha2.DiskFailed + s.cb. + Status(metav1.ConditionFalse). + Reason(vdcondition.ProvisioningFailed). + Message(service.CapitalizeFirstLetter(err.Error() + ".")) + return nil, err + } + + if vdSnapshot == nil { + vd.Status.Phase = v1alpha2.DiskPending + s.cb. + Status(metav1.ConditionFalse). + Reason(vdcondition.ProvisioningNotStarted). + Message(fmt.Sprintf("VirtualDiskSnapshot %q not found.", vd.Spec.DataSource.ObjectRef.Name)) + return &reconcile.Result{}, nil + } + + vs, err := object.FetchObject(ctx, types.NamespacedName{Name: vdSnapshot.Status.VolumeSnapshotName, Namespace: vdSnapshot.Namespace}, s.client, &vsv1.VolumeSnapshot{}) + if err != nil { + err = fmt.Errorf("failed to fetch the volume snapshot: %w", err) + vd.Status.Phase = v1alpha2.DiskFailed + s.cb. + Status(metav1.ConditionFalse). + Reason(vdcondition.ProvisioningFailed). + Message(service.CapitalizeFirstLetter(err.Error() + ".")) + return nil, err + } + + if vdSnapshot.Status.Phase != v1alpha2.VirtualDiskSnapshotPhaseReady || vs == nil || vs.Status == nil || vs.Status.ReadyToUse == nil || !*vs.Status.ReadyToUse { + vd.Status.Phase = v1alpha2.DiskPending + s.cb. + Status(metav1.ConditionFalse). + Reason(vdcondition.ProvisioningNotStarted). + Message(fmt.Sprintf("VirtualDiskSnapshot %q is not ready to use.", vdSnapshot.Name)) + return &reconcile.Result{}, nil + } + + areAnnotationsAdded, err := setOriginalAnnotations(vd, vs) + if err != nil { + wrappedErr := fmt.Errorf("failed to set original annotations: %w", err) + vd.Status.Phase = v1alpha2.DiskFailed + s.cb. + Status(metav1.ConditionFalse). + Reason(vdcondition.ProvisioningFailed). + Message(service.CapitalizeFirstLetter(wrappedErr.Error() + ".")) + return nil, wrappedErr + } + + areLabelsAdded, err := setOriginalLabels(vd, vs) + if err != nil { + wrappedErr := fmt.Errorf("failed to set original labels: %w", err) + vd.Status.Phase = v1alpha2.DiskFailed + s.cb. + Status(metav1.ConditionFalse). + Reason(vdcondition.ProvisioningFailed). + Message(service.CapitalizeFirstLetter(wrappedErr.Error() + ".")) + return nil, wrappedErr + } + + // Ensure that new metadata is applied correctly because a conflict error can occur + // when updating the virtual disk resource. Therefore, this step should finish + // with reconciliation if the metadata has changed. + if areAnnotationsAdded || areLabelsAdded { + msg := "The original metadata sync has started" + s.recorder.Event( + vd, + corev1.EventTypeNormal, + v1alpha2.ReasonMetadataSyncStarted, + msg, + ) + s.cb. + Status(metav1.ConditionFalse). + Reason(vdcondition.Provisioning). + Message(msg) + return &reconcile.Result{}, nil + } + + return nil, nil +} + +func setOriginalAnnotations(vd *v1alpha2.VirtualDisk, vs *vsv1.VolumeSnapshot) (bool, error) { + var originalAnnotationsMap map[string]string + if vs.Annotations[annotations.AnnVirtualDiskOriginalAnnotations] != "" { + err := json.Unmarshal([]byte(vs.Annotations[annotations.AnnVirtualDiskOriginalAnnotations]), &originalAnnotationsMap) + if err != nil { + return false, fmt.Errorf("failed to unmarshal the original annotations: %w", err) + } + } + + if vd.Annotations == nil { + vd.Annotations = make(map[string]string) + } + + var areAnnotationsAdded bool + for key, originalvalue := range originalAnnotationsMap { + if key == lastAppliedConfigAnnotation { + continue + } + if currentValue, exists := vd.Annotations[key]; !exists || currentValue != originalvalue { + vd.Annotations[key] = originalvalue + areAnnotationsAdded = true + } + } + + return areAnnotationsAdded, nil +} + +func setOriginalLabels(vd *v1alpha2.VirtualDisk, vs *vsv1.VolumeSnapshot) (bool, error) { + var originalLabelsMap map[string]string + if vs.Annotations[annotations.AnnVirtualDiskOriginalLabels] != "" { + err := json.Unmarshal([]byte(vs.Annotations[annotations.AnnVirtualDiskOriginalLabels]), &originalLabelsMap) + if err != nil { + return false, fmt.Errorf("failed to unmarshal the original labels: %w", err) + } + } + + if vd.Labels == nil { + vd.Labels = make(map[string]string) + } + + var areLabelsAdded bool + for key, originalvalue := range originalLabelsMap { + if currentValue, exists := vd.Labels[key]; !exists || currentValue != originalvalue { + vd.Labels[key] = originalvalue + areLabelsAdded = true + } + } + + return areLabelsAdded, nil +} diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/source/step/create_pvc_from_vdsnapshot_step.go b/images/virtualization-artifact/pkg/controller/vd/internal/source/step/create_pvc_from_vdsnapshot_step.go index be0ea0357b..8dc2f5af13 100644 --- a/images/virtualization-artifact/pkg/controller/vd/internal/source/step/create_pvc_from_vdsnapshot_step.go +++ b/images/virtualization-artifact/pkg/controller/vd/internal/source/step/create_pvc_from_vdsnapshot_step.go @@ -34,7 +34,6 @@ import ( "github.com/deckhouse/virtualization-controller/pkg/common/annotations" "github.com/deckhouse/virtualization-controller/pkg/common/object" "github.com/deckhouse/virtualization-controller/pkg/common/pointer" - commonvdsnapshot "github.com/deckhouse/virtualization-controller/pkg/common/vdsnapshot" "github.com/deckhouse/virtualization-controller/pkg/controller/conditions" "github.com/deckhouse/virtualization-controller/pkg/controller/service" vdsupplements "github.com/deckhouse/virtualization-controller/pkg/controller/vd/internal/supplements" @@ -137,11 +136,6 @@ func (s CreatePVCFromVDSnapshotStep) Take(ctx context.Context, vd *v1alpha2.Virt vd.Status.SourceUID = pointer.GetPointer(vdSnapshot.UID) vdsupplements.SetPVCName(vd, pvc.Name) - err = commonvdsnapshot.AddOriginalMetadata(vd, vs) - if err != nil { - return nil, fmt.Errorf("failed to add original metadata: %w", err) - } - return nil, nil } diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/watcher/vd_watcher.go b/images/virtualization-artifact/pkg/controller/vd/internal/watcher/vd_watcher.go new file mode 100644 index 0000000000..831cddf1da --- /dev/null +++ b/images/virtualization-artifact/pkg/controller/vd/internal/watcher/vd_watcher.go @@ -0,0 +1,45 @@ +/* +Copyright 2025 Flant JSC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package watcher + +import ( + "fmt" + + "sigs.k8s.io/controller-runtime/pkg/controller" + "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/source" + + "github.com/deckhouse/virtualization/api/core/v1alpha2" +) + +type VirtualDiskWatcher struct{} + +func NewVirtualDiskWatcher() *VirtualDiskWatcher { + return &VirtualDiskWatcher{} +} + +func (w VirtualDiskWatcher) Watch(mgr manager.Manager, ctr controller.Controller) error { + if err := ctr.Watch( + source.Kind(mgr.GetCache(), &v1alpha2.VirtualDisk{}, + &handler.TypedEnqueueRequestForObject[*v1alpha2.VirtualDisk]{}, + ), + ); err != nil { + return fmt.Errorf("error setting watch on VirtualDisk: %w", err) + } + return nil +} diff --git a/images/virtualization-artifact/pkg/controller/vd/vd_reconciler.go b/images/virtualization-artifact/pkg/controller/vd/vd_reconciler.go index 654caf4b0f..c71f4565c5 100644 --- a/images/virtualization-artifact/pkg/controller/vd/vd_reconciler.go +++ b/images/virtualization-artifact/pkg/controller/vd/vd_reconciler.go @@ -23,10 +23,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" - "sigs.k8s.io/controller-runtime/pkg/source" "github.com/deckhouse/virtualization-controller/pkg/controller/reconciler" vdsupplements "github.com/deckhouse/virtualization-controller/pkg/controller/vd/internal/supplements" @@ -87,14 +85,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco } func (r *Reconciler) SetupController(_ context.Context, mgr manager.Manager, ctr controller.Controller) error { - if err := ctr.Watch( - source.Kind(mgr.GetCache(), &v1alpha2.VirtualDisk{}, - &handler.TypedEnqueueRequestForObject[*v1alpha2.VirtualDisk]{}, - ), - ); err != nil { - return fmt.Errorf("error setting watch on VirtualDisk: %w", err) - } - vdFromVIEnqueuer := watchers.NewVirtualDiskRequestEnqueuer(mgr.GetClient(), &v1alpha2.VirtualImage{}, v1alpha2.VirtualDiskObjectRefKindVirtualImage) viWatcher := watchers.NewObjectRefWatcher(watchers.NewVirtualImageFilter(), vdFromVIEnqueuer) if err := viWatcher.Run(mgr, ctr); err != nil { @@ -109,6 +99,7 @@ func (r *Reconciler) SetupController(_ context.Context, mgr manager.Manager, ctr mgrClient := mgr.GetClient() for _, w := range []Watcher{ + watcher.NewVirtualDiskWatcher(), watcher.NewPersistentVolumeClaimWatcher(mgrClient), watcher.NewVirtualDiskSnapshotWatcher(mgrClient), watcher.NewStorageClassWatcher(mgrClient), diff --git a/test/e2e/legacy/vm_restore_force.go b/test/e2e/legacy/vm_restore_force.go index b33e62e0c9..2499f8ed68 100644 --- a/test/e2e/legacy/vm_restore_force.go +++ b/test/e2e/legacy/vm_restore_force.go @@ -258,12 +258,12 @@ var _ = Describe("VirtualMachineRestoreForce", Ordered, func() { }) By("Checking the result of restoration", func() { - // const ( - // testLabelKey = "test-label" - // testLabelValue = "test-label-value" - // testAnnotationKey = "test-annotation" - // testAnnotationValue = "test-annotation-value" - // ) + const ( + testLabelKey = "test-label" + testLabelValue = "test-label-value" + testAnnotationKey = "test-annotation" + testAnnotationValue = "test-annotation-value" + ) vmrestores := &v1alpha2.VirtualMachineRestoreList{} err := GetObjects(v1alpha2.VirtualMachineRestoreKind, vmrestores, kc.GetOptions{Namespace: namespace, Labels: testCaseLabel}) @@ -289,10 +289,8 @@ var _ = Describe("VirtualMachineRestoreForce", Ordered, func() { Expect(err).NotTo(HaveOccurred()) Expect(vd.Annotations).To(HaveKeyWithValue(annotations.AnnVMRestore, string(restore.UID))) - // Skip the annotation and label checks until the issue with virtual disk restoration is fixed. - // Cause: Sometimes, a virtual disk does not have annotations and labels from a virtual disk snapshot, causing the test to fail. - // Expect(vd.Annotations).To(HaveKeyWithValue(testAnnotationKey, testAnnotationValue)) - // Expect(vd.Labels).To(HaveKeyWithValue(testLabelKey, testLabelValue)) + Expect(vd.Annotations).To(HaveKeyWithValue(testAnnotationKey, testAnnotationValue)) + Expect(vd.Labels).To(HaveKeyWithValue(testLabelKey, testLabelValue)) } if bd.VirtualMachineBlockDeviceAttachmentName != "" { diff --git a/test/e2e/legacy/vm_restore_safe.go b/test/e2e/legacy/vm_restore_safe.go index 4bad7a052a..d029dc01ce 100644 --- a/test/e2e/legacy/vm_restore_safe.go +++ b/test/e2e/legacy/vm_restore_safe.go @@ -264,12 +264,12 @@ var _ = Describe("VirtualMachineRestoreSafe", Ordered, func() { }) By("Checking the result of restoration", func() { - // const ( - // testLabelKey = "test-label" - // testLabelValue = "test-label-value" - // testAnnotationKey = "test-annotation" - // testAnnotationValue = "test-annotation-value" - // ) + const ( + testLabelKey = "test-label" + testLabelValue = "test-label-value" + testAnnotationKey = "test-annotation" + testAnnotationValue = "test-annotation-value" + ) vmrestores := &v1alpha2.VirtualMachineRestoreList{} err := GetObjects(v1alpha2.VirtualMachineRestoreKind, vmrestores, kc.GetOptions{Namespace: namespace, Labels: testCaseLabel}) @@ -294,10 +294,8 @@ var _ = Describe("VirtualMachineRestoreSafe", Ordered, func() { Expect(err).NotTo(HaveOccurred()) Expect(vd.Annotations).To(HaveKeyWithValue(annotations.AnnVMRestore, string(restore.UID))) - // Skip the annotation and label checks until the issue with virtual disk restoration is fixed. - // Cause: Sometimes, a virtual disk does not have annotations and labels from a virtual disk snapshot, causing the test to fail. - // Expect(vd.Annotations).To(HaveKeyWithValue(testAnnotationKey, testAnnotationValue)) - // Expect(vd.Labels).To(HaveKeyWithValue(testLabelKey, testLabelValue)) + Expect(vd.Annotations).To(HaveKeyWithValue(testAnnotationKey, testAnnotationValue)) + Expect(vd.Labels).To(HaveKeyWithValue(testLabelKey, testLabelValue)) } if bd.VirtualMachineBlockDeviceAttachmentName != "" {