-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
✨ Add DryRunClient wrapper #839
Conversation
c6fce28
to
535b63c
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.
Nice work.
kscheme "k8s.io/client-go/kubernetes/scheme" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" |
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.
Only curious because it looks intentional and not the kind of thing I would expect gofmt
to do. Why this change?
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.
Because we usually put imports from our own repo in a dedicated group, rather than mixing them with other imports in a common group
535b63c
to
9fc31ad
Compare
9fc31ad
to
6981b0a
Compare
/assign @DirectXMan12 |
pkg/client/client.go
Outdated
@@ -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 |
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'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
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.
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?
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.
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?
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.
@mengqiy the reason I dislike that is that its pretty hard to discover that these kind of build-in opts exists
6981b0a
to
e5ce18f
Compare
/assign @DirectXMan12 |
@DirectXMan12 any chance you can have a look? |
hey, sorry for the lag /lgtm |
[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 |
e5ce18f
to
626063b
Compare
@DirectXMan12 could you give a new lgtm as I had to rebase? |
/lgtm |
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 |
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