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
pull/8/head
Kubernetes Submit Queue 2018-06-21 13:59:15 -07:00 committed by GitHub
commit 570760dbe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -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)