Skip to content

Commit 6b179a5

Browse files
committed
Address review comments
1 parent 23bba14 commit 6b179a5

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

pkg/common-controller/snapshot_controller.go

+20-11
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ const controllerUpdateFailMsg = "snapshot controller failed to update"
8181

8282
// syncContent deals with one key off the queue. It returns false when it's time to quit.
8383
func (ctrl *csiSnapshotCommonController) syncContent(content *crdv1.VolumeSnapshotContent) error {
84-
klog.V(5).Infof("synchronizing VolumeSnapshotContent[%s]", content.Name)
85-
8684
snapshotName := utils.SnapshotRefKey(&content.Spec.VolumeSnapshotRef)
8785

8886
klog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]: content is bound to snapshot %s", content.Name, snapshotName)
@@ -159,7 +157,7 @@ func (ctrl *csiSnapshotCommonController) syncSnapshot(snapshot *crdv1.VolumeSnap
159157
klog.V(5).Infof("synchronizing VolumeSnapshot[%s]: %s", utils.SnapshotKey(snapshot), utils.GetSnapshotStatusForLogging(snapshot))
160158

161159
if snapshot.ObjectMeta.DeletionTimestamp != nil {
162-
err := ctrl.processIfDeletionTimestampSet(snapshot)
160+
err := ctrl.processSnapshotWithDeletionTimestamp(snapshot)
163161
if err != nil {
164162
return err
165163
}
@@ -178,6 +176,10 @@ func (ctrl *csiSnapshotCommonController) syncSnapshot(snapshot *crdv1.VolumeSnap
178176
return nil
179177
}
180178

179+
// checkContentAndBoundStatus is a helper function that checks the following:
180+
// - It checks if content exists and returns the content object if it exists and nil otherwise.
181+
// - It checks the deletionPolicy and returns true if policy is Delete and false otherwise.
182+
// - It checks if snapshot and content are bound and returns true if bound and false otherwise.
181183
func (ctrl *csiSnapshotCommonController) checkContentAndBoundStatus(snapshot *crdv1.VolumeSnapshot) (*crdv1.VolumeSnapshotContent, bool, bool, error) {
182184
// If content is deleted already, remove SnapshotBound finalizer
183185
content, err := ctrl.getContentFromStore(snapshot)
@@ -201,25 +203,26 @@ func (ctrl *csiSnapshotCommonController) checkContentAndBoundStatus(snapshot *cr
201203
return content, deleteContent, snapshotBound, nil
202204
}
203205

204-
// processIfDeletionTimestampSet processes finalizers and deletes the content when appropriate
205-
// It checks if contents exists, it checks if snapshot has bi-directional binding, it checks if
206-
// finalizers should be removed, and it checks if content should be deleted and deletes it if needed.
207-
func (ctrl *csiSnapshotCommonController) processIfDeletionTimestampSet(snapshot *crdv1.VolumeSnapshot) error {
208-
klog.V(5).Infof("processIfDeletionTimestampSet VolumeSnapshot[%s]: %s", utils.SnapshotKey(snapshot), utils.GetSnapshotStatusForLogging(snapshot))
206+
// processSnapshotWithDeletionTimestamp processes finalizers and deletes the content when appropriate. It has the following steps:
207+
// 1. Call a helper function checkContentAndBoundStatus() to check content and bound status.
208+
// 2. Call checkandRemoveSnapshotFinalizersAndCheckandDeleteContent() with information obtained from step 1. This function name is very long but the name suggests what it does. It determines whether to remove finalizers on snapshot and whether to delete content.
209+
// 3. Call checkandRemovePVCFinalizer() to determine whether to remove the finalizer on PVC.
210+
func (ctrl *csiSnapshotCommonController) processSnapshotWithDeletionTimestamp(snapshot *crdv1.VolumeSnapshot) error {
211+
klog.V(5).Infof("processSnapshotWithDeletionTimestamp VolumeSnapshot[%s]: %s", utils.SnapshotKey(snapshot), utils.GetSnapshotStatusForLogging(snapshot))
209212

210213
// If content is really not found in the cache store, err is nil
211214
content, deleteContent, _, err := ctrl.checkContentAndBoundStatus(snapshot)
212215
if err != nil {
213216
return err
214217
}
215218

216-
klog.V(5).Infof("processIfDeletionTimestampSet[%s]: delete snapshot content and remove finalizer from snapshot if needed", utils.SnapshotKey(snapshot))
219+
klog.V(5).Infof("processSnapshotWithDeletionTimestamp[%s]: delete snapshot content and remove finalizer from snapshot if needed", utils.SnapshotKey(snapshot))
217220
err = ctrl.checkandRemoveSnapshotFinalizersAndCheckandDeleteContent(snapshot, content, deleteContent)
218221
if err != nil {
219222
return err
220223
}
221224

222-
klog.V(5).Infof("processIfDeletionTimestampSet[%s]: check if we should remove finalizer on snapshot source and remove it if we can", utils.SnapshotKey(snapshot))
225+
klog.V(5).Infof("processSnapshotWithDeletionTimestamp[%s]: check if we should remove finalizer on snapshot source and remove it if we can", utils.SnapshotKey(snapshot))
223226

224227
// Check if we should remove finalizer on PVC and remove it if we can.
225228
errFinalizer := ctrl.checkandRemovePVCFinalizer(snapshot)
@@ -231,7 +234,7 @@ func (ctrl *csiSnapshotCommonController) processIfDeletionTimestampSet(snapshot
231234
return nil
232235
}
233236

234-
// checkandRemoveSnapshotFinalizersAndCheckandDeleteContent deletes the content and removes snapshot finalizers if needed
237+
// checkandRemoveSnapshotFinalizersAndCheckandDeleteContent deletes the content and removes snapshot finalizers (VolumeSnapshotAsSourceFinalizer and VolumeSnapshotBoundFinalizer) if needed
235238
func (ctrl *csiSnapshotCommonController) checkandRemoveSnapshotFinalizersAndCheckandDeleteContent(snapshot *crdv1.VolumeSnapshot, content *crdv1.VolumeSnapshotContent, deleteContent bool) error {
236239
klog.V(5).Infof("checkandRemoveSnapshotFinalizersAndCheckandDeleteContent VolumeSnapshot[%s]: %s", utils.SnapshotKey(snapshot), utils.GetSnapshotStatusForLogging(snapshot))
237240

@@ -278,6 +281,12 @@ func (ctrl *csiSnapshotCommonController) checkandAddSnapshotFinalizers(snapshot
278281

279282
addSourceFinalizer := false
280283
addBoundFinalizer := false
284+
// NOTE: Source finalizer will be added to snapshot if
285+
// DeletionTimeStamp is nil and it is not set yet.
286+
// This is because the logic to check whether a PVC is being
287+
// created from the snapshot is expensive so we only go thru
288+
// it when we need to remove this finalizer and make sure
289+
// it is removed when it is not needed any more.
281290
if utils.NeedToAddSnapshotAsSourceFinalizer(snapshot) {
282291
addSourceFinalizer = true
283292
}

0 commit comments

Comments
 (0)