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

✨ Add DryRunClient wrapper #839

Merged
merged 2 commits into from
Apr 17, 2020

Conversation

alvaroaleman
Copy link
Member

This PR adds a DryRunClient wrapper that enforced DryRun on all mutating operations and plugs that into the client and manager constructors. This is useful to check what a controller does in a production environment without actually doing it.

Fixes #831

@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 Mar 5, 2020
Copy link
Contributor

@djzager djzager left a comment

Choose a reason for hiding this comment

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

Nice work.

kscheme "k8s.io/client-go/kubernetes/scheme"

"sigs.k8s.io/controller-runtime/pkg/client"
Copy link
Contributor

Choose a reason for hiding this comment

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

Only curious because it looks intentional and not the kind of thing I would expect gofmt to do. Why this change?

Copy link
Member Author

@alvaroaleman alvaroaleman Mar 6, 2020

Choose a reason for hiding this comment

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

Because we usually put imports from our own repo in a dedicated group, rather than mixing them with other imports in a common group

pkg/client/dryrun_test.go Show resolved Hide resolved
pkg/client/dryrun_test.go Outdated Show resolved Hide resolved
pkg/client/dryrun_test.go Outdated Show resolved Hide resolved
@alvaroaleman
Copy link
Member Author

/assign @DirectXMan12

@@ -37,6 +37,9 @@ type Options struct {

// Mapper, if provided, will be used to map GroupVersionKinds to Resources
Mapper meta.RESTMapper

// DryRun specifies whether dry run mode should be enforced
DryRun bool
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the main usecase for having this as an option here vs just letting people call NewDryRunClient? Just want to avoid too many options here, esp since this isn't strictly related to creating the client

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, its not really necessary there, I removed it.

I would like to keep it in the manager though, because the defaultNewClient is not exported and replacing the NewClient func is not very intuitive and an option ppl that are not deeply familiar with c-r will most likely not become aware of. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Not super excited about growing manager's Options.

One alternative we can try here is that:
Making defaultNewClient exportable, but under pkg/manager/internal or pkg/internal/manager or some place similar.
Then you can have a helper method that satisfy NewClientFunc

func NewDryRunClientFn(cache cache.Cache, config *rest.Config, options client.Options) (client.Client, error) {
  cl, err := managerinternal.DefaultNewClient(cache, config, options) 
  return &dryRunClient{cl}, err
}

User can pass this method to manager Options.

@DirectXMan12 Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

@mengqiy the reason I dislike that is that its pretty hard to discover that these kind of build-in opts exists

@alvaroaleman
Copy link
Member Author

/assign @DirectXMan12
Could you have another look, please?

@vincepri vincepri added this to the v0.5.x milestone Mar 26, 2020
@alvaroaleman
Copy link
Member Author

@DirectXMan12 any chance you can have a look?

@DirectXMan12
Copy link
Contributor

hey, sorry for the lag

/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 Apr 17, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, DirectXMan12

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 Apr 17, 2020
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 17, 2020
@alvaroaleman
Copy link
Member Author

@DirectXMan12 could you give a new lgtm as I had to rebase?

@djzager
Copy link
Contributor

djzager commented Apr 17, 2020

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 17, 2020
@k8s-ci-robot k8s-ci-robot merged commit 6016987 into kubernetes-sigs:master Apr 17, 2020
@DirectXMan12
Copy link
Contributor

FWIW, I'd love to eventually figure out how to make it easy to sub in the dryrun client instead of needing an option on manager, but I don't really think I want to block on that now

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

Add DryRun option to the client
6 participants