From 2de1ea9769bc5832d2608f589859b6839a4265bd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 4 Sep 2025 18:53:06 +0200 Subject: [PATCH] cli/context/docker: don't wrap client options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We may still change this, but in the client module, the signature of the client.Opt changed to now include a non-exported type, which means that we can't construct a custom option that is implemented using client options: #18 16.94 # github.com/docker/cli/cli/context/docker #18 16.94 cli/context/docker/load.go:105:29: cannot use withHTTPClient(tlsConfig) (value of type func(*client.Client) error) as client.Opt value in argument to append #18 16.94 cli/context/docker/load.go:152:6: cannot use c (variable of type *client.Client) as *client.clientConfig value in argument to client.WithHTTPClient(&http.Client{…}) We can consider exporting the `client.clientConfig` type (but keep its fields non-exported), but for this use, we don't strictly need it, so let's change the implementation to not having to depend on that. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit b0b0e457f0555f41229d392975e4969c02b0f3c4) Signed-off-by: Sebastiaan van Stijn --- cli/context/docker/load.go | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/cli/context/docker/load.go b/cli/context/docker/load.go index 89d43e2e32..e37ee4646d 100644 --- a/cli/context/docker/load.go +++ b/cli/context/docker/load.go @@ -101,7 +101,22 @@ func (ep *Endpoint) ClientOpts() ([]client.Opt, error) { if err != nil { return nil, err } - result = append(result, withHTTPClient(tlsConfig)) + + // If there's no tlsConfig available, we use the default HTTPClient. + if tlsConfig != nil { + result = append(result, + client.WithHTTPClient(&http.Client{ + Transport: &http.Transport{ + TLSClientConfig: tlsConfig, + DialContext: (&net.Dialer{ + KeepAlive: 30 * time.Second, + Timeout: 30 * time.Second, + }).DialContext, + }, + CheckRedirect: client.CheckRedirect, + }), + ) + } } result = append(result, client.WithHost(ep.Host)) } else { @@ -133,25 +148,6 @@ func isSocket(addr string) bool { } } -func withHTTPClient(tlsConfig *tls.Config) func(*client.Client) error { - return func(c *client.Client) error { - if tlsConfig == nil { - // Use the default HTTPClient - return nil - } - return client.WithHTTPClient(&http.Client{ - Transport: &http.Transport{ - TLSClientConfig: tlsConfig, - DialContext: (&net.Dialer{ - KeepAlive: 30 * time.Second, - Timeout: 30 * time.Second, - }).DialContext, - }, - CheckRedirect: client.CheckRedirect, - })(c) - } -} - // EndpointFromContext parses a context docker endpoint metadata into a typed EndpointMeta structure func EndpointFromContext(metadata store.Metadata) (EndpointMeta, error) { ep, ok := metadata.Endpoints[DockerEndpoint]