-
Notifications
You must be signed in to change notification settings - Fork 4k
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
refactor(*): move getKubeClient to utils/kubernetes #6180
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: qianlei90 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
c76fb3d
to
b9f636d
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.
/assign
Thanks for the change! Left some comments, let me know what you think.
) | ||
|
||
// GetKubeConfig returns the rest config from AutoscalingOptions. | ||
func GetKubeConfig(opts config.AutoscalingOptions) *rest.Config { |
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.
Passing all AutoscalingOptions
here seems like overkill for this: it only requires a few values. WDYT about moving all kube-client related fields to a dedicated struct and only passing that struct here? If it is necessary in AutoscalingOptions
, it can still be there.
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.
type AutoscalingOptions struct {
...
// Kubernetes master location.
Kubernetes string
// Path to kube configuration if available
KubeConfigPath string
// Content type of requests sent to APIServer.
KubeAPIContentType string
// Burst setting for kubernetes client
KubeClientBurst int
// QPS setting for kubernetes client
KubeClientQPS float64
...
}
Yeah I think it's very reasonable. How about moving these fields to a dedicated struct KubeClientOptions
in utils/kubernetes/client.go?
I want to create a kube client in cloudprovider(see #5820 (comment)) but buildCloudProvider
only accept AutoscalingOptions
:
func buildCloudProvider(opts config.AutoscalingOptions, do cloudprovider.NodeGroupDiscoveryOptions, rl *cloudprovider.ResourceLimiter) cloudprovider.CloudProvider { |
If we move kube-client releated fields and functions to utils/kubernetes/client.go, I'm wondering how to create kube client in cloudprovider.
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 think the struct should still live next to AutoscalingOptions
- this package has almost no dependencies and I'd like to keep it that way. Otherwise it would depend on the new file. (And transitively depend on anything else the new file imports.)
What I'm proposing is:
type AutoscalingOptions struct {
...
KubeClient KubeClientOptions
...
}
type KubeClientOptions struct {
// Kubernetes master location.
Kubernetes string
// Path to kube configuration if available
KubeConfigPath string
// Content type of requests sent to APIServer.
ContentType string
// Burst setting for kubernetes client
BurstLimit int
// QPS setting for kubernetes client
QPSLimit float64
}
And then in the new package:
package client
...
func New(opts config.KubeClientOptions) kube_client.Interface {
...
}
With that, given AutoscalingOptions
, you can still use the new utils to create kube client. Does that make sense?
@@ -455,7 +430,7 @@ func buildAutoscaler(debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter | |||
} | |||
informerFactory := informers.NewSharedInformerFactoryWithOptions(kubeClient, 0, informers.WithTransform(trim)) | |||
|
|||
eventsKubeClient := createKubeClient(getKubeConfig()) | |||
eventsKubeClient := createKubeClient(kube_util.GetKubeConfig(autoscalingOptions)) |
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.
Is KubeConfig
abstraction needed at all in main? Can the entire client creation be moved to a dedicated package?
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.
Is KubeConfig abstraction needed at all in main?
Yes. Releated fields and getKubeConfig
、createKubeClient
now are only used in main.go
. I do this refactor because I want to reuse these functions in cloudprovider.
Can the entire client creation be moved to a dedicated package?
I think Yes.
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.
Ack, in this case let's move both kube config and client creation to the util package, so main will be able to create client directly and kube config you'll be able to reuse in cloudprovider.
@qianlei90 any updates on this? I wanted to include changes in this PR in #5820. Since this is related to the kwok provider PR, I can help with the changes if you want. Other options I am thinking of:
Let me know what you think. |
@qianlei90 wanted to remind you about #6180 (comment) |
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Seems like @qianlei90 might not be available to work on this. |
Yup, makes sense. If you are going to follow up separately, I'll just close this one. Please assign me to the follow-up PR once it exists. /close |
@x13n: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
move getKubeClient to
utils/kubernetes
and make this function public.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: