@@ -289,14 +289,6 @@ func (ctrl *csiSnapshotCommonController) syncGroupSnapshot(groupSnapshot *crdv1a
289
289
290
290
klog .V (5 ).Infof ("syncGroupSnapshot [%s]: check if we should remove finalizer on group snapshot PVC source and remove it if we can" , utils .GroupSnapshotKey (groupSnapshot ))
291
291
292
- /*
293
- TODO:
294
- - Check and remove finalizer if needed.
295
- - Check and set invalid group snapshot label, if needed.
296
- - Process if deletion timestamp is set.
297
- - Check and add group snapshot finalizers.
298
- */
299
- // START
300
292
// Proceed with snapshot deletion and remove finalizers when needed
301
293
if groupSnapshot .ObjectMeta .DeletionTimestamp != nil {
302
294
return ctrl .processGroupSnapshotWithDeletionTimestamp (groupSnapshot )
@@ -311,15 +303,13 @@ func (ctrl *csiSnapshotCommonController) syncGroupSnapshot(groupSnapshot *crdv1a
311
303
return err
312
304
}
313
305
314
- klog .V (5 ).Infof ("syncGroupSnapshot[%s] : check if we should add finalizers on group snapshot" , utils .GroupSnapshotKey (groupSnapshot ))
306
+ klog .V (5 ).Infof ("syncGroupSnapshot: check if we should add finalizers on group snapshot [%s] " , utils .GroupSnapshotKey (groupSnapshot ))
315
307
if err := ctrl .checkandAddGroupSnapshotFinalizers (groupSnapshot ); err != nil {
316
- klog .Errorf ("error check and add GroupSnapshot finalizers for group snapshot [%s]: %v" , groupSnapshot . Name , err )
308
+ klog .Errorf ("error ccheckandAddGroupSnapshotFinalizers for group snapshot [%s]: %v" , utils . GroupSnapshotKey ( groupSnapshot ) , err )
317
309
ctrl .eventRecorder .Event (groupSnapshot , v1 .EventTypeWarning , "GroupSnapshotFinalizerError" , fmt .Sprintf ("Failed to check and update group snapshot: %s" , err .Error ()))
318
310
return err
319
311
}
320
312
321
- // END
322
-
323
313
// Need to build or update groupSnapshot.Status in following cases:
324
314
// 1) groupSnapshot.Status is nil
325
315
// 2) groupSnapshot.Status.ReadyToUse is false
@@ -750,7 +740,7 @@ func (ctrl *csiSnapshotCommonController) createGroupSnapshotContent(groupSnapsho
750
740
klog .Infof ("createSnapshotContent: Creating group snapshot content for group snapshot %s through the plugin ..." , utils .GroupSnapshotKey (groupSnapshot ))
751
741
752
742
/*
753
- TODO: Add finalizer to group snapshot
743
+ TODO: Add PVC finalizer
754
744
*/
755
745
756
746
groupSnapshotClass , volumes , contentName , err := ctrl .getCreateGroupSnapshotInput (groupSnapshot )
@@ -872,12 +862,8 @@ func (ctrl *csiSnapshotCommonController) syncGroupSnapshotContent(groupSnapshotC
872
862
return nil
873
863
}
874
864
875
- /*
876
- TODO: Add finalizer to prevent deletion
877
- */
878
-
879
865
if utils .NeedToAddGroupSnapshotContentFinalizer (groupSnapshotContent ) {
880
- // Content is not being deleted -> it should have the finalizer.
866
+ // Group Snapshot Content is not being deleted -> it should have the finalizer.
881
867
klog .V (5 ).Infof ("syncGroupSnapshotContent [%s]: Add Finalizer for VolumeGroupSnapshotContent" , groupSnapshotContent .Name )
882
868
return ctrl .addGroupSnapshotContentFinalizer (groupSnapshotContent )
883
869
}
@@ -999,7 +985,7 @@ func (ctrl *csiSnapshotCommonController) addGroupSnapshotContentFinalizer(groupS
999
985
1000
986
// checkandAddSnapshotFinalizers checks and adds snapshot finailzers when needed
1001
987
func (ctrl * csiSnapshotCommonController ) checkandAddGroupSnapshotFinalizers (groupSnapshot * crdv1alpha1.VolumeGroupSnapshot ) error {
1002
- // get the content for this Snapshot
988
+ // get the group snapshot content for this group snapshot
1003
989
var (
1004
990
groupSnapshotContent * crdv1alpha1.VolumeGroupSnapshotContent
1005
991
err error
@@ -1013,29 +999,21 @@ func (ctrl *csiSnapshotCommonController) checkandAddGroupSnapshotFinalizers(grou
1013
999
return err
1014
1000
}
1015
1001
1016
- /*
1017
- TODO: Do we need to add group snapshot as source finalizer?
1018
- */
1019
-
1020
- // note that content could be nil, in this case bound finalizer is not needed
1021
- addBoundFinalizer := false
1022
- if groupSnapshotContent != nil {
1023
- // A bound finalizer is needed ONLY when all following conditions are satisfied:
1024
- // 1. the VolumeSnapshot is bound to a content
1025
- // 2. the VolumeSnapshot does not have deletion timestamp set
1026
- // 3. the matching content has a deletion policy to be Delete
1027
- // Note that if a matching content is found, it must points back to the snapshot
1028
- addBoundFinalizer = utils .NeedToAddGroupSnapshotBoundFinalizer (groupSnapshot ) && (groupSnapshotContent .Spec .DeletionPolicy == crdv1 .VolumeSnapshotContentDelete )
1029
- }
1030
- if addBoundFinalizer {
1002
+ // A bound finalizer is needed ONLY when all following conditions are satisfied:
1003
+ // 1. the VolumeGroupSnapshot is bound to a VolumeGroupSnapshotContent
1004
+ // 2. the VolumeGroupSnapshot does not have deletion timestamp set
1005
+ // 3. the matching VolumeGroupSnapshotContent has a deletion policy to be Delete
1006
+ // Note that if a matching VolumeGroupSnapshotContent is found, it must point back to the VolumeGroupSnapshot
1007
+ if groupSnapshotContent != nil && utils .NeedToAddGroupSnapshotBoundFinalizer (groupSnapshot ) && (groupSnapshotContent .Spec .DeletionPolicy == crdv1 .VolumeSnapshotContentDelete ) {
1031
1008
// Snapshot is not being deleted -> it should have the finalizer.
1032
1009
klog .V (5 ).Infof ("checkandAddGroupSnapshotFinalizers: Add Finalizer for VolumeGroupSnapshot[%s]" , utils .GroupSnapshotKey (groupSnapshot ))
1033
- return ctrl .addGroupSnapshotFinalizer (groupSnapshot , addBoundFinalizer )
1010
+ return ctrl .addGroupSnapshotFinalizer (groupSnapshot , true )
1011
+
1034
1012
}
1035
1013
return nil
1036
1014
}
1037
1015
1038
- // addGroupSnapshotFinalizer adds a Finalizer for VolumeGroupSnapshot.
1016
+ // addGroupSnapshotFinalizer adds a Finalizer to a VolumeGroupSnapshot.
1039
1017
func (ctrl * csiSnapshotCommonController ) addGroupSnapshotFinalizer (groupSnapshot * crdv1alpha1.VolumeGroupSnapshot , addBoundFinalizer bool ) error {
1040
1018
var updatedGroupSnapshot * crdv1alpha1.VolumeGroupSnapshot
1041
1019
var err error
@@ -1080,7 +1058,7 @@ func (ctrl *csiSnapshotCommonController) addGroupSnapshotFinalizer(groupSnapshot
1080
1058
1081
1059
// processGroupSnapshotWithDeletionTimestamp processes finalizers and deletes the
1082
1060
// group snapshot content when appropriate. It has the following steps:
1083
- // 1. Get the group snapshot content which the to-be-deleted VolumeGroupSnapshot
1061
+ // 1. Get the VolumeGroupSnapshotContent which the to-be-deleted VolumeGroupSnapshot
1084
1062
// points to and verifies bi-directional binding.
1085
1063
// 2. Call checkandRemoveGroupSnapshotFinalizersAndCheckandDeleteGroupSnapshotContent()
1086
1064
// with information obtained from step 1. This function name is very long but the
@@ -1101,7 +1079,7 @@ func (ctrl *csiSnapshotCommonController) processGroupSnapshotWithDeletionTimesta
1101
1079
if groupSnapshotContentName == "" && & groupSnapshot .Spec .Source .VolumeGroupSnapshotContentName == nil {
1102
1080
groupSnapshotContentName = utils .GetDynamicSnapshotContentNameForGroupSnapshot (groupSnapshot )
1103
1081
}
1104
- // find a group snapshot content from cache store, note that it's complete legit
1082
+ // find a group snapshot content from cache store, note that it's completely legit
1105
1083
// that no group snapshot content has been found from group snapshot content
1106
1084
// cache store
1107
1085
groupSnapshotContent , err := ctrl .getGroupSnapshotContentFromStore (groupSnapshotContentName )
@@ -1139,18 +1117,24 @@ func (ctrl *csiSnapshotCommonController) checkandRemoveGroupSnapshotFinalizersAn
1139
1117
return nil
1140
1118
}
1141
1119
1142
- /* NEEDED?
1143
- // check if the group snapshot is being used for restore a PVC, if yes, do nothing
1144
- // and wait until PVC restoration finishes
1145
- if content != nil && ctrl.isVolumeBeingCreatedFromSnapshot(snapshot) {
1146
- klog.V(4).Infof("checkandRemoveSnapshotFinalizersAndCheckandDeleteContent[%s]: snapshot is being used to restore a PVC", utils.SnapshotKey(snapshot))
1147
- ctrl.eventRecorder.Event(snapshot, v1.EventTypeWarning, "SnapshotDeletePending", "Snapshot is being used to restore a PVC")
1148
- // TODO(@xiangqian): should requeue this?
1149
- return nil
1150
- }
1120
+ // TODO: In this needed?
1121
+ // check if an individual snapshot belonging to the group snapshot is being
1122
+ // used for restore a PVC
1123
+ // If yes, do nothing and wait until PVC restoration finishes
1124
+ for _ , snapshotRef := range groupSnapshot .Status .VolumeSnapshotRefList {
1125
+ snapshot , err := ctrl .snapshotLister .VolumeSnapshots (snapshotRef .Namespace ).Get (snapshotRef .Name )
1126
+ if err != nil {
1127
+ return err
1128
+ }
1129
+ if ctrl .isVolumeBeingCreatedFromSnapshot (snapshot ) {
1130
+ klog .V (4 ).Infof ("checkandRemoveGroupSnapshotFinalizersAndCheckandDeleteGroupSnapshotContent[%s]: snapshot [%s] belonging to volume group snapshot is being used to restore a PVC" , utils .GroupSnapshotKey (groupSnapshot ), utils .SnapshotKey (snapshot ))
1131
+ ctrl .eventRecorder .Event (snapshot , v1 .EventTypeWarning , "SnapshotDeletePending" , "Snapshot is being used to restore a PVC" )
1132
+ // TODO(@xiangqian): should requeue this?
1133
+ return nil
1134
+ }
1151
1135
1136
+ }
1152
1137
1153
- */
1154
1138
// regardless of the deletion policy, set the VolumeSnapshotBeingDeleted on
1155
1139
// content object, this is to allow snapshotter sidecar controller to conduct
1156
1140
// a delete operation whenever the content has deletion timestamp set.
@@ -1167,7 +1151,7 @@ func (ctrl *csiSnapshotCommonController) checkandRemoveGroupSnapshotFinalizersAn
1167
1151
// VolumeGroupSnapshot should be deleted. Check and remove finalizers
1168
1152
// If group snapshot content exists and has a deletion policy of Delete, set
1169
1153
// DeletionTimeStamp on the content;
1170
- // group snapshot content won't be deleted immediately due to the VolumeGroupSnapshotContentFinalizer
1154
+ // VolumeGroupSnapshotContent won't be deleted immediately due to the VolumeGroupSnapshotContentFinalizer
1171
1155
if groupSnapshotContent != nil && deleteGroupSnapshotContent {
1172
1156
klog .V (5 ).Infof ("checkandRemoveGroupSnapshotFinalizersAndCheckandDeleteGroupSnapshotContent: set DeletionTimeStamp on group snapshot content [%s]." , groupSnapshotContent .Name )
1173
1157
err := ctrl .clientset .GroupsnapshotV1alpha1 ().VolumeGroupSnapshotContents ().Delete (context .TODO (), groupSnapshotContent .Name , metav1.DeleteOptions {})
@@ -1228,26 +1212,9 @@ func (ctrl *csiSnapshotCommonController) removeGroupSnapshotFinalizer(groupSnaps
1228
1212
if ! removeBoundFinalizer {
1229
1213
return nil
1230
1214
}
1231
- /* NEEDED?
1232
- // NOTE(xyang): We have to make sure PVC finalizer is deleted before
1233
- // the VolumeSnapshot API object is deleted. Once the VolumeSnapshot
1234
- // API object is deleted, there won't be any VolumeSnapshot update
1235
- // event that can trigger the PVC finalizer removal any more.
1236
- // We also can't remove PVC finalizer too early. PVC finalizer should
1237
- // not be removed if a VolumeSnapshot API object is still using it.
1238
- // If we are here, it means we are going to remove finalizers from the
1239
- // VolumeSnapshot API object so that the VolumeSnapshot API object can
1240
- // be deleted. This means we no longer need to keep the PVC finalizer
1241
- // for this particular snapshot.
1242
- if err := ctrl.checkandRemovePVCFinalizer(groupSnapshot, true); err != nil {
1243
- klog.Errorf("removeSnapshotFinalizer: error check and remove PVC finalizer for snapshot [%s]: %v", groupSnapshot.Name, err)
1244
- // Log an event and keep the original error from checkandRemovePVCFinalizer
1245
- ctrl.eventRecorder.Event(groupSnapshot, v1.EventTypeWarning, "ErrorPVCFinalizer", "Error check and remove PVC Finalizer for VolumeSnapshot")
1246
- return newControllerUpdateError(groupSnapshot.Name, err.Error())
1247
- }
1248
1215
1216
+ // TODO: Remove PVC Finalizer
1249
1217
1250
- */
1251
1218
groupSnapshotClone := groupSnapshot .DeepCopy ()
1252
1219
groupSnapshotClone .ObjectMeta .Finalizers = utils .RemoveString (groupSnapshotClone .ObjectMeta .Finalizers , utils .VolumeGroupSnapshotBoundFinalizer )
1253
1220
newGroupSnapshot , err := ctrl .clientset .GroupsnapshotV1alpha1 ().VolumeGroupSnapshots (groupSnapshotClone .Namespace ).Update (context .TODO (), groupSnapshotClone , metav1.UpdateOptions {})
0 commit comments