Fix error for strategic merge patch of custom resources#53558
Fix error for strategic merge patch of custom resources#53558k8s-github-robot merged 1 commit intokubernetes:masterfrom
Conversation
|
Hi @nikhita. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
Now, the error message is shown as: $ cat crd.yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: crontabs.stable.example.com
spec:
group: stable.example.com
version: v1
scope: Namespaced
names:
plural: crontabs
singular: crontab
kind: CronTab
shortNames:
- ct
$ kubectl create -f crd.yaml
customresourcedefinition "crontabs.stable.example.com" created
$ cat crontab-object.yaml
apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
name: my-new-cron-object
spec:
cronSpec: "* * * * */5"
image: my-awesome-cron-image
$ kubectl create -f crontab-object.yaml
crontab "my-new-cron-object" created
$ kubectl patch crontab my-new-cron-object -p '{"spec":{"image":"new-image"}}'
Error from server: cannot apply strategic merge patch for custom resources, try --type merge |
|
/ok-to-test |
|
/retest |
| // each field in a strategic merge patch, we can't easily do a strategic merge for custom resources. | ||
| // So we should fail fast and return an error. | ||
| if t.Name() == "Unstructured" { | ||
| return nil, fmt.Errorf("cannot apply strategic merge patch for custom resources, try --type merge") |
There was a problem hiding this comment.
Isn't the strategy patch logic without any metadata just the classical non-strategic patch? What does the user see now?
In general, I would prefer not to mention custom resources here in apimachinery. An error constant in vendor/k8s.io/apimachinery/pkg/util/mergepatch/errors.go with "ErrUnsupportedPatchFormat" would make more sense.
7507ac4 to
e93baef
Compare
The user sees: After this update, it is |
|
@nikhita feel like adding a unit test? |
|
@ncdc Will do! Also, maybe we should hold this off until #53379 (comment) is resolved (working on it). |
|
Looks good to me. |
e93baef to
2ae617e
Compare
|
Added a test and updated the comment to add more detail into why we can't support strategic merge patch for custom resources. |
There was a problem hiding this comment.
would _, ok := dataStruct.(Unstructured); ok be the same?
There was a problem hiding this comment.
_, ok := dataStruct.(*unstructured.Unstructured); ok would be the same (with the pointer). 👍
updated.
We need the go struct tags `patchMergeKey` and `patchStrategy` for fields that support a strategic merge patch. For native resources, we can easily figure out these tags since we know the fields. Because custom resources are decoded as Unstructured and because we're missing the metadata about how to handle each field in a strategic merge patch, we can't find the go struct tags. Hence, we can't easily do a strategic merge for custom resources. So we should fail fast and return an error.
2ae617e to
79349c9
Compare
We need the go struct tags `patchMergeKey` and `patchStrategy` for fields that support a strategic merge patch. For native resources, we can easily figure out these tags since we know the fields. Because custom resources are decoded as Unstructured and because we're missing the metadata about how to handle each field in a strategic merge patch, we can't find the go struct tags. Hence, we can't easily do a strategic merge for custom resources. So we should fail fast and return an error.
2ae617e to
79349c9
Compare
|
/retest |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: nikhita, sttts Associated issue: 50037 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
|
Automatic merge from submit-queue (batch tested with PRs 54800, 53898, 54812, 54921, 53558). If you want to cherry-pick this change to another branch, please follow the instructions here. |
Fixes #50037.
We need the go struct tags
patchMergeKeyandpatchStrategyfor fields that support a strategic merge patch. For native resources, we can easily figure out these tags since we know the fields.Because custom resources are decoded as Unstructured and because we're missing the metadata about how to handle each field in a strategic merge patch, we can't find the go struct tags. Hence, we can't easily do a strategic merge for custom resources.
So we should fail fast and return an error.
Release note:
/cc @sttts @deads2k @ncdc