Skip to content

Commit

Permalink
Merge pull request #601 from ggriffiths/fix_patch_error_status
Browse files Browse the repository at this point in the history
Fix an issue where patch will fail when status is nil
  • Loading branch information
k8s-ci-robot authored Nov 11, 2021
2 parents caef201 + f3d3453 commit 8bb933b
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions pkg/sidecar-controller/snapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,40 @@ func (ctrl *csiSnapshotSideCarController) updateContentErrorStatusWithEvent(cont
return nil
}

var patches []utils.PatchOp
ready := false
patch := []utils.PatchOp{
{
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/error",
Value: &crdv1.VolumeSnapshotError{
Time: &metav1.Time{
Time: time.Now(),
},
Message: &message,
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)
Expand Down

0 comments on commit 8bb933b

Please sign in to comment.