Change:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --What happened: Attempting to add a finalizer to a custom resource using a strategic merge patch fails: kubectl sends the request with a media type () that the server rejects: What you expected to happen: kubectl sends the patch with a media type that the server accepts. How to reproduce it (as minimally and precisely as possible): Apply the example custom resource definition from the sample controller project: Create a sample custom resource: Attempt to patch the CR: Anything else we need to know?: Environment: Kubernetes version (use ): Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.1", GitCommit:"", GitTreeState:"clean", BuildDate:"2020-12-18T12:09:25Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.1", GitCommit:"", GitTreeState:"clean", BuildDate:"2020-12-18T12:00:47Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"} Cloud provider or hardware configuration: libvirt virtual machine OS (e.g: ): NAME="Ubuntu" VERSION="20.04.1 LTS (Focal Fossa)" ID=ubuntu IDLIKE=debian PRETTYNAME="Ubuntu 20.04.1 LTS" VERSIONID="20.04" HOMEURL="" SUPPORTURL="" BUGREPORTURL="" PRIVACYPOLICYURL="" VERSIONCODENAME=focal UBUNTUCODENAME=focal Kernel (e.g. ): Linux egw 5.4.0-56-generic -Ubuntu SMP Mon Nov 23 19:20:19 UTC 2020 x8664 x8664 x8664 GNU/Linux Install tools: kubeadm Network plugin and version (if this is a network-related bug): Others:
/sig cli
/assign Will look into this. You can refer to and the quota above. "strategic merge patch format is not supported" for custom resource. The error message is not that clear.
When you run it with , it suggests to use --type=merge and it works. uses uses
This seems to work as expected. Do you think we need to make the server response more friendly as the message of .
Thank you, Paco, for looking into this! The problem is that merge patch is unable to do some important operations (for example, safely removing a finalizer from an object's metadata) so it's not a substitute for strategic merge. The error message suggesting that the client switch to merge patch is unhelpful, but a clear message indicating that strategic merge patch is unsupported would be helpful, and documentation that strategic merge patch is unsupported for Custom Resource objects would also be helpful. For most use cases the proper workaround is update with retry, not merge patch. Thank you!
/unassign
this is a topic for sig api machinery. /sig api-machinery
/cc /triage accepted
Do you think we need to make the server response more friendly as the message of kubectl client --dry-run=client. Apologies for the really late response on this. I've created to improve the message. /assign

Discussion:
// get a typed object for this GVK if we need to apply a strategic merge patch obj, err := creater.New(gvk) if err != nil { <del> return nil, fmt.Errorf("cannot apply strategic merge patch for %s locally, try --type merge", gvk.String()) </del> <ins> return nil, fmt.Errorf("strategic merge patch is not supported for %s locally, try --type merge", gvk.String()) </ins> } return strategicpatch.StrategicMergePatch(originalJS, patchJS, obj)