-
Notifications
You must be signed in to change notification settings - Fork 1.2k
⚠️ Change client.Patch to take client.Object for performance #1395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
Instructions 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. |
Welcome @cbandy! |
Hi @cbandy. 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. Instructions 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 signed it |
/milestone v0.9.x If we switch the interface accepted in the method, we need to mark this as |
/ok-to-test |
If we're changing the signatures, perhaps we should add an options vararg to MergeFrom like |
@cbandy Could we discuss that change in a separate issue? |
Certainly. Is the signature (with runtime.Object) acceptable as-is in this PR? |
We should move to |
Most uses of merge-patch will be for built-in types or kubebuilder- generated custom resources which have accessors for ResourceVersion. Using these with DeepCopyObject() is simple and fast. name old time/op new time/op delta MergeFrom/NoOptions 91.6µs ± 4% 107.3µs ±26% ~ (p=0.417 n=7+10) MergeFrom/NoOptions-2 112µs ±18% 88µs ±11% -21.15% (p=0.000 n=10+9) MergeFrom/WithOptimisticLock 163µs ± 3% 121µs ± 3% -25.66% (p=0.000 n=10+8) MergeFrom/WithOptimisticLock-2 137µs ± 4% 101µs ± 4% -26.28% (p=0.000 n=10+10) name old alloc/op new alloc/op delta MergeFrom/NoOptions 20.3kB ± 0% 20.3kB ± 0% ~ (all equal) MergeFrom/NoOptions-2 20.3kB ± 0% 20.3kB ± 0% ~ (all equal) MergeFrom/WithOptimisticLock 34.1kB ± 0% 26.7kB ± 0% -21.89% (p=0.000 n=10+10) MergeFrom/WithOptimisticLock-2 34.2kB ± 0% 26.7kB ± 0% -21.89% (p=0.000 n=10+8) name old allocs/op new allocs/op delta MergeFrom/NoOptions 359 ± 0% 359 ± 0% ~ (all equal) MergeFrom/NoOptions-2 359 ± 0% 359 ± 0% ~ (all equal) MergeFrom/WithOptimisticLock 579 ± 0% 390 ± 0% -32.64% (p=0.000 n=10+10) MergeFrom/WithOptimisticLock-2 579 ± 0% 390 ± 0% -32.64% (p=0.000 n=10+10)
This allows us to use metav1 accessors to speed up the merge-patch implementation.
@cbandy: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions 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. |
LGTM please squash commits |
/milestone v0.9.x |
/assign @alvaroaleman |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/label tide/merge-method-squash
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, cbandy The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
* Upgrade to k/*@v0.21.1 in go.mod * [automated] make revendor for k/* dependencies This deletes pkg/mock/client-go/kubernetes/mocks.go to resolve the following deadlock: make revendor fails because of some dependencies of the file and make generate fails because of missing revendoring. File will be generated again in the next commit. * [automated] make generate for k/* dependencies * Upgrade to [email protected] in go.mod * [automated] make revendor for c-r dependency `make revendor` results in `hack/setup-envtest.sh` being broken, so reset the file after running `make revendor`. Adaption to breaking changes in the upstream file will be done in a later commit. * manager.NewClientBuilder was removed in favor of cluster.DefaultNewClient ref kubernetes-sigs/controller-runtime#1409 * client.*MergeFrom* now take client.Object instead of runtime.Object ref kubernetes-sigs/controller-runtime#1395 * [automated] make generate for c-r dependency * Adapt to changes in labels.NewRequirement ref kubernetes/kubernetes#97538 * Adapt to new setup-envtest tool Makes use of the new setup-envtest tool (kubernetes-sigs/controller-runtime#1488) in hack/setup-envtest.sh instead of vendoring hack/setup-envtest.sh and fetching binaries with that. * [automated] make revendor for setup-envtest tool * Adapt pkg/envtest to upstream changes - Make use of the new Users concept in envtest to provision a dedicated user for gardener-apiserver and a valid kubeconfig - Make use of the new way to configure API server args to easily configure kube-aggregator flags - Also generate certs for aggregation layer on our own instead of reusing the API server ca/certs (which is semantically correct), which allows us to drop our fork including kubernetes-sigs/controller-runtime#1449 * Styling nits
…tes-sigs#1395) * ✨ Add a fast path for client.Object in merge-patch Most uses of merge-patch will be for built-in types or kubebuilder- generated custom resources which have accessors for ResourceVersion. Using these with DeepCopyObject() is simple and fast. name old time/op new time/op delta MergeFrom/NoOptions 91.6µs ± 4% 107.3µs ±26% ~ (p=0.417 n=7+10) MergeFrom/NoOptions-2 112µs ±18% 88µs ±11% -21.15% (p=0.000 n=10+9) MergeFrom/WithOptimisticLock 163µs ± 3% 121µs ± 3% -25.66% (p=0.000 n=10+8) MergeFrom/WithOptimisticLock-2 137µs ± 4% 101µs ± 4% -26.28% (p=0.000 n=10+10) name old alloc/op new alloc/op delta MergeFrom/NoOptions 20.3kB ± 0% 20.3kB ± 0% ~ (all equal) MergeFrom/NoOptions-2 20.3kB ± 0% 20.3kB ± 0% ~ (all equal) MergeFrom/WithOptimisticLock 34.1kB ± 0% 26.7kB ± 0% -21.89% (p=0.000 n=10+10) MergeFrom/WithOptimisticLock-2 34.2kB ± 0% 26.7kB ± 0% -21.89% (p=0.000 n=10+8) name old allocs/op new allocs/op delta MergeFrom/NoOptions 359 ± 0% 359 ± 0% ~ (all equal) MergeFrom/NoOptions-2 359 ± 0% 359 ± 0% ~ (all equal) MergeFrom/WithOptimisticLock 579 ± 0% 390 ± 0% -32.64% (p=0.000 n=10+10) MergeFrom/WithOptimisticLock-2 579 ± 0% 390 ± 0% -32.64% (p=0.000 n=10+10) * ⚠ Change client.Patch to take client.Object This allows us to use metav1 accessors to speed up the merge-patch implementation.
* Upgrade to k/*@v0.21.1 in go.mod * [automated] make revendor for k/* dependencies This deletes pkg/mock/client-go/kubernetes/mocks.go to resolve the following deadlock: make revendor fails because of some dependencies of the file and make generate fails because of missing revendoring. File will be generated again in the next commit. * [automated] make generate for k/* dependencies * Upgrade to [email protected] in go.mod * [automated] make revendor for c-r dependency `make revendor` results in `hack/setup-envtest.sh` being broken, so reset the file after running `make revendor`. Adaption to breaking changes in the upstream file will be done in a later commit. * manager.NewClientBuilder was removed in favor of cluster.DefaultNewClient ref kubernetes-sigs/controller-runtime#1409 * client.*MergeFrom* now take client.Object instead of runtime.Object ref kubernetes-sigs/controller-runtime#1395 * [automated] make generate for c-r dependency * Adapt to changes in labels.NewRequirement ref kubernetes/kubernetes#97538 * Adapt to new setup-envtest tool Makes use of the new setup-envtest tool (kubernetes-sigs/controller-runtime#1488) in hack/setup-envtest.sh instead of vendoring hack/setup-envtest.sh and fetching binaries with that. * [automated] make revendor for setup-envtest tool * Adapt pkg/envtest to upstream changes - Make use of the new Users concept in envtest to provision a dedicated user for gardener-apiserver and a valid kubeconfig - Make use of the new way to configure API server args to easily configure kube-aggregator flags - Also generate certs for aggregation layer on our own instead of reusing the API server ca/certs (which is semantically correct), which allows us to drop our fork including kubernetes-sigs/controller-runtime#1449 * Styling nits
* Upgrade to k/*@v0.21.1 in go.mod * [automated] make revendor for k/* dependencies This deletes pkg/mock/client-go/kubernetes/mocks.go to resolve the following deadlock: make revendor fails because of some dependencies of the file and make generate fails because of missing revendoring. File will be generated again in the next commit. * [automated] make generate for k/* dependencies * Upgrade to [email protected] in go.mod * [automated] make revendor for c-r dependency `make revendor` results in `hack/setup-envtest.sh` being broken, so reset the file after running `make revendor`. Adaption to breaking changes in the upstream file will be done in a later commit. * manager.NewClientBuilder was removed in favor of cluster.DefaultNewClient ref kubernetes-sigs/controller-runtime#1409 * client.*MergeFrom* now take client.Object instead of runtime.Object ref kubernetes-sigs/controller-runtime#1395 * [automated] make generate for c-r dependency * Adapt to changes in labels.NewRequirement ref kubernetes/kubernetes#97538 * Adapt to new setup-envtest tool Makes use of the new setup-envtest tool (kubernetes-sigs/controller-runtime#1488) in hack/setup-envtest.sh instead of vendoring hack/setup-envtest.sh and fetching binaries with that. * [automated] make revendor for setup-envtest tool * Adapt pkg/envtest to upstream changes - Make use of the new Users concept in envtest to provision a dedicated user for gardener-apiserver and a valid kubeconfig - Make use of the new way to configure API server args to easily configure kube-aggregator flags - Also generate certs for aggregation layer on our own instead of reusing the API server ca/certs (which is semantically correct), which allows us to drop our fork including kubernetes-sigs/controller-runtime#1449 * Styling nits
Most uses of merge-patch will be for built-in types or kubebuilder-generated custom resources which have accessors for ResourceVersion. Using these with DeepCopyObject() is simple and fast.