Merge pull request #601 from ggriffiths/fix_patch_error_status

Fix an issue where patch will fail when status is nil
This commit is contained in:
Kubernetes Prow Robot
2021-11-11 12:50:08 -08:00
committed by GitHub

View File

@@ -147,25 +147,40 @@ func (ctrl *csiSnapshotSideCarController) updateContentErrorStatusWithEvent(cont
return nil
}
var patches []utils.PatchOp
ready := false
patch := []utils.PatchOp{
{
Op: "replace",
Path: "/status/error",
Value: &crdv1.VolumeSnapshotError{
Time: &metav1.Time{
Time: time.Now(),
},
Message: &message,
},
contentStatusError := &crdv1.VolumeSnapshotError{
Time: &metav1.Time{
Time: time.Now(),
},
{
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",
Path: "/status/readyToUse",
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
ctrl.eventRecorder.Event(newContent, eventtype, reason, message)