🐛 Fix object overwrite on patch for fake client#1651
🐛 Fix object overwrite on patch for fake client#1651k8s-ci-robot merged 1 commit intokubernetes-sigs:masterfrom FillZpp:fix-fake-client-patch-overwrite
Conversation
|
Hi @FillZpp. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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. |
alvaroaleman
left a comment
There was a problem hiding this comment.
This is essentially the same issue as #1639 which was fixed by zeroing the target object in the decoder (but your approach is likely more efficient here).
Could you also do this for Get and List? They have the same issue
/ok-to-test
pkg/client/fake/client.go
Outdated
| j, err := json.Marshal(o) | ||
| if err != nil { | ||
| return err | ||
| objVal := reflect.ValueOf(obj) |
There was a problem hiding this comment.
If we use reflect to assign the value, we need to deepcopy first
Signed-off-by: FillZpp <FillZpp.pub@gmail.com>
Sure. But I find that we can not simply use So I have to zero each object before decode into it, just like the thing you do in |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, FillZpp The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
These tests were not preparing the test objects correctly: they only updated them in memory but not on the fake client. This wasn't caught until now because the fake client mimicked the real json decoder, which didn't unset fields not present on the server. Now that the fake client zeroes fields, the tests started failing (which is correct). So fix the tests. ref kubernetes-sigs/controller-runtime#1651
* Upgrade to k8s.io/*@v0.22.2 in go.mod
* [automated] make revendor
* [automated] make generate
* [automated] make revendor
github.com/go-openapi/spec seems to be orphaned after previous make generate
* Upgrade to c-r@v0.10.2 in go.mod
Also, upgrade setup-envtest (doesn't have a tagged release yet, so use
release commit instead)
* [automated] make revendor
* Upgrade to controller-tools@v0.7.0 in go.mod
* [automated] make revendor
* Add missing WarningsOn{Create,Update} to rest strategies
* Replace dot imports for github.com/onsi/gomega/types
Fix linting errors: `Assertion` redeclared in this block (typecheck)
* Switch to typed values for WebhookInstallOptions.*Webhooks
ref kubernetes-sigs/controller-runtime#1626
* RequestCertificate now takes an optional requestedDuration
ref kubernetes/kubernetes#99494
* Switch to matchers.DeepEqual to test semantic equality
Maps (e.g. labels, selectors, resource requirements) might be sorted differently
than expected. Hence, use semantic equality instead of strict equality, as this
is what matters to us.
Also, DeepEqual outputs yaml and adds a nice diff indicator instead of printing
some large confusing go struct representation.
* Add new memorySwap field to expected kubelet config
ref kubernetes/kubernetes#102823
* Round condition.lastUpdateTime to seconds in test
There were several changes in the fake clients that might cause the failure
to happen just now.
* Correct unit tests falsely succeeding
These tests were not preparing the test objects correctly: they only updated
them in memory but not on the fake client. This wasn't caught until now
because the fake client mimicked the real json decoder, which didn't unset
fields not present on the server. Now that the fake client zeroes fields,
the tests started failing (which is correct). So fix the tests.
ref kubernetes-sigs/controller-runtime#1651
* Remove workarounds for missing zeroing in json decoder
Now that the c-r client zeroes fields before decoding into the object,
we can drop our workarounds for this, so basically drop
kutil.CreateResetObjectFunc and its usages.
ref kubernetes-sigs/controller-runtime#1640
* Drop setting webhook gvk explicitly in envtest
webhookConfig.SetGroupVersionKind is not needed anymore with
kubernetes-sigs/controller-runtime#1665
* Add some follow-up TODO comments
* [automated] make generate
but with go 1.16.9
* Address review comments
Signed-off-by: FillZpp FillZpp.pub@gmail.com
Previously the fake client tried to decode the new object after patching to the object outside, which will cause some fields that should be removed in this patch remain in the object.
It should overwrite the object using reflect set, just like the way in cache get.