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

Avoid to use the http.DefaultClient #4667

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions flyteplugins/go/tasks/pluginmachinery/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
package k8s

import (
"net/http"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/cache"
Expand Down Expand Up @@ -40,9 +38,14 @@ type Options struct {
// NewKubeClient creates a new KubeClient that caches reads and falls back to
// make API calls on failure. Write calls are not cached.
func NewKubeClient(config *rest.Config, options Options) (core.KubeClient, error) {
httpClient, err := rest.HTTPClientFor(config)
Copy link
Member

Choose a reason for hiding this comment

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

A question. We used to have three different http clients for different purposes, and now we will only have one. Do you know the implication, or do you prefer we still have three? @eapolinario

Copy link
Member

Choose a reason for hiding this comment

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

To be clear, I don't see why we would need three different struct instances given the config is the same.

Copy link
Member

Choose a reason for hiding this comment

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

// The Client's Transport typically has internal state (cached TCP
// connections), so Clients should be reused instead of created as
// needed. Clients are safe for concurrent use by multiple goroutines.

Copy link
Member

Choose a reason for hiding this comment

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

I think this was the PR kubernetes-sigs/controller-runtime#2122, which carried exactly the same rationale.

if err != nil {
return nil, err
}

if options.MapperProvider == nil {
options.MapperProvider = func(c *rest.Config) (meta.RESTMapper, error) {
return apiutil.NewDynamicRESTMapper(config, http.DefaultClient)
return apiutil.NewDynamicRESTMapper(config, httpClient)
}
}

Expand All @@ -53,7 +56,7 @@ func NewKubeClient(config *rest.Config, options Options) (core.KubeClient, error

if options.CacheOptions == nil {
options.CacheOptions = &cache.Options{
HTTPClient: http.DefaultClient,
HTTPClient: httpClient,
andresgomezfrr marked this conversation as resolved.
Show resolved Hide resolved
Mapper: mapper,
}
}
Expand All @@ -64,7 +67,10 @@ func NewKubeClient(config *rest.Config, options Options) (core.KubeClient, error
}

if options.ClientOptions == nil {
options.ClientOptions = &client.Options{Mapper: mapper}
options.ClientOptions = &client.Options{
HTTPClient: httpClient,
Mapper: mapper,
}
}

client, err := client.New(config, *options.ClientOptions)
Expand Down
Loading