@@ -18,6 +18,7 @@ package source
1818
1919import (
2020 "context"
21+ "fmt"
2122 "log/slog"
2223 "testing"
2324
@@ -34,6 +35,7 @@ import (
3435 "sigs.k8s.io/controller-runtime/pkg/client/fake"
3536 "sigs.k8s.io/controller-runtime/pkg/client/interceptor"
3637
38+ "github.com/deckhouse/virtualization-controller/pkg/common/annotations"
3739 "github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
3840 "github.com/deckhouse/virtualization-controller/pkg/controller/supplements"
3941 "github.com/deckhouse/virtualization-controller/pkg/eventrecord"
@@ -185,7 +187,7 @@ var _ = Describe("ObjectRef VirtualDiskSnapshot", func() {
185187 It ("waits for the first consumer" , func () {
186188 pvc .Status .Phase = corev1 .ClaimPending
187189 sc .VolumeBindingMode = ptr .To (storagev1 .VolumeBindingWaitForFirstConsumer )
188- client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (pvc , sc ).Build ()
190+ client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (pvc , sc , vdSnapshot , vs ).Build ()
189191
190192 syncer := NewObjectRefVirtualDiskSnapshot (recorder , svc , client )
191193
@@ -200,7 +202,7 @@ var _ = Describe("ObjectRef VirtualDiskSnapshot", func() {
200202 It ("is in provisioning" , func () {
201203 pvc .Status .Phase = corev1 .ClaimPending
202204 sc .VolumeBindingMode = ptr .To (storagev1 .VolumeBindingImmediate )
203- client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (pvc , sc ).Build ()
205+ client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (pvc , sc , vdSnapshot , vs ).Build ()
204206
205207 syncer := NewObjectRefVirtualDiskSnapshot (recorder , svc , client )
206208
@@ -273,6 +275,30 @@ var _ = Describe("ObjectRef VirtualDiskSnapshot", func() {
273275 Expect (vd .Status .Target .PersistentVolumeClaim ).NotTo (BeEmpty ())
274276 })
275277 })
278+
279+ Context ("Virtual disk has annotations and labels" , func () {
280+ It ("checks that the restored virtual disk has its original metadata" , func () {
281+ key := "key"
282+ value := "value"
283+ originalMetadata := fmt .Sprintf ("{\" %s\" :\" %s\" }" , key , value )
284+
285+ vs .Annotations = map [string ]string {
286+ annotations .AnnVirtualDiskOriginalAnnotations : originalMetadata ,
287+ annotations .AnnVirtualDiskOriginalLabels : originalMetadata ,
288+ }
289+
290+ client := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (vdSnapshot , vs ).Build ()
291+
292+ syncer := NewObjectRefVirtualDiskSnapshot (recorder , svc , client )
293+
294+ res , err := syncer .Sync (ctx , vd )
295+ Expect (err ).ToNot (HaveOccurred ())
296+ Expect (res .IsZero ()).To (BeTrue ())
297+
298+ Expect (vd .Annotations ).To (HaveKeyWithValue (key , value ))
299+ Expect (vd .Labels ).To (HaveKeyWithValue (key , value ))
300+ })
301+ })
276302})
277303
278304func ExpectStats (vd * v1alpha2.VirtualDisk ) {
0 commit comments