-
Notifications
You must be signed in to change notification settings - Fork 702
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 typed client to plugin client getter. #3043
Conversation
} | ||
typedClient, err := kubernetes.NewForConfig(config) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("unable to create typed client: %w", err) |
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.
Main change here (other than adding the new client) was just to DRY up the code for creating a client (or clients).
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.
Great, thanks for adding it. I initially thought of adding a clientGetter for each type, sth like "clientGetter" and "dynamicClientGetter", but returning both clients is better (assuming there are no more clients out there)
@@ -51,6 +48,9 @@ const ( | |||
clustersCAFilesPrefix = "/etc/additional-clusters-cafiles" | |||
) | |||
|
|||
// KubernetesClientGetter is a function type used by plugins to get a k8s client | |||
type KubernetesClientGetter func(context.Context) (kubernetes.Interface, dynamic.Interface, error) |
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.
Created this type alias so its easier to update the signature (before I added the typed interface).
if tc.statusCode == codes.OK { | ||
if _, ok := client.(dynamic.Interface); !ok { |
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 sure why I initially used a type conversion here, since if it's non-nil, it's going to be the correct type (or it wouldn't compile).
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.
Thanks for jumping in adding the client getter. It's interesting the amount of PRs that are required for a simple listing packages operation. Step by step :)
I'll land this PR and modify mine accordingly (happy to get rid of the from/to structured)
Description of the change
As per discussion on #3022, we originally tried the typed client for interacting with packaging CRs but hit the issue that we'd need the same version of client-go used by those packaging systems, which leads to dependency hell. So we switched to use a dynamic client for the plugins.
That said, now that certain plugins also need to interact with the core k8s api resources, a typed client(set) would also be useful (and nicer to work with) for interacting with those core resources.
This PR updates so that plugins are provided with both - a type clientset and a dynamic clientset.
Benefits
Plugins don't need to use unstructured objects when interacting with the core k8s resources.
Possible drawbacks
None (assuming the client works IRL, which we'll test in a subsequent PR that uses the typed client for the direct helm plugin).
Applicable issues
Additional information
Antonio, if you want to land this so you can use it in your PR, that's fine, or if you'd rather not depend on it but move forward with your unstructured work-around and switch later, that's fine too :)