@@ -166,6 +166,16 @@ type reactorError struct {
166
166
error error
167
167
}
168
168
169
+ func withSnapshotFinalizer (snapshot * crdv1.VolumeSnapshot ) * crdv1.VolumeSnapshot {
170
+ snapshot .ObjectMeta .Finalizers = append (snapshot .ObjectMeta .Finalizers , VolumeSnapshotFinalizer )
171
+ return snapshot
172
+ }
173
+
174
+ func withContentFinalizer (content * crdv1.VolumeSnapshotContent ) * crdv1.VolumeSnapshotContent {
175
+ content .ObjectMeta .Finalizers = append (content .ObjectMeta .Finalizers , VolumeSnapshotContentFinalizer )
176
+ return content
177
+ }
178
+
169
179
// React is a callback called by fake kubeClient from the controller.
170
180
// In other words, every snapshot/content change performed by the controller ends
171
181
// here.
@@ -744,7 +754,7 @@ func newTestController(kubeClient kubernetes.Interface, clientset clientset.Inte
744
754
}
745
755
746
756
// newContent returns a new content with given attributes
747
- func newContent (name , className , snapshotHandle , volumeUID , volumeName , boundToSnapshotUID , boundToSnapshotName string , size * int64 , creationTime * int64 ) * crdv1.VolumeSnapshotContent {
757
+ func newContent (name , className , snapshotHandle , volumeUID , volumeName , boundToSnapshotUID , boundToSnapshotName string , deletionPolicy * crdv1. DeletionPolicy , size * int64 , creationTime * int64 , withFinalizer bool ) * crdv1.VolumeSnapshotContent {
748
758
content := crdv1.VolumeSnapshotContent {
749
759
ObjectMeta : metav1.ObjectMeta {
750
760
Name : name ,
@@ -766,6 +776,7 @@ func newContent(name, className, snapshotHandle, volumeUID, volumeName, boundToS
766
776
UID : types .UID (volumeUID ),
767
777
Name : volumeName ,
768
778
},
779
+ DeletionPolicy : deletionPolicy ,
769
780
},
770
781
}
771
782
if boundToSnapshotName != "" {
@@ -778,17 +789,20 @@ func newContent(name, className, snapshotHandle, volumeUID, volumeName, boundToS
778
789
}
779
790
}
780
791
792
+ if withFinalizer {
793
+ return withContentFinalizer (& content )
794
+ }
781
795
return & content
782
796
}
783
797
784
- func newContentArray (name , className , snapshotHandle , volumeUID , volumeName , boundToSnapshotUID , boundToSnapshotName string , size * int64 , creationTime * int64 ) []* crdv1.VolumeSnapshotContent {
798
+ func newContentArray (name , className , snapshotHandle , volumeUID , volumeName , boundToSnapshotUID , boundToSnapshotName string , deletionPolicy * crdv1. DeletionPolicy , size * int64 , creationTime * int64 , withFinalizer bool ) []* crdv1.VolumeSnapshotContent {
785
799
return []* crdv1.VolumeSnapshotContent {
786
- newContent (name , className , snapshotHandle , volumeUID , volumeName , boundToSnapshotUID , boundToSnapshotName , size , creationTime ),
800
+ newContent (name , className , snapshotHandle , volumeUID , volumeName , boundToSnapshotUID , boundToSnapshotName , deletionPolicy , size , creationTime , withFinalizer ),
787
801
}
788
802
}
789
803
790
- func newContentWithUnmatchDriverArray (name , className , snapshotHandle , volumeUID , volumeName , boundToSnapshotUID , boundToSnapshotName string , size * int64 , creationTime * int64 ) []* crdv1.VolumeSnapshotContent {
791
- content := newContent (name , className , snapshotHandle , volumeUID , volumeName , boundToSnapshotUID , boundToSnapshotName , size , creationTime )
804
+ func newContentWithUnmatchDriverArray (name , className , snapshotHandle , volumeUID , volumeName , boundToSnapshotUID , boundToSnapshotName string , deletionPolicy * crdv1. DeletionPolicy , size * int64 , creationTime * int64 ) []* crdv1.VolumeSnapshotContent {
805
+ content := newContent (name , className , snapshotHandle , volumeUID , volumeName , boundToSnapshotUID , boundToSnapshotName , deletionPolicy , size , creationTime , false )
792
806
content .Spec .VolumeSnapshotSource .CSI .Driver = "fake"
793
807
return []* crdv1.VolumeSnapshotContent {
794
808
content ,
@@ -814,13 +828,13 @@ func newSnapshot(name, className, boundToContent, snapshotUID, claimName string,
814
828
},
815
829
Status : crdv1.VolumeSnapshotStatus {
816
830
CreationTime : creationTime ,
817
- Ready : ready ,
831
+ ReadyToUse : ready ,
818
832
Error : err ,
819
833
RestoreSize : size ,
820
834
},
821
835
}
822
836
823
- return & snapshot
837
+ return withSnapshotFinalizer ( & snapshot )
824
838
}
825
839
826
840
func newSnapshotArray (name , className , boundToContent , snapshotUID , claimName string , ready bool , err * storagev1beta1.VolumeError , creationTime * metav1.Time , size * resource.Quantity ) []* crdv1.VolumeSnapshot {
0 commit comments