-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
✨ Use caching read for bootstrap config owner #8867
✨ Use caching read for bootstrap config owner #8867
Conversation
Namespace: metav1.NamespaceDefault, | ||
Labels: map[string]string{ | ||
clusterv1.MachineControlPlaneLabel: "", | ||
doTests := func(t *testing.T, getFn func(context.Context, client.Client, metav1.Object) (*ConfigOwner, error)) { |
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.
Most of the test changes here are indentation-related, so I recommend ticking the "hide whitespace" checkbox.
@fabriziopandini Please let me know if there's any specific testing I can do to show what kind of performance impact this has. |
5a71226
to
06e8903
Compare
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.
Thanks for implementing this PR, just a couple of nits from my side.
Also, what about adding a note about the introduction of the new function in the 1.4 -> 1.5 migration notes?
bootstrap/util/configowner.go
Outdated
@@ -125,6 +127,16 @@ func (co ConfigOwner) KubernetesVersion() string { | |||
|
|||
// GetConfigOwner returns the Unstructured object owning the current resource. |
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.
I would add a warning that this can impact performance at scale because it reads unstructured objects which are not cached
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.
Should we deprecate this func?
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.
I would say not without knowing why me made this public, I assume because someone asked for it from providers
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.
Looks like there is one usage in the CAPA controller: https://cs.k8s.io/?q=GetConfigOwner&i=nope&files=&excludeFiles=&repos=
I don't know if they intentionally use the version which triggers an uncached call.
But definitely fine for me to not deprecate in this PR to get the improvement in ASAP.
bootstrap/util/configowner.go
Outdated
// GetOwnerByRefCached finds and returns the owner by looking at the object | ||
// reference. It may return a cached object. |
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.
what about
// GetOwnerByRefCached finds and returns the owner by looking at the object | |
// reference. It may return a cached object. | |
// GetOwnerByRefFromCache finds and returns the owner by looking at the object | |
// reference. The implementation ensures a typed client is used, so the objects are read from the cache. |
bootstrap/util/configowner.go
Outdated
// GetConfigOwnerCached returns the Unstructured object owning the current | ||
// resource, which may come from a cache. | ||
func GetConfigOwnerCached(ctx context.Context, c client.Client, obj metav1.Object) (*ConfigOwner, error) { |
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.
What about
// GetConfigOwnerCached returns the Unstructured object owning the current | |
// resource, which may come from a cache. | |
func GetConfigOwnerCached(ctx context.Context, c client.Client, obj metav1.Object) (*ConfigOwner, error) { | |
// GetConfigOwnerCached returns the Unstructured object owning the current | |
// resource. The implementation ensures a typed client is used, so the objects are read from the cache. | |
func GetConfigOwnerFromCache(ctx context.Context, c client.Client, obj metav1.Object) (*ConfigOwner, error) { |
lgtm pending the godoc nits |
I think our scale testing is not in a state yet to just say please rerun those tests and you can see the improvement based on this data. But based on some other changes we made we know that using the cache is a lot more performant than calls against the apiserver. I'll include this PR/commit in the scale testing I'm currently doing locally. |
06e8903
to
f6777ab
Compare
f6777ab
to
426d2ad
Compare
Sorry for the extra force-push, almost forgot to update the function name in the migration doc. All feedback should be addressed now. |
Thank you very much! /lgtm |
LGTM label has been added. Git tree hash: 108045f494f20d713ee38a44c73e84675199917c
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sbueringer 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 |
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.
/area provider/bootstrap-kubeadm
What this PR does / why we need it: This PR makes the lookup of the KubeadmConfig's owner use a cached client instead of the uncached unstructured client. To make the rest of the adjacent plumbing reusable, the new typed read by
GetOwnerByRefCached
converts the object intoUnstructured
to construct aConfigOwner
.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #8849
/cc @fabriziopandini