-
Notifications
You must be signed in to change notification settings - Fork 55
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
Impersonation client #39
Conversation
This commit contains simple code clean up. By Adding comments to the Client struct. As well as basic unit test to verify REST API calls. This commit also removed the timeout parameter from the private function setupCtx(...) since all callers of the function passed in the same '0 argument.
3ef6054
to
e392bf3
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.
I like the general pattern, and think that making this more generic was a smart move. Good job on that.
Thank you for adding comments as well.
Two overall suggestions:
- I'd recommend for allowing for more than one mutator. I've left a comment on the client about this (would also apply to the controllers) and what it would look like. It does change the exported functions here, so I'm open to discussion on if that is useful or not.
- In the future (probably not part of this PR), we should consider using code-gen/generics so that each new mutator doesn't result in changes to clientMutator and controllerMutator to expose the new
NewSharedFactoryWithMutator
option. We don't have to do this here, but it's something to think about.
e392bf3
to
07398ea
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.
Actual code LGTM. Have a couple of comments (mostly nits) on the tests.
Non-nit test comments:
- We should probably test
WithAgent
andWithImpersonation
on the client directly, particularly since we can access the config and need to assert that it's not overwriting the previously-set options afterwards - The tests for
Watch
ignore thewatch.Interface
return. Since this is the part that is actually returning objects to us, I think we should make some type of test/assertion which accounts for it.
07398ea
to
9641c92
Compare
fe359d7
to
f04e680
Compare
f04e680
to
693b2d0
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.
I remember you mentioning this idea:
SharedControllerWithMutator mutates the client once on construction and returns the stored client with every call to Client() instead of generating a new client everytime to mimick the same behavior of SharedController.
but I don't think I see it implemented anywhere, am I missing something?
pkg/client/clientMutator.go
Outdated
"k8s.io/client-go/rest" | ||
) | ||
|
||
// Mutator is function that takes in a client and returns an new mutated 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.
// Mutator is function that takes in a client and returns an new mutated client. | |
// Mutator is function that takes in a client and returns a new mutated client. |
@rmweir Originally, I had added mutators and impersonation to the SharedControllerFactory but ultimately decided against it, so I left the code that creates a new client as is. I decided not to add impersonation to the Controllers because in practice we would not want an end user to create a ControllerFactory with impersonation. Instead, we would want to keep it scoped to the client level for one-off situations. |
This commit allows users to create a client with a impersonation config which then is applied to all request sent from that client. Users can also create a new controller and controllerFactory to use impersonation as well.
693b2d0
to
f9f8599
Compare
Add a
WithImpersonation
option for clients that allows users to get a client set up for impersonation.Notable Changes
Mutators
to reduce duplicate code for controllers and factories.user_agent
test code was not deleted but moved into mutator_test.goWithAgent
andWithImpersonation
now update the returned config so that both options can be used together.SharedControllerWithMutator
mutates the client once on construction and returns the stored client with every call toClient()
instead of generating a new client everytime to mimick the same behavior ofSharedController
.