Skip to content

Commit ed0e8ab

Browse files
committed
Address review comments
1 parent 582802f commit ed0e8ab

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

pkg/common-controller/snapshot_controller.go

+20-13
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ func (ctrl *csiSnapshotCommonController) syncContent(content *crdv1.VolumeSnapsh
100100
}
101101

102102
// Check if snapshot exists in cache store
103-
// If snapshotExists returns (nil, nil), it means snapshot not found
103+
// If getSnapshotFromStore returns (nil, nil), it means snapshot not found
104104
// and it may have already been deleted, and it will fall into the
105105
// snapshot == nil case below
106106
var snapshot *crdv1.VolumeSnapshot
107-
snapshot, err := ctrl.snapshotExists(snapshotName)
107+
snapshot, err := ctrl.getSnapshotFromStore(snapshotName)
108108
if err != nil {
109109
return err
110110
}
@@ -136,7 +136,7 @@ func (ctrl *csiSnapshotCommonController) syncContent(content *crdv1.VolumeSnapsh
136136
// Snapshot won't be deleted until content is deleted
137137
// due to the finalizer
138138
if snapshot == nil || utils.IsSnapshotDeletionCandidate(snapshot) {
139-
_, err = ctrl.setAnnVolumeSnapshotBeingDeleted(content)
139+
err = ctrl.setAnnVolumeSnapshotBeingDeleted(content)
140140
if err != nil {
141141
return err
142142
}
@@ -175,12 +175,12 @@ func (ctrl *csiSnapshotCommonController) syncSnapshot(snapshot *crdv1.VolumeSnap
175175

176176
func (ctrl *csiSnapshotCommonController) checkContentAndBoundStatus(snapshot *crdv1.VolumeSnapshot) (*crdv1.VolumeSnapshotContent, bool, bool, error) {
177177
// If content is deleted already, remove SnapshotBound finalizer
178-
content, err := ctrl.contentExists(snapshot)
178+
content, err := ctrl.getContentFromStore(snapshot)
179179
if err != nil {
180180
return nil, false, false, err
181181
}
182182
deleteContent := false
183-
// It is possible for contentExists to return nil, nil
183+
// It is possible for getContentFromStore to return nil, nil
184184
if content != nil && content.Spec.DeletionPolicy == crdv1.VolumeSnapshotContentDelete {
185185
klog.V(5).Infof("processFinalizersAndCheckandDeleteContent: Content [%s] deletion policy [%s] is delete.", content.Name, content.Spec.DeletionPolicy)
186186
deleteContent = true
@@ -202,6 +202,7 @@ func (ctrl *csiSnapshotCommonController) checkContentAndBoundStatus(snapshot *cr
202202
func (ctrl *csiSnapshotCommonController) processIfDeletionTimestampSet(snapshot *crdv1.VolumeSnapshot) error {
203203
klog.V(5).Infof("processIfDeletionTimestampSet VolumeSnapshot[%s]: %s", utils.SnapshotKey(snapshot), utils.GetSnapshotStatusForLogging(snapshot))
204204

205+
// If content is really not found in the cache store, err is nil
205206
content, deleteContent, _, err := ctrl.checkContentAndBoundStatus(snapshot)
206207
if err != nil {
207208
return err
@@ -1195,7 +1196,10 @@ func (ctrl *csiSnapshotCommonController) removeSnapshotFinalizer(snapshot *crdv1
11951196
return nil
11961197
}
11971198

1198-
func (ctrl *csiSnapshotCommonController) contentExists(snapshot *crdv1.VolumeSnapshot) (*crdv1.VolumeSnapshotContent, error) {
1199+
// getContentFromStore finds content from the cache store.
1200+
// If getContentFromStore returns (nil, nil), it means content not found
1201+
// and it may have already been deleted.
1202+
func (ctrl *csiSnapshotCommonController) getContentFromStore(snapshot *crdv1.VolumeSnapshot) (*crdv1.VolumeSnapshotContent, error) {
11991203
var contentName string
12001204
if snapshot.Status != nil && snapshot.Status.BoundVolumeSnapshotContentName != nil {
12011205
contentName = *snapshot.Status.BoundVolumeSnapshotContentName
@@ -1219,15 +1223,18 @@ func (ctrl *csiSnapshotCommonController) contentExists(snapshot *crdv1.VolumeSna
12191223
return content, nil
12201224
}
12211225

1222-
func (ctrl *csiSnapshotCommonController) snapshotExists(snapshotName string) (*crdv1.VolumeSnapshot, error) {
1226+
// getSnapshotFromStore finds snapshot from the cache store.
1227+
// If getSnapshotFromStore returns (nil, nil), it means snapshot not found
1228+
// and it may have already been deleted.
1229+
func (ctrl *csiSnapshotCommonController) getSnapshotFromStore(snapshotName string) (*crdv1.VolumeSnapshot, error) {
12231230
// Get the VolumeSnapshot by _name_
12241231
var snapshot *crdv1.VolumeSnapshot
12251232
obj, found, err := ctrl.snapshotStore.GetByKey(snapshotName)
12261233
if err != nil {
12271234
return nil, err
12281235
}
12291236
if !found {
1230-
klog.V(4).Infof("snapshotExists: snapshot %s not found", snapshotName)
1237+
klog.V(4).Infof("getSnapshotFromStore: snapshot %s not found", snapshotName)
12311238
// Fall through with snapshot = nil
12321239
return nil, nil
12331240
} else {
@@ -1236,30 +1243,30 @@ func (ctrl *csiSnapshotCommonController) snapshotExists(snapshotName string) (*c
12361243
if !ok {
12371244
return nil, fmt.Errorf("cannot convert object from snapshot cache to snapshot %q!?: %#v", snapshotName, obj)
12381245
}
1239-
klog.V(4).Infof("snapshotExists: snapshot %s found", snapshotName)
1246+
klog.V(4).Infof("getSnapshotFromStore: snapshot %s found", snapshotName)
12401247
}
12411248
return snapshot, nil
12421249
}
12431250

1244-
func (ctrl *csiSnapshotCommonController) setAnnVolumeSnapshotBeingDeleted(content *crdv1.VolumeSnapshotContent) (*crdv1.VolumeSnapshotContent, error) {
1251+
func (ctrl *csiSnapshotCommonController) setAnnVolumeSnapshotBeingDeleted(content *crdv1.VolumeSnapshotContent) error {
12451252
// Set AnnVolumeSnapshotBeingDeleted if it is not set yet
12461253
if !metav1.HasAnnotation(content.ObjectMeta, utils.AnnVolumeSnapshotBeingDeleted) {
12471254
klog.V(5).Infof("setAnnVolumeSnapshotBeingDeleted: set annotation [%s] on content [%s].", utils.AnnVolumeSnapshotBeingDeleted, content.Name)
12481255
metav1.SetMetaDataAnnotation(&content.ObjectMeta, utils.AnnVolumeSnapshotBeingDeleted, "yes")
12491256

12501257
updateContent, err := ctrl.clientset.SnapshotV1beta1().VolumeSnapshotContents().Update(content)
12511258
if err != nil {
1252-
return content, newControllerUpdateError(content.Name, err.Error())
1259+
return newControllerUpdateError(content.Name, err.Error())
12531260
}
12541261
// update content if update is successful
12551262
content = updateContent
12561263

12571264
_, err = ctrl.storeContentUpdate(content)
12581265
if err != nil {
12591266
klog.V(4).Infof("setAnnVolumeSnapshotBeingDeleted for content [%s]: cannot update internal cache %v", content.Name, err)
1260-
return content, err
1267+
return err
12611268
}
12621269
klog.V(5).Infof("setAnnVolumeSnapshotBeingDeleted: volume snapshot content %+v", content)
12631270
}
1264-
return content, nil
1271+
return nil
12651272
}

0 commit comments

Comments
 (0)