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 and provide a single dynamic rest mapper #2296

Merged
merged 1 commit into from
May 4, 2023

Conversation

vincepri
Copy link
Member

@vincepri vincepri commented May 2, 2023

No description provided.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 2, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

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 requested a review from FillZpp May 2, 2023 18:37
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 2, 2023
@sbueringer
Copy link
Member

Didn't see the test failure before but looks unrelated

/test pull-controller-runtime-test

Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

one nit, up to you

pkg/client/apiutil/restmapper.go Outdated Show resolved Hide resolved
@sbueringer
Copy link
Member

/retest

@vincepri vincepri force-pushed the restmapper-one branch 3 times, most recently from 6ac8b0c to 98137e8 Compare May 3, 2023 14:17
@vincepri
Copy link
Member Author

vincepri commented May 3, 2023

/retest

@vincepri vincepri force-pushed the restmapper-one branch 3 times, most recently from 651fe09 to 98d420f Compare May 3, 2023 15:14
pkg/client/apiutil/restmapper.go Outdated Show resolved Hide resolved
pkg/client/apiutil/restmapper.go Outdated Show resolved Hide resolved
pkg/client/apiutil/restmapper.go Outdated Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

@vincepri: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-controller-runtime-apidiff 935faeb link false /test pull-controller-runtime-apidiff

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.

@sbueringer
Copy link
Member

sbueringer commented May 4, 2023

/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 May 4, 2023
@k8s-ci-robot k8s-ci-robot merged commit 57674c8 into kubernetes-sigs:main May 4, 2023
chlunde added a commit to sparebank1utvikling/provider-kubernetes that referenced this pull request May 8, 2023
provider-kubernetes initialized a new kubernetes client for each
reconcile. The REST mapper in controller-runtime used to fetch
information about every CRD in the cluster.

controller-runtime introduced a lazy restmapper which means we don't
have to introduce any complex caching to get a significant performance
boost in provider-kubernetes:

kubernetes-sigs/controller-runtime#2116

This seems to become the default in the next release:

kubernetes-sigs/controller-runtime#2296

But this is so significant that we want to update now:

* CPU reduced from constant throttling at 0.4 cores to 0.04 cores

* CloudWatch / EKS audit log costs reduced significantly (55% for our
  cluster, with a lot of provider-kubernetes resources)

Signed-off-by: Carl Henrik Lunde <[email protected]>
chlunde added a commit to sparebank1utvikling/provider-kubernetes that referenced this pull request May 8, 2023
provider-kubernetes initialized a new kubernetes client for each
reconcile. The REST mapper in controller-runtime used to fetch
information about every CRD in the cluster.

controller-runtime introduced a lazy restmapper which means we don't
have to introduce any complex caching to get a significant performance
boost in provider-kubernetes:

kubernetes-sigs/controller-runtime#2116

This seems to become the default in the next release:

kubernetes-sigs/controller-runtime#2296

But this is so significant that we want to update now:

* CPU reduced from constant throttling at 0.4 cores to 0.04 cores

* CloudWatch / EKS audit log costs reduced significantly (55% for our
  cluster, with a lot of provider-kubernetes resources)

Signed-off-by: Carl Henrik Lunde <[email protected]>
harshanarayana added a commit to harshanarayana/e2e-framework that referenced this pull request Jun 17, 2023
New changes done to the controller-runtime to make the rest mapper
truly lazy in nature now means that the connection is never really
validated until the first connection is made. So the current test is
basically of no use anymore. Cleaning them up.

xref: kubernetes-sigs/controller-runtime#2296
chlunde added a commit to sparebank1utvikling/provider-kubernetes that referenced this pull request Jun 26, 2023
provider-kubernetes initialized a new kubernetes client for each
reconcile. The REST mapper in controller-runtime used to fetch
information about every CRD in the cluster.

controller-runtime introduced a lazy restmapper which means we don't
have to introduce any complex caching to get a significant performance
boost in provider-kubernetes:

kubernetes-sigs/controller-runtime#2116

This seems to become the default in the next release:

kubernetes-sigs/controller-runtime#2296

But this is so significant that we want to update now:

* CPU reduced from constant throttling at 0.4 cores to 0.04 cores

* CloudWatch / EKS audit log costs reduced significantly (55% for our
  cluster, with a lot of provider-kubernetes resources)

Signed-off-by: Carl Henrik Lunde <[email protected]>
@RainbowMango
Copy link
Member

@vincepri May I ask the background of this PR?

Why removed the following options: WithCustomMapper, WithExperimentalLazyMapper, WithLazyDiscovery, and WithLimiter?

@vincepri
Copy link
Member Author

vincepri commented Jul 5, 2023

@RainbowMango The options were either outdated, or provided no meaningful additions. Folks can always use their own RESTMapper implementation if they need. For the majority of controller-runtime users, having a single implementation is less error prone.

matrus2 pushed a commit to matrus2/e2e-framework that referenced this pull request Jul 10, 2023
New changes done to the controller-runtime to make the rest mapper
truly lazy in nature now means that the connection is never really
validated until the first connection is made. So the current test is
basically of no use anymore. Cleaning them up.

xref: kubernetes-sigs/controller-runtime#2296
@RainbowMango
Copy link
Member

Hi @vincepri,
We built a cached restmapper based on the DynamicRESTMapper of [email protected], the cached restmapper simply maintains a map which records the recent match result, and the map will be reset if the DiscoveryRESTMapper needs a reload.
We did that by the WithCustomMapper before, but during the bump to v0.15, we can't use it anymore.

Do you have any suggestions about how we can adopt the breaking change?
Or, is it possible to add the WithCustomMapper back to the upcoming release?

PS:
The background why we need the cahced restmapper is all about the performance, the underlying Kubernetes DiscoveryRESTMapper caches the resource with a slice, which performance is not good comparing with map.
We did a benchmark after that:

# go test -bench=. 
goos: linux
goarch: amd64
pkg: github.com/karmada-io/karmada/pkg/util/restmapper
cpu: Intel(R) Xeon(R) Gold 6278C CPU @ 2.60GHz
BenchmarkGetGroupVersionResource-4            	   52779	     20799 ns/op
BenchmarkGetGroupVersionResourceWithCache-4   	  245550	      4754 ns/op   // cached restmapper
PASS
ok  	github.com/karmada-io/karmada/pkg/util/restmapper	2.574s

The performance of cached restmapper had improved significantly.

@vincepri
Copy link
Member Author

@RainbowMango Overriding the RESTMapper implementation in the manager is still possible with

// MapperProvider provides the rest mapper used to map go types to Kubernetes APIs.
//
// If set, the RESTMapper returned by this function is used to create the RESTMapper
// used by the Client and Cache.
MapperProvider func(c *rest.Config, httpClient *http.Client) (meta.RESTMapper, error)

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. 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants