@@ -40,11 +40,12 @@ import (
40
40
"k8s.io/apimachinery/pkg/types"
41
41
"k8s.io/client-go/tools/events"
42
42
"k8s.io/utils/ptr"
43
+ ctrl "sigs.k8s.io/controller-runtime"
43
44
"sigs.k8s.io/controller-runtime/pkg/client"
44
45
"sigs.k8s.io/controller-runtime/pkg/log/zap"
45
46
46
47
volsyncv1alpha1 "github.com/backube/volsync/api/v1alpha1"
47
- "github.com/backube/volsync/controllers/mover"
48
+ vsmover "github.com/backube/volsync/controllers/mover"
48
49
"github.com/backube/volsync/controllers/utils"
49
50
)
50
51
@@ -239,7 +240,7 @@ var _ = Describe("Restic properly registers", func() {
239
240
240
241
It ("is added to the mover catalog" , func () {
241
242
found := false
242
- for _ , v := range mover .Catalog {
243
+ for _ , v := range vsmover .Catalog {
243
244
if _ , ok := v .(* Builder ); ok {
244
245
found = true
245
246
}
@@ -624,6 +625,78 @@ var _ = Describe("Restic as a source", func() {
624
625
Expect (* cache .Spec .StorageClassName ).To (Equal (cachesc ))
625
626
})
626
627
})
628
+
629
+ Context ("old cache name migration" , func () {
630
+ var oldCache * corev1.PersistentVolumeClaim
631
+ When ("The cache PVC with the old name exists" , func () {
632
+ BeforeEach (func () {
633
+ sc := "some-storage"
634
+ oldCache = & corev1.PersistentVolumeClaim {
635
+ ObjectMeta : metav1.ObjectMeta {
636
+ Name : vsmover .VolSyncPrefix + rs .GetName () + "-cache" ,
637
+ Namespace : rs .GetNamespace (),
638
+ },
639
+ Spec : corev1.PersistentVolumeClaimSpec {
640
+ AccessModes : []corev1.PersistentVolumeAccessMode {
641
+ corev1 .ReadWriteOnce ,
642
+ },
643
+ Resources : corev1.VolumeResourceRequirements {
644
+ Requests : corev1.ResourceList {
645
+ "storage" : resource .MustParse ("1Gi" ),
646
+ },
647
+ },
648
+ StorageClassName : & sc ,
649
+ },
650
+ }
651
+ })
652
+
653
+ JustBeforeEach (func () {
654
+ Expect (k8sClient .Create (ctx , oldCache )).To (Succeed ())
655
+ })
656
+
657
+ When ("The old cache pvc is not owned by this VolSync RS" , func () {
658
+ It ("Should not delete the old cache PVC and still create the new one" , func () {
659
+ cache , err := mover .ensureCache (ctx , dataPVC , false )
660
+ Expect (err ).ToNot (HaveOccurred ())
661
+ Expect (cache .GetName ()).To (ContainSubstring ("-cache" ))
662
+ Expect (cache .GetName ()).To (ContainSubstring ("-src-" ))
663
+
664
+ // Check that old cache pvc is still there
665
+ Expect (k8sClient .Get (ctx , client .ObjectKeyFromObject (oldCache ), oldCache )).To (Succeed ())
666
+ Expect (oldCache .GetDeletionTimestamp ().IsZero ()).To (BeTrue ()) // Not marked for deletion
667
+ })
668
+ })
669
+
670
+ When ("The old cache PVC was owned by this VolSync RS" , func () {
671
+ JustBeforeEach (func () {
672
+ // Need to do this after the RS has been created
673
+ Expect (k8sClient .Get (ctx , client .ObjectKeyFromObject (oldCache ), oldCache )).To (Succeed ())
674
+ Expect (ctrl .SetControllerReference (rs , oldCache , k8sClient .Scheme ())).To (Succeed ())
675
+ Expect (k8sClient .Update (ctx , oldCache )).To (Succeed ())
676
+ })
677
+
678
+ It ("Should delete the old cache pvc and still create the new one" , func () {
679
+ cache , err := mover .ensureCache (ctx , dataPVC , false )
680
+ Expect (err ).ToNot (HaveOccurred ())
681
+ Expect (cache .GetName ()).To (ContainSubstring ("-cache" ))
682
+ Expect (cache .GetName ()).To (ContainSubstring ("-src-" ))
683
+
684
+ // Check that old cache pvc was deleted
685
+ err = k8sClient .Get (ctx , client .ObjectKeyFromObject (oldCache ), oldCache )
686
+ if err == nil {
687
+ // Should be marked for deletion
688
+ Expect (oldCache .GetDeletionTimestamp ().IsZero ()).To (BeFalse ())
689
+ } else {
690
+ Expect (kerrors .IsNotFound (err )).To (BeTrue ())
691
+ }
692
+
693
+ // Should be able to reconcile again
694
+ _ , err = mover .ensureCache (ctx , dataPVC , false )
695
+ Expect (err ).ToNot (HaveOccurred ())
696
+ })
697
+ })
698
+ })
699
+ })
627
700
})
628
701
629
702
Context ("Source volume is handled properly" , func () {
@@ -1829,6 +1902,32 @@ var _ = Describe("Restic as a destination", func() {
1829
1902
mover , _ = m .(* Mover )
1830
1903
Expect (mover ).NotTo (BeNil ())
1831
1904
})
1905
+
1906
+ Context ("Restic cache is created correctly" , func () {
1907
+ var dataPVC * corev1.PersistentVolumeClaim
1908
+ BeforeEach (func () {
1909
+ am := corev1 .ReadWriteMany
1910
+ rd .Spec .Restic .AccessModes = []corev1.PersistentVolumeAccessMode {
1911
+ am ,
1912
+ }
1913
+ destVolCap := resource .MustParse ("6Gi" )
1914
+ rd .Spec .Restic .Capacity = & destVolCap
1915
+ })
1916
+
1917
+ JustBeforeEach (func () {
1918
+ var err error
1919
+ dataPVC , err = mover .ensureDestinationPVC (ctx )
1920
+ Expect (err ).NotTo (HaveOccurred ())
1921
+ })
1922
+
1923
+ It ("Should create old cache pvc" , func () {
1924
+ cache , err := mover .ensureCache (ctx , dataPVC , false )
1925
+ Expect (err ).ToNot (HaveOccurred ())
1926
+ Expect (cache .GetName ()).To (ContainSubstring ("-cache" ))
1927
+ Expect (cache .GetName ()).To (ContainSubstring ("-dst-" ))
1928
+ })
1929
+ })
1930
+
1832
1931
When ("no destination volume is supplied" , func () {
1833
1932
var destVolCap resource.Quantity
1834
1933
var am corev1.PersistentVolumeAccessMode
0 commit comments