Merge pull request #3512 from thaJeztah/update_engine_local_changes

client: local changes after engine update
This commit is contained in:
Sebastiaan van Stijn 2022-04-08 15:50:52 +02:00 committed by GitHub
commit 2784bb565c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 23 deletions

View File

@ -411,7 +411,7 @@ func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (string, error
var host string var host string
switch len(hosts) { switch len(hosts) {
case 0: case 0:
host = os.Getenv("DOCKER_HOST") host = os.Getenv(client.EnvOverrideHost)
case 1: case 1:
host = hosts[0] host = hosts[0]
default: default:
@ -429,7 +429,7 @@ func UserAgent() string {
// resolveContextName resolves the current context name with the following rules: // resolveContextName resolves the current context name with the following rules:
// - setting both --context and --host flags is ambiguous // - setting both --context and --host flags is ambiguous
// - if --context is set, use this value // - if --context is set, use this value
// - if --host flag or DOCKER_HOST is set, fallbacks to use the same logic as before context-store was added // - if --host flag or DOCKER_HOST (client.EnvOverrideHost) is set, fallbacks to use the same logic as before context-store was added
// for backward compatibility with existing scripts // for backward compatibility with existing scripts
// - if DOCKER_CONTEXT is set, use this value // - if DOCKER_CONTEXT is set, use this value
// - if Config file has a globally set "CurrentContext", use this value // - if Config file has a globally set "CurrentContext", use this value
@ -444,7 +444,7 @@ func resolveContextName(opts *cliflags.CommonOptions, config *configfile.ConfigF
if len(opts.Hosts) > 0 { if len(opts.Hosts) > 0 {
return DefaultContextName, nil return DefaultContextName, nil
} }
if _, present := os.LookupEnv("DOCKER_HOST"); present { if _, present := os.LookupEnv(client.EnvOverrideHost); present {
return DefaultContextName, nil return DefaultContextName, nil
} }
if ctxName, ok := os.LookupEnv("DOCKER_CONTEXT"); ok { if ctxName, ok := os.LookupEnv("DOCKER_CONTEXT"); ok {

View File

@ -10,6 +10,7 @@ import (
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/context/docker" "github.com/docker/cli/cli/context/docker"
flagsHelper "github.com/docker/cli/cli/flags" flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/docker/client"
"github.com/fvbommel/sortorder" "github.com/fvbommel/sortorder"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -73,9 +74,9 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
if err := format(dockerCli, opts, contexts); err != nil { if err := format(dockerCli, opts, contexts); err != nil {
return err return err
} }
if os.Getenv("DOCKER_HOST") != "" { if os.Getenv(client.EnvOverrideHost) != "" {
fmt.Fprint(dockerCli.Err(), "Warning: DOCKER_HOST environment variable overrides the active context. "+ fmt.Fprintf(dockerCli.Err(), "Warning: %[1]s environment variable overrides the active context. "+
"To use a context, either set the global --context flag, or unset DOCKER_HOST environment variable.\n") "To use a context, either set the global --context flag, or unset %[1]s environment variable.\n", client.EnvOverrideHost)
} }
return nil return nil
} }

View File

@ -6,6 +6,7 @@ import (
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/context/store" "github.com/docker/cli/cli/context/store"
"github.com/docker/docker/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -41,9 +42,9 @@ func RunUse(dockerCli command.Cli, name string) error {
} }
fmt.Fprintln(dockerCli.Out(), name) fmt.Fprintln(dockerCli.Out(), name)
fmt.Fprintf(dockerCli.Err(), "Current context is now %q\n", name) fmt.Fprintf(dockerCli.Err(), "Current context is now %q\n", name)
if os.Getenv("DOCKER_HOST") != "" { if os.Getenv(client.EnvOverrideHost) != "" {
fmt.Fprintf(dockerCli.Err(), "Warning: DOCKER_HOST environment variable overrides the active context. "+ fmt.Fprintf(dockerCli.Err(), "Warning: %[1]s environment variable overrides the active context. "+
"To use %q, either set the global --context flag, or unset DOCKER_HOST environment variable.\n", name) "To use %[2]q, either set the global --context flag, or unset %[1]s environment variable.\n", client.EnvOverrideHost, name)
} }
return nil return nil
} }

View File

@ -6,7 +6,6 @@ import (
"encoding/pem" "encoding/pem"
"net" "net"
"net/http" "net/http"
"os"
"time" "time"
"github.com/docker/cli/cli/connhelper" "github.com/docker/cli/cli/connhelper"
@ -122,12 +121,7 @@ func (c *Endpoint) ClientOpts() ([]client.Opt, error) {
} }
} }
version := os.Getenv("DOCKER_API_VERSION") result = append(result, client.WithVersionFromEnv(), client.WithAPIVersionNegotiation())
if version != "" {
result = append(result, client.WithVersion(version))
} else {
result = append(result, client.WithAPIVersionNegotiation())
}
return result, nil return result, nil
} }

View File

@ -7,6 +7,7 @@ import (
"github.com/docker/cli/cli/config" "github.com/docker/cli/cli/config"
"github.com/docker/cli/opts" "github.com/docker/cli/opts"
"github.com/docker/docker/client"
"github.com/docker/go-connections/tlsconfig" "github.com/docker/go-connections/tlsconfig"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@ -36,9 +37,10 @@ Refer to https://docs.docker.com/go/formatting/ for more information about forma
) )
var ( var (
dockerCertPath = os.Getenv("DOCKER_CERT_PATH") dockerCertPath = os.Getenv(client.EnvOverrideCertPath)
dockerTLSVerify = os.Getenv("DOCKER_TLS_VERIFY") != "" dockerTLSVerify = os.Getenv(client.EnvTLSVerify) != ""
dockerTLS = os.Getenv("DOCKER_TLS") != "" // TODO(thaJeztah) the 'DOCKER_TLS' environment variable is not documented, and does not have a const.
dockerTLS = os.Getenv("DOCKER_TLS") != ""
) )
// CommonOptions are options common to both the client and the daemon. // CommonOptions are options common to both the client and the daemon.
@ -84,7 +86,7 @@ func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) {
hostOpt := opts.NewNamedListOptsRef("hosts", &commonOpts.Hosts, nil) hostOpt := opts.NewNamedListOptsRef("hosts", &commonOpts.Hosts, nil)
flags.VarP(hostOpt, "host", "H", "Daemon socket(s) to connect to") flags.VarP(hostOpt, "host", "H", "Daemon socket(s) to connect to")
flags.StringVarP(&commonOpts.Context, "context", "c", "", flags.StringVarP(&commonOpts.Context, "context", "c", "",
`Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")`) `Name of the context to use to connect to the daemon (overrides `+client.EnvOverrideHost+` env var and default context set with "docker context use")`)
} }
// SetDefaultOptions sets default values for options after flag parsing is // SetDefaultOptions sets default values for options after flag parsing is

View File

@ -7,6 +7,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/docker/docker/client"
"github.com/pkg/errors" "github.com/pkg/errors"
"gotest.tools/v3/icmd" "gotest.tools/v3/icmd"
"gotest.tools/v3/poll" "gotest.tools/v3/poll"
@ -19,15 +20,15 @@ func Setup() error {
if dockerHost == "" { if dockerHost == "" {
return errors.New("$TEST_DOCKER_HOST must be set") return errors.New("$TEST_DOCKER_HOST must be set")
} }
if err := os.Setenv("DOCKER_HOST", dockerHost); err != nil { if err := os.Setenv(client.EnvOverrideHost, dockerHost); err != nil {
return err return err
} }
if dockerCertPath := os.Getenv("TEST_DOCKER_CERT_PATH"); dockerCertPath != "" { if dockerCertPath := os.Getenv("TEST_DOCKER_CERT_PATH"); dockerCertPath != "" {
if err := os.Setenv("DOCKER_CERT_PATH", dockerCertPath); err != nil { if err := os.Setenv(client.EnvOverrideCertPath, dockerCertPath); err != nil {
return err return err
} }
if err := os.Setenv("DOCKER_TLS_VERIFY", "1"); err != nil { if err := os.Setenv(client.EnvTLSVerify, "1"); err != nil {
return err return err
} }
} }