From 37fcaf7a29e862fb9e2a1591c2fa1d66c5775a78 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Sirot Date: Tue, 26 Feb 2019 16:08:26 +0100 Subject: [PATCH] Resolve the docker Endpoint even if the client already exists. In that case the `TestDialStdio` e2e test had to be modified: the `--tls` option triggers an error since the endpoint resolution tries to read the `${DOCKER_CERT_PATH}/ca.pem` file which does not exist. Signed-off-by: Jean-Christophe Sirot --- cli/command/cli.go | 16 +++++++--------- e2e/cli-plugins/dial_test.go | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cli/command/cli.go b/cli/command/cli.go index 55858aedbc05..3208a790417e 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -214,20 +214,18 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize if err != nil { return err } + cli.dockerEndpoint, err = resolveDockerEndpoint(cli.contextStore, cli.currentContext, opts.Common) + if err != nil { + return errors.Wrap(err, "unable to resolve docker endpoint") + } if cli.client == nil { - endpoint, err := resolveDockerEndpoint(cli.contextStore, cli.currentContext, opts.Common) - if err != nil { - return errors.Wrap(err, "unable to resolve docker endpoint") - } - cli.dockerEndpoint = endpoint - - cli.client, err = newAPIClientFromEndpoint(endpoint, cli.configFile) + cli.client, err = newAPIClientFromEndpoint(cli.dockerEndpoint, cli.configFile) if tlsconfig.IsErrEncryptedKey(err) { passRetriever := passphrase.PromptRetrieverWithInOut(cli.In(), cli.Out(), nil) newClient := func(password string) (client.APIClient, error) { - endpoint.TLSPassword = password - return newAPIClientFromEndpoint(endpoint, cli.configFile) + cli.dockerEndpoint.TLSPassword = password + return newAPIClientFromEndpoint(cli.dockerEndpoint, cli.configFile) } cli.client, err = getClientWithPassword(passRetriever, newClient) } diff --git a/e2e/cli-plugins/dial_test.go b/e2e/cli-plugins/dial_test.go index a01feb034539..9953f3a7a8a7 100644 --- a/e2e/cli-plugins/dial_test.go +++ b/e2e/cli-plugins/dial_test.go @@ -18,9 +18,9 @@ func TestDialStdio(t *testing.T) { // follows. We observe this from the debug level logging from // the connhelper stuff. helloworld := filepath.Join(os.Getenv("DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS"), "docker-helloworld") - cmd := icmd.Command(helloworld, "--config=blah", "--tls", "--log-level", "debug", "helloworld", "--who=foo") + cmd := icmd.Command(helloworld, "--config=blah", "--log-level", "debug", "helloworld", "--who=foo") res := icmd.RunCmd(cmd, icmd.WithEnv(manager.ReexecEnvvar+"=/bin/true")) res.Assert(t, icmd.Success) - assert.Assert(t, is.Contains(res.Stderr(), `msg="commandconn: starting /bin/true with [--config=blah --tls --log-level debug system dial-stdio]"`)) + assert.Assert(t, is.Contains(res.Stderr(), `msg="commandconn: starting /bin/true with [--config=blah --log-level debug system dial-stdio]"`)) assert.Assert(t, is.Equal(res.Stdout(), "Hello foo!\n")) }