Skip to content
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

Merged
merged 1 commit into from
Jun 21, 2023

Conversation

nojnhuh
Copy link
Contributor

@nojnhuh nojnhuh commented Jun 15, 2023

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 into Unstructured to construct a ConfigOwner.

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

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 15, 2023
Namespace: metav1.NamespaceDefault,
Labels: map[string]string{
clusterv1.MachineControlPlaneLabel: "",
doTests := func(t *testing.T, getFn func(context.Context, client.Client, metav1.Object) (*ConfigOwner, error)) {
Copy link
Contributor Author

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.

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Jun 15, 2023

@fabriziopandini Please let me know if there's any specific testing I can do to show what kind of performance impact this has.

Copy link
Member

@fabriziopandini fabriziopandini left a 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?

@@ -125,6 +127,16 @@ func (co ConfigOwner) KubernetesVersion() string {

// GetConfigOwner returns the Unstructured object owning the current resource.
Copy link
Member

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

Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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.

Comment on lines 184 to 185
// GetOwnerByRefCached finds and returns the owner by looking at the object
// reference. It may return a cached object.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about

Suggested change
// 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.

Comment on lines 133 to 135
// 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

Suggested change
// 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) {

@sbueringer
Copy link
Member

lgtm pending the godoc nits

@sbueringer
Copy link
Member

sbueringer commented Jun 20, 2023

@fabriziopandini Please let me know if there's any specific testing I can do to show what kind of performance impact this has.

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.

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Jun 20, 2023

Sorry for the extra force-push, almost forgot to update the function name in the migration doc. All feedback should be addressed now.

@sbueringer
Copy link
Member

Thank you very much!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 21, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 108045f494f20d713ee38a44c73e84675199917c

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 21, 2023
@k8s-ci-robot k8s-ci-robot merged commit 869676f into kubernetes-sigs:main Jun 21, 2023
20 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.5 milestone Jun 21, 2023
@sbueringer sbueringer mentioned this pull request Jun 23, 2023
27 tasks
Copy link
Contributor

@killianmuldoon killianmuldoon left a 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

@k8s-ci-robot k8s-ci-robot added the area/provider/bootstrap-kubeadm Issues or PRs related to CAPBK label Jun 27, 2023
@nojnhuh nojnhuh deleted the cached-get-config-owner branch February 18, 2024 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/provider/bootstrap-kubeadm Issues or PRs related to CAPBK cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use cache for GetConfigOwner in CABPK
5 participants