diff --git a/flyteplugins/go/tasks/pluginmachinery/k8s/client.go b/flyteplugins/go/tasks/pluginmachinery/k8s/client.go index 79a81c7e79..f14ae2c8a0 100644 --- a/flyteplugins/go/tasks/pluginmachinery/k8s/client.go +++ b/flyteplugins/go/tasks/pluginmachinery/k8s/client.go @@ -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" @@ -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) } } @@ -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, } } @@ -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)