Skip to content

Commit 37d5705

Browse files
committed
Address review comments
1 parent 29e69f4 commit 37d5705

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pkg/common-controller/snapshot_controller.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,7 @@ func (ctrl *csiSnapshotCommonController) syncContent(content *crdv1.VolumeSnapsh
144144
// Snapshot won't be deleted until content is deleted
145145
// due to the finalizer.
146146
if snapshot != nil && utils.IsSnapshotDeletionCandidate(snapshot) {
147-
err = ctrl.setAnnVolumeSnapshotBeingDeleted(content)
148-
if err != nil {
149-
return err
150-
}
147+
return ctrl.setAnnVolumeSnapshotBeingDeleted(content)
151148
}
152149

153150
return nil
@@ -184,19 +181,19 @@ func (ctrl *csiSnapshotCommonController) syncSnapshot(snapshot *crdv1.VolumeSnap
184181
func (ctrl *csiSnapshotCommonController) checkContentAndBoundStatus(snapshot *crdv1.VolumeSnapshot) (*crdv1.VolumeSnapshotContent, bool, bool, error) {
185182
// If content is deleted already, remove SnapshotBound finalizer
186183
content, err := ctrl.getContentFromStore(snapshot)
187-
if err != nil {
184+
if err != nil || content == nil {
188185
return nil, false, false, err
189186
}
190187
deleteContent := false
191188
// 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 {
193190
klog.V(5).Infof("processFinalizersAndCheckandDeleteContent: Content [%s] deletion policy [%s] is delete.", content.Name, content.Spec.DeletionPolicy)
194191
deleteContent = true
195192
}
196193

197194
snapshotBound := false
198195
// Check if the snapshot content is bound to the snapshot
199-
if content != nil && utils.IsSnapshotBound(snapshot, content) {
196+
if utils.IsSnapshotBound(snapshot, content) {
200197
klog.Infof("syncSnapshot: VolumeSnapshot %s is bound to volumeSnapshotContent [%s]", snapshot.Name, content.Name)
201198
snapshotBound = true
202199

@@ -244,7 +241,10 @@ func (ctrl *csiSnapshotCommonController) checkandRemoveSnapshotFinalizersAndChec
244241
// Volume snapshot should be deleted. Check if it's used
245242
// and remove finalizer if it's not.
246243
// 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+
}
248248

249249
klog.V(5).Infof("checkandRemoveSnapshotFinalizersAndCheckandDeleteContent[%s]: set DeletionTimeStamp on content.", utils.SnapshotKey(snapshot))
250250
// If content exists, set DeletionTimeStamp on the content;
@@ -904,10 +904,7 @@ func (ctrl *csiSnapshotCommonController) needsUpdateSnapshotStatus(snapshot *crd
904904
if snapshot.Status == nil && content.Status != nil {
905905
return true
906906
}
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 {
911908
return false
912909
}
913910
if snapshot.Status.BoundVolumeSnapshotContentName == nil {
@@ -922,7 +919,10 @@ func (ctrl *csiSnapshotCommonController) needsUpdateSnapshotStatus(snapshot *crd
922919
if snapshot.Status.ReadyToUse != nil && content.Status.ReadyToUse != nil && snapshot.Status.ReadyToUse != content.Status.ReadyToUse {
923920
return true
924921
}
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 {
926926
return true
927927
}
928928

0 commit comments

Comments
 (0)