Fix an issue where patch will fail when status is nil
Signed-off-by: Grant Griffiths <ggriffiths@purestorage.com>
This commit is contained in:
@@ -147,25 +147,40 @@ func (ctrl *csiSnapshotSideCarController) updateContentErrorStatusWithEvent(cont
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var patches []utils.PatchOp
|
||||||
ready := false
|
ready := false
|
||||||
patch := []utils.PatchOp{
|
contentStatusError := &crdv1.VolumeSnapshotError{
|
||||||
{
|
Time: &metav1.Time{
|
||||||
Op: "replace",
|
Time: time.Now(),
|
||||||
Path: "/status/error",
|
|
||||||
Value: &crdv1.VolumeSnapshotError{
|
|
||||||
Time: &metav1.Time{
|
|
||||||
Time: time.Now(),
|
|
||||||
},
|
|
||||||
Message: &message,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
Message: &message,
|
||||||
|
}
|
||||||
|
if content.Status == nil {
|
||||||
|
// Initialize status if nil
|
||||||
|
patches = append(patches, utils.PatchOp{
|
||||||
|
Op: "replace",
|
||||||
|
Path: "/status",
|
||||||
|
Value: &crdv1.VolumeSnapshotContentStatus{
|
||||||
|
ReadyToUse: &ready,
|
||||||
|
Error: contentStatusError,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// Patch status if non-nil
|
||||||
|
patches = append(patches, utils.PatchOp{
|
||||||
|
Op: "replace",
|
||||||
|
Path: "/status/error",
|
||||||
|
Value: contentStatusError,
|
||||||
|
})
|
||||||
|
patches = append(patches, utils.PatchOp{
|
||||||
Op: "replace",
|
Op: "replace",
|
||||||
Path: "/status/readyToUse",
|
Path: "/status/readyToUse",
|
||||||
Value: &ready,
|
Value: &ready,
|
||||||
},
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
newContent, err := utils.PatchVolumeSnapshotContent(content, patch, ctrl.clientset, "status")
|
|
||||||
|
newContent, err := utils.PatchVolumeSnapshotContent(content, patches, ctrl.clientset, "status")
|
||||||
|
|
||||||
// Emit the event even if the status update fails so that user can see the error
|
// Emit the event even if the status update fails so that user can see the error
|
||||||
ctrl.eventRecorder.Event(newContent, eventtype, reason, message)
|
ctrl.eventRecorder.Event(newContent, eventtype, reason, message)
|
||||||
|
Reference in New Issue
Block a user