@@ -144,10 +144,7 @@ func (ctrl *csiSnapshotCommonController) syncContent(content *crdv1.VolumeSnapsh
144
144
// Snapshot won't be deleted until content is deleted
145
145
// due to the finalizer.
146
146
if snapshot != nil && utils .IsSnapshotDeletionCandidate (snapshot ) {
147
- err = ctrl .setAnnVolumeSnapshotBeingDeleted (content )
148
- if err != nil {
149
- return err
150
- }
147
+ return ctrl .setAnnVolumeSnapshotBeingDeleted (content )
151
148
}
152
149
153
150
return nil
@@ -184,19 +181,19 @@ func (ctrl *csiSnapshotCommonController) syncSnapshot(snapshot *crdv1.VolumeSnap
184
181
func (ctrl * csiSnapshotCommonController ) checkContentAndBoundStatus (snapshot * crdv1.VolumeSnapshot ) (* crdv1.VolumeSnapshotContent , bool , bool , error ) {
185
182
// If content is deleted already, remove SnapshotBound finalizer
186
183
content , err := ctrl .getContentFromStore (snapshot )
187
- if err != nil {
184
+ if err != nil || content == nil {
188
185
return nil , false , false , err
189
186
}
190
187
deleteContent := false
191
188
// It is possible for getContentFromStore to return nil, nil
192
- if content != nil && content .Spec .DeletionPolicy == crdv1 .VolumeSnapshotContentDelete {
189
+ if content .Spec .DeletionPolicy == crdv1 .VolumeSnapshotContentDelete {
193
190
klog .V (5 ).Infof ("processFinalizersAndCheckandDeleteContent: Content [%s] deletion policy [%s] is delete." , content .Name , content .Spec .DeletionPolicy )
194
191
deleteContent = true
195
192
}
196
193
197
194
snapshotBound := false
198
195
// Check if the snapshot content is bound to the snapshot
199
- if content != nil && utils .IsSnapshotBound (snapshot , content ) {
196
+ if utils .IsSnapshotBound (snapshot , content ) {
200
197
klog .Infof ("syncSnapshot: VolumeSnapshot %s is bound to volumeSnapshotContent [%s]" , snapshot .Name , content .Name )
201
198
snapshotBound = true
202
199
@@ -244,7 +241,10 @@ func (ctrl *csiSnapshotCommonController) checkandRemoveSnapshotFinalizersAndChec
244
241
// Volume snapshot should be deleted. Check if it's used
245
242
// and remove finalizer if it's not.
246
243
// Check if a volume is being created from snapshot.
247
- inUse := ctrl .isVolumeBeingCreatedFromSnapshot (snapshot )
244
+ inUse := false
245
+ if content != nil {
246
+ inUse = ctrl .isVolumeBeingCreatedFromSnapshot (snapshot )
247
+ }
248
248
249
249
klog .V (5 ).Infof ("checkandRemoveSnapshotFinalizersAndCheckandDeleteContent[%s]: set DeletionTimeStamp on content." , utils .SnapshotKey (snapshot ))
250
250
// If content exists, set DeletionTimeStamp on the content;
@@ -904,10 +904,7 @@ func (ctrl *csiSnapshotCommonController) needsUpdateSnapshotStatus(snapshot *crd
904
904
if snapshot .Status == nil && content .Status != nil {
905
905
return true
906
906
}
907
- if snapshot .Status != nil && content .Status == nil {
908
- return false
909
- }
910
- if snapshot .Status == nil && content .Status == nil {
907
+ if content .Status == nil {
911
908
return false
912
909
}
913
910
if snapshot .Status .BoundVolumeSnapshotContentName == nil {
@@ -922,7 +919,10 @@ func (ctrl *csiSnapshotCommonController) needsUpdateSnapshotStatus(snapshot *crd
922
919
if snapshot .Status .ReadyToUse != nil && content .Status .ReadyToUse != nil && snapshot .Status .ReadyToUse != content .Status .ReadyToUse {
923
920
return true
924
921
}
925
- if (snapshot .Status .RestoreSize == nil && content .Status .RestoreSize != nil ) || (snapshot .Status .RestoreSize != nil && snapshot .Status .RestoreSize .IsZero () && content .Status .RestoreSize != nil && * content .Status .RestoreSize > 0 ) {
922
+ if snapshot .Status .RestoreSize == nil && content .Status .RestoreSize != nil {
923
+ return true
924
+ }
925
+ if snapshot .Status .RestoreSize != nil && snapshot .Status .RestoreSize .IsZero () && content .Status .RestoreSize != nil && * content .Status .RestoreSize > 0 {
926
926
return true
927
927
}
928
928
0 commit comments