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

⚠️ Remove use of apiutil.NewDynamicRESTMapper #2329

Merged
merged 1 commit into from
Feb 19, 2020

Conversation

detiber
Copy link
Member

@detiber detiber commented Feb 13, 2020

What this PR does / why we need it:

Since we are now using controller-runtime v0.5.0 we no longer need
to override the default restmapper when initializing a controller-runtime
client because the dynamic restmapper is now the default.

This does change some of the semantics of how we are interacting with clients where we were previously setting WithLazyDiscovery, but those changes should be limited just to the ability to get a client for a not-yet-ready remote server.

/assign @vincepri

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 13, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: detiber

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 Feb 13, 2020
if err != nil {
return nil, errors.Wrapf(err, "failed to create a DynamicRESTMapper for Cluster %s/%s", cluster.Namespace, cluster.Name)
}
ret, err := client.New(restConfig, client.Options{Scheme: scheme, Mapper: mapper})
Copy link
Member Author

Choose a reason for hiding this comment

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

This is causing the test failure because the test is trying to verify a non-error result from NewClusterClient, which currently wouldn't happen due to the test not providing a server for the client to connect to.

Do we have a need for a long lived remote client that would necessitate lazy discovery? I'm not sure we do.

return nil, errors.Wrapf(err, "failed to create the controller-runtime DynamicRESTMapper")
}

c, err := client.New(config, client.Options{Scheme: Scheme, Mapper: mapper})
Copy link
Member Author

Choose a reason for hiding this comment

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

@fabriziopandini is this proxy client a long lived client within clusterctl that would require the client to be setup and configured prior to the remote server listening? If not, then I think we can get away without lazy discovery and use the default controller-runtime client mapper.

Copy link
Member

Choose a reason for hiding this comment

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

This client is used in many places, usually short-lived.
However, there are places like e.g. when installing cert-manager, where we create CRDs and immediately after we check for the CRDs to be available, and without the NewDynamicRESTMapper the client was not able to detect the new type (no matter if creating a new client or not)

Copy link
Member Author

Choose a reason for hiding this comment

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

@fabriziopandini with the version of controller-runtime that we updated to use of the Dynamic REST Mapper is now the default. The behavior change introduced here is removal of the lazy discovery (which should only be needed if we absolutely need to be able to create a client before the server is available).

Copy link
Contributor

@chuckha chuckha left a comment

Choose a reason for hiding this comment

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

The title of this PR is a little misleading as it is also changing the semantics of the code. In 2/3 places WithLazyDiscovery is being removed. I'm +1 on removing the NewDynamicRESTMapper in test/framework/management/kind/mgmt.go since the semantics don't change, but the other two look to intentionally be using WithLazyDiscovery.

I'd suggest either opening an issue to get feedback or rephrasing the title of the PR and using ⚠️ instead of 🏃 since it's very likely fine to remove the WithLazyDiscovery anyway.

@detiber detiber changed the title 🏃 Remove use of apiutil.NewDynamicRESTMapper [WIP] ⚠️ Remove use of apiutil.NewDynamicRESTMapper Feb 14, 2020
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 14, 2020
@vincepri
Copy link
Member

/retest

@vincepri
Copy link
Member

/milestone v0.3.0-rc.1

@k8s-ci-robot k8s-ci-robot added this to the v0.3.0-rc.1 milestone Feb 16, 2020
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 18, 2020
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 18, 2020
@detiber detiber changed the title [WIP] ⚠️ Remove use of apiutil.NewDynamicRESTMapper ⚠️ Remove use of apiutil.NewDynamicRESTMapper Feb 19, 2020
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 19, 2020
@vincepri
Copy link
Member

This PR needs documentation about the API removal in https://master.cluster-api.sigs.k8s.io/developer/providers/v1alpha2-to-v1alpha3.html

@detiber
Copy link
Member Author

detiber commented Feb 19, 2020

@vincepri added a statement to the doc for the remote client change. Other changes are net new for v1alpha3 anyway.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 19, 2020
Since we are now using controller-runtime v0.5.0 we no longer need
to override the default restmapper when initializing a controller-runtime
client because the dynamic restmapper is now the default.
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 19, 2020
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 19, 2020
@k8s-ci-robot k8s-ci-robot merged commit a81c040 into kubernetes-sigs:master Feb 19, 2020
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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants