Skip to content

Commit

Permalink
Avoid to use the http.DefaultClient (#4667)
Browse files Browse the repository at this point in the history
* Avoid to use the http.DefaultClient

Signed-off-by: Andres Gomez Ferrer <[email protected]>

* Add httpClient to ClientOptions

Signed-off-by: Andres Gomez Ferrer <[email protected]>

---------

Signed-off-by: Andres Gomez Ferrer <[email protected]>
  • Loading branch information
andresgomezfrr authored Jan 3, 2024
1 parent ba10600 commit a726c36
Showing 1 changed file with 11 additions and 5 deletions.
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)
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,
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

0 comments on commit a726c36

Please sign in to comment.