@@ -100,11 +100,11 @@ func (ctrl *csiSnapshotCommonController) syncContent(content *crdv1.VolumeSnapsh
100
100
}
101
101
102
102
// 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
104
104
// and it may have already been deleted, and it will fall into the
105
105
// snapshot == nil case below
106
106
var snapshot * crdv1.VolumeSnapshot
107
- snapshot , err := ctrl .snapshotExists (snapshotName )
107
+ snapshot , err := ctrl .getSnapshotFromStore (snapshotName )
108
108
if err != nil {
109
109
return err
110
110
}
@@ -136,7 +136,7 @@ func (ctrl *csiSnapshotCommonController) syncContent(content *crdv1.VolumeSnapsh
136
136
// Snapshot won't be deleted until content is deleted
137
137
// due to the finalizer
138
138
if snapshot == nil || utils .IsSnapshotDeletionCandidate (snapshot ) {
139
- _ , err = ctrl .setAnnVolumeSnapshotBeingDeleted (content )
139
+ err = ctrl .setAnnVolumeSnapshotBeingDeleted (content )
140
140
if err != nil {
141
141
return err
142
142
}
@@ -175,12 +175,12 @@ func (ctrl *csiSnapshotCommonController) syncSnapshot(snapshot *crdv1.VolumeSnap
175
175
176
176
func (ctrl * csiSnapshotCommonController ) checkContentAndBoundStatus (snapshot * crdv1.VolumeSnapshot ) (* crdv1.VolumeSnapshotContent , bool , bool , error ) {
177
177
// If content is deleted already, remove SnapshotBound finalizer
178
- content , err := ctrl .contentExists (snapshot )
178
+ content , err := ctrl .getContentFromStore (snapshot )
179
179
if err != nil {
180
180
return nil , false , false , err
181
181
}
182
182
deleteContent := false
183
- // It is possible for contentExists to return nil, nil
183
+ // It is possible for getContentFromStore to return nil, nil
184
184
if content != nil && content .Spec .DeletionPolicy == crdv1 .VolumeSnapshotContentDelete {
185
185
klog .V (5 ).Infof ("processFinalizersAndCheckandDeleteContent: Content [%s] deletion policy [%s] is delete." , content .Name , content .Spec .DeletionPolicy )
186
186
deleteContent = true
@@ -202,6 +202,7 @@ func (ctrl *csiSnapshotCommonController) checkContentAndBoundStatus(snapshot *cr
202
202
func (ctrl * csiSnapshotCommonController ) processIfDeletionTimestampSet (snapshot * crdv1.VolumeSnapshot ) error {
203
203
klog .V (5 ).Infof ("processIfDeletionTimestampSet VolumeSnapshot[%s]: %s" , utils .SnapshotKey (snapshot ), utils .GetSnapshotStatusForLogging (snapshot ))
204
204
205
+ // If content is really not found in the cache store, err is nil
205
206
content , deleteContent , _ , err := ctrl .checkContentAndBoundStatus (snapshot )
206
207
if err != nil {
207
208
return err
@@ -1195,7 +1196,10 @@ func (ctrl *csiSnapshotCommonController) removeSnapshotFinalizer(snapshot *crdv1
1195
1196
return nil
1196
1197
}
1197
1198
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 ) {
1199
1203
var contentName string
1200
1204
if snapshot .Status != nil && snapshot .Status .BoundVolumeSnapshotContentName != nil {
1201
1205
contentName = * snapshot .Status .BoundVolumeSnapshotContentName
@@ -1219,15 +1223,18 @@ func (ctrl *csiSnapshotCommonController) contentExists(snapshot *crdv1.VolumeSna
1219
1223
return content , nil
1220
1224
}
1221
1225
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 ) {
1223
1230
// Get the VolumeSnapshot by _name_
1224
1231
var snapshot * crdv1.VolumeSnapshot
1225
1232
obj , found , err := ctrl .snapshotStore .GetByKey (snapshotName )
1226
1233
if err != nil {
1227
1234
return nil , err
1228
1235
}
1229
1236
if ! found {
1230
- klog .V (4 ).Infof ("snapshotExists : snapshot %s not found" , snapshotName )
1237
+ klog .V (4 ).Infof ("getSnapshotFromStore : snapshot %s not found" , snapshotName )
1231
1238
// Fall through with snapshot = nil
1232
1239
return nil , nil
1233
1240
} else {
@@ -1236,30 +1243,30 @@ func (ctrl *csiSnapshotCommonController) snapshotExists(snapshotName string) (*c
1236
1243
if ! ok {
1237
1244
return nil , fmt .Errorf ("cannot convert object from snapshot cache to snapshot %q!?: %#v" , snapshotName , obj )
1238
1245
}
1239
- klog .V (4 ).Infof ("snapshotExists : snapshot %s found" , snapshotName )
1246
+ klog .V (4 ).Infof ("getSnapshotFromStore : snapshot %s found" , snapshotName )
1240
1247
}
1241
1248
return snapshot , nil
1242
1249
}
1243
1250
1244
- func (ctrl * csiSnapshotCommonController ) setAnnVolumeSnapshotBeingDeleted (content * crdv1.VolumeSnapshotContent ) ( * crdv1. VolumeSnapshotContent , error ) {
1251
+ func (ctrl * csiSnapshotCommonController ) setAnnVolumeSnapshotBeingDeleted (content * crdv1.VolumeSnapshotContent ) error {
1245
1252
// Set AnnVolumeSnapshotBeingDeleted if it is not set yet
1246
1253
if ! metav1 .HasAnnotation (content .ObjectMeta , utils .AnnVolumeSnapshotBeingDeleted ) {
1247
1254
klog .V (5 ).Infof ("setAnnVolumeSnapshotBeingDeleted: set annotation [%s] on content [%s]." , utils .AnnVolumeSnapshotBeingDeleted , content .Name )
1248
1255
metav1 .SetMetaDataAnnotation (& content .ObjectMeta , utils .AnnVolumeSnapshotBeingDeleted , "yes" )
1249
1256
1250
1257
updateContent , err := ctrl .clientset .SnapshotV1beta1 ().VolumeSnapshotContents ().Update (content )
1251
1258
if err != nil {
1252
- return content , newControllerUpdateError (content .Name , err .Error ())
1259
+ return newControllerUpdateError (content .Name , err .Error ())
1253
1260
}
1254
1261
// update content if update is successful
1255
1262
content = updateContent
1256
1263
1257
1264
_ , err = ctrl .storeContentUpdate (content )
1258
1265
if err != nil {
1259
1266
klog .V (4 ).Infof ("setAnnVolumeSnapshotBeingDeleted for content [%s]: cannot update internal cache %v" , content .Name , err )
1260
- return content , err
1267
+ return err
1261
1268
}
1262
1269
klog .V (5 ).Infof ("setAnnVolumeSnapshotBeingDeleted: volume snapshot content %+v" , content )
1263
1270
}
1264
- return content , nil
1271
+ return nil
1265
1272
}
0 commit comments