@@ -147,25 +147,40 @@ func (ctrl *csiSnapshotSideCarController) updateContentErrorStatusWithEvent(cont
147147 return nil
148148 }
149149
150+ var patches []utils.PatchOp
150151 ready := false
151- patch := []utils.PatchOp {
152- {
152+ contentStatusError := & crdv1.VolumeSnapshotError {
153+ Time : & metav1.Time {
154+ Time : time .Now (),
155+ },
156+ Message : & message ,
157+ }
158+ if content .Status == nil {
159+ // Initialize status if nil
160+ patches = append (patches , utils.PatchOp {
153161 Op : "replace" ,
154- Path : "/status/error" ,
155- Value : & crdv1.VolumeSnapshotError {
156- Time : & metav1.Time {
157- Time : time .Now (),
158- },
159- Message : & message ,
162+ Path : "/status" ,
163+ Value : & crdv1.VolumeSnapshotContentStatus {
164+ ReadyToUse : & ready ,
165+ Error : contentStatusError ,
160166 },
161- },
162- {
167+ })
168+ } else {
169+ // Patch status if non-nil
170+ patches = append (patches , utils.PatchOp {
171+ Op : "replace" ,
172+ Path : "/status/error" ,
173+ Value : contentStatusError ,
174+ })
175+ patches = append (patches , utils.PatchOp {
163176 Op : "replace" ,
164177 Path : "/status/readyToUse" ,
165178 Value : & ready ,
166- },
179+ })
180+
167181 }
168- newContent , err := utils .PatchVolumeSnapshotContent (content , patch , ctrl .clientset , "status" )
182+
183+ newContent , err := utils .PatchVolumeSnapshotContent (content , patches , ctrl .clientset , "status" )
169184
170185 // Emit the event even if the status update fails so that user can see the error
171186 ctrl .eventRecorder .Event (newContent , eventtype , reason , message )
0 commit comments