Skip to content

Commit 05bbb2e

Browse files
committed
Use custom request from upstream moby
Signed-off-by: Mathieu Champlon <mathieu.champlon@docker.com>
1 parent 0bf781e commit 05bbb2e

4 files changed

Lines changed: 38 additions & 34 deletions

File tree

cli/command/cli.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
174174
DefaultVersion: cli.client.ClientVersion(),
175175
HasExperimental: hasExperimental,
176176
Orchestrator: orchestrator,
177-
TLSOptions: opts.Common.TLSOptions,
178177
}
179178
cli.initializeFromClient()
180179
return nil
@@ -241,7 +240,6 @@ type ClientInfo struct {
241240
HasExperimental bool
242241
DefaultVersion string
243242
Orchestrator Orchestrator
244-
TLSOptions *tlsconfig.Options
245243
}
246244

247245
// HasKubernetes checks if kubernetes orchestrator is enabled

cli/command/stack/kubernetes/list.go

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package kubernetes
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
7+
"io"
68
"io/ioutil"
79
"net/http"
810
"net/url"
911

1012
"github.com/docker/cli/cli/command"
1113
"github.com/docker/cli/cli/command/formatter"
1214
"github.com/docker/cli/cli/command/stack/options"
13-
"github.com/docker/go-connections/tlsconfig"
1415
"github.com/pkg/errors"
1516
"github.com/sirupsen/logrus"
1617
core_v1 "k8s.io/api/core/v1"
@@ -86,44 +87,22 @@ func getUserVisibleNamespaces(dockerCli command.Cli) (*core_v1.NamespaceList, er
8687
if err != nil {
8788
return nil, err
8889
}
89-
endpoint.Scheme = "https"
90-
endpoint.Path = "/kubernetesNamespaces"
90+
url := "https://" + endpoint.Host + "/kubernetesNamespaces"
9191
res := core_v1.NamespaceList{}
92-
return &res, makeRequest(dockerCli, *endpoint, func(resp http.Response) error {
93-
body, err := ioutil.ReadAll(resp.Body)
92+
err = dockerCli.Client().CustomRequest(context.Background(), "GET", url, nil, nil, nil, func(statusCode int, body io.Reader) error {
93+
bytes, err := ioutil.ReadAll(body)
9494
if err != nil {
95-
return errors.Wrapf(err, "received %d status and unable to read response", resp.StatusCode)
95+
return errors.Wrapf(err, "received %d status and unable to read response", statusCode)
9696
}
97-
if resp.StatusCode != http.StatusOK {
98-
return fmt.Errorf(string(body))
97+
if statusCode != http.StatusOK {
98+
return fmt.Errorf(string(bytes))
9999
}
100-
if err := json.Unmarshal(body, &res); err != nil {
101-
return errors.Wrapf(err, "unmarshal failed: %s", string(body))
100+
if err := json.Unmarshal(bytes, &res); err != nil {
101+
return errors.Wrapf(err, "unmarshal failed: %s", string(bytes))
102102
}
103103
return nil
104104
})
105-
}
106-
107-
func makeRequest(dockerCli command.Cli, endpoint url.URL, handler func(resp http.Response) error) error {
108-
tlsOptions := dockerCli.ClientInfo().TLSOptions
109-
if tlsOptions == nil {
110-
return fmt.Errorf("missing TLS options for https")
111-
}
112-
tlsConfig, err := tlsconfig.Client(*tlsOptions)
113-
if err != nil {
114-
return err
115-
}
116-
httpClient := http.Client{
117-
Transport: &http.Transport{
118-
TLSClientConfig: tlsConfig,
119-
},
120-
}
121-
resp, err := httpClient.Get(endpoint.String())
122-
if err != nil {
123-
return err
124-
}
125-
defer resp.Body.Close()
126-
return handler(*resp)
105+
return &res, err
127106
}
128107

129108
func getStacksWithNamespaces(kubeCli *KubeCli, opts options.List) ([]*formatter.Stack, error) {

vendor/github.com/docker/docker/client/interface.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/docker/client/request.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)