@@ -116,9 +116,9 @@ func (ctrl *csiSnapshotCommonController) syncContent(content *crdv1.VolumeSnapsh
116
116
// Treat the content as bound to a missing snapshot.
117
117
snapshot = nil
118
118
} else {
119
- // TODO(xyang): Write a function to check if snapshot.Status is different from content.Status and add snapshot to queue if there is a difference and it is worth triggering an snapshot status update
120
- // Check if content status is set to true and update snapshot status if so
121
- if snapshot != nil && content . Status != nil && content . Status . ReadyToUse != nil && * content . Status . ReadyToUse == true {
119
+ // Check if snapshot.Status is different from content.Status and add snapshot to queue
120
+ // if there is a difference and it is worth triggering an snapshot status update.
121
+ if snapshot != nil && ctrl . needsUpdateSnapshotStatus ( snapshot , content ) {
122
122
klog .V (4 ).Infof ("synchronizing VolumeSnapshotContent for snapshot [%s]: update snapshot status to true if needed." , snapshotName )
123
123
// Manually trigger a snapshot status update to happen
124
124
// right away so that it is in-sync with the content status
@@ -895,6 +895,39 @@ func (ctrl *csiSnapshotCommonController) bindandUpdateVolumeSnapshot(snapshotCon
895
895
return snapshotCopy , nil
896
896
}
897
897
898
+ // needsUpdateSnapshotStatus compares snapshot status with the content status and decide
899
+ // if snapshot status needs to be updated based on content status
900
+ func (ctrl * csiSnapshotCommonController ) needsUpdateSnapshotStatus (snapshot * crdv1.VolumeSnapshot , content * crdv1.VolumeSnapshotContent ) bool {
901
+ klog .V (5 ).Infof ("needsUpdateSnapshotStatus[%s]" , utils .SnapshotKey (snapshot ))
902
+
903
+ if snapshot .Status == nil && content .Status != nil {
904
+ return true
905
+ }
906
+ if snapshot .Status != nil && content .Status == nil {
907
+ return false
908
+ }
909
+ if snapshot .Status == nil && content .Status == nil {
910
+ return false
911
+ }
912
+ if snapshot .Status .BoundVolumeSnapshotContentName == nil {
913
+ return true
914
+ }
915
+ if snapshot .Status .CreationTime == nil && content .Status .CreationTime != nil {
916
+ return true
917
+ }
918
+ if snapshot .Status .ReadyToUse == nil && content .Status .ReadyToUse != nil {
919
+ return true
920
+ }
921
+ if snapshot .Status .ReadyToUse != nil && content .Status .ReadyToUse != nil && snapshot .Status .ReadyToUse != content .Status .ReadyToUse {
922
+ return true
923
+ }
924
+ 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 ) {
925
+ return true
926
+ }
927
+
928
+ return false
929
+ }
930
+
898
931
// UpdateSnapshotStatus updates snapshot status based on content status
899
932
func (ctrl * csiSnapshotCommonController ) updateSnapshotStatus (snapshot * crdv1.VolumeSnapshot , content * crdv1.VolumeSnapshotContent ) (* crdv1.VolumeSnapshot , error ) {
900
933
klog .V (5 ).Infof ("updateSnapshotStatus[%s]" , utils .SnapshotKey (snapshot ))
0 commit comments