mirror of https://github.com/k3s-io/k3s
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-bugspull/8/head
commit
570760dbe2
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue