Unverified Commit 570760db authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #65128 from brendandburns/kubectl

Automatic merge from submit-queue (batch tested with PRs 65116, 61718, 65140, 65128, 65099). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Detect a missing key error and print a cleaner message. Closes https://github.com/kubernetes/kubernetes/issues/63247 @kubernetes/sig-cli-bugs
parents 7b53aca7 e3d22423
......@@ -306,7 +306,15 @@ func getPatchedJSON(patchType types.PatchType, originalJS, patchJS []byte, gvk s
if err != nil {
return nil, err
}
return patchObj.Apply(originalJS)
bytes, err := patchObj.Apply(originalJS)
// TODO: This is pretty hacky, we need a better structured error from the json-patch
if err != nil && strings.Contains(err.Error(), "doc is missing key") {
msg := err.Error()
ix := strings.Index(msg, "key:")
key := msg[ix+5:]
return bytes, fmt.Errorf("Object to be patched is missing field (%s)", key)
}
return bytes, err
case types.MergePatchType:
return jsonpatch.MergePatch(originalJS, patchJS)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment