Skip to content

Commit 2de1ea9

Browse files
committed
cli/context/docker: don't wrap client options
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 <[email protected]> (cherry picked from commit b0b0e45) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 0ac676b commit 2de1ea9

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

cli/context/docker/load.go

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,22 @@ func (ep *Endpoint) ClientOpts() ([]client.Opt, error) {
101101
if err != nil {
102102
return nil, err
103103
}
104-
result = append(result, withHTTPClient(tlsConfig))
104+
105+
// If there's no tlsConfig available, we use the default HTTPClient.
106+
if tlsConfig != nil {
107+
result = append(result,
108+
client.WithHTTPClient(&http.Client{
109+
Transport: &http.Transport{
110+
TLSClientConfig: tlsConfig,
111+
DialContext: (&net.Dialer{
112+
KeepAlive: 30 * time.Second,
113+
Timeout: 30 * time.Second,
114+
}).DialContext,
115+
},
116+
CheckRedirect: client.CheckRedirect,
117+
}),
118+
)
119+
}
105120
}
106121
result = append(result, client.WithHost(ep.Host))
107122
} else {
@@ -133,25 +148,6 @@ func isSocket(addr string) bool {
133148
}
134149
}
135150

136-
func withHTTPClient(tlsConfig *tls.Config) func(*client.Client) error {
137-
return func(c *client.Client) error {
138-
if tlsConfig == nil {
139-
// Use the default HTTPClient
140-
return nil
141-
}
142-
return client.WithHTTPClient(&http.Client{
143-
Transport: &http.Transport{
144-
TLSClientConfig: tlsConfig,
145-
DialContext: (&net.Dialer{
146-
KeepAlive: 30 * time.Second,
147-
Timeout: 30 * time.Second,
148-
}).DialContext,
149-
},
150-
CheckRedirect: client.CheckRedirect,
151-
})(c)
152-
}
153-
}
154-
155151
// EndpointFromContext parses a context docker endpoint metadata into a typed EndpointMeta structure
156152
func EndpointFromContext(metadata store.Metadata) (EndpointMeta, error) {
157153
ep, ok := metadata.Endpoints[DockerEndpoint]

0 commit comments

Comments
 (0)