From a4f3ea85304683b87f857dd20b2481bcd886f06d Mon Sep 17 00:00:00 2001 From: Andres Gomez Ferrer Date: Wed, 3 Jan 2024 14:29:09 +0100 Subject: [PATCH 1/2] Avoid to use the http.DefaultClient Signed-off-by: Andres Gomez Ferrer --- flyteplugins/go/tasks/pluginmachinery/k8s/client.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/flyteplugins/go/tasks/pluginmachinery/k8s/client.go b/flyteplugins/go/tasks/pluginmachinery/k8s/client.go index 79a81c7e79..5eb53976f5 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, } } From 32d1c3504236c986961f29798ad8e6c0f1ebf7f2 Mon Sep 17 00:00:00 2001 From: Andres Gomez Ferrer Date: Wed, 3 Jan 2024 15:40:28 +0100 Subject: [PATCH 2/2] Add httpClient to ClientOptions Signed-off-by: Andres Gomez Ferrer --- flyteplugins/go/tasks/pluginmachinery/k8s/client.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flyteplugins/go/tasks/pluginmachinery/k8s/client.go b/flyteplugins/go/tasks/pluginmachinery/k8s/client.go index 5eb53976f5..f14ae2c8a0 100644 --- a/flyteplugins/go/tasks/pluginmachinery/k8s/client.go +++ b/flyteplugins/go/tasks/pluginmachinery/k8s/client.go @@ -67,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)