diff --git a/cli/command/cli.go b/cli/command/cli.go index b34d9e7f3d..bdd3b18f24 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -136,11 +136,12 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error { if err != nil { return errors.Wrap(err, "Experimental field") } - orchestrator := GetOrchestrator(cli.configFile.Orchestrator) + orchestrator := GetOrchestrator(opts.Common.Orchestrator, cli.configFile.Orchestrator) cli.clientInfo = ClientInfo{ DefaultVersion: cli.client.ClientVersion(), HasExperimental: hasExperimental, HasKubernetes: orchestrator == OrchestratorKubernetes, + Orchestrator: orchestrator, } cli.initializeFromClient() return nil @@ -207,6 +208,7 @@ type ClientInfo struct { HasExperimental bool HasKubernetes bool DefaultVersion string + Orchestrator Orchestrator } // NewDockerCli returns a DockerCli instance with IO output and error streams set by in, out and err. diff --git a/cli/command/orchestrator.go b/cli/command/orchestrator.go index 4438ef5cc6..6cf0e4603b 100644 --- a/cli/command/orchestrator.go +++ b/cli/command/orchestrator.go @@ -33,19 +33,23 @@ func normalize(flag string) Orchestrator { // GetOrchestrator checks DOCKER_ORCHESTRATOR environment variable and configuration file // orchestrator value and returns user defined Orchestrator. -func GetOrchestrator(orchestrator string) Orchestrator { +func GetOrchestrator(flagValue, value string) Orchestrator { + // Check flag + if o := normalize(flagValue); o != orchestratorUnset { + return o + } // Check environment variable env := os.Getenv(dockerOrchestrator) if o := normalize(env); o != orchestratorUnset { return o } // Check specified orchestrator - if o := normalize(orchestrator); o != orchestratorUnset { + if o := normalize(value); o != orchestratorUnset { return o } - if orchestrator != "" { - fmt.Fprintf(os.Stderr, "Specified orchestrator %q is invalid. Please use either kubernetes or swarm\n", orchestrator) + if value != "" { + fmt.Fprintf(os.Stderr, "Specified orchestrator %q is invalid. Please use either kubernetes or swarm\n", value) } // Nothing set, use default orchestrator return defaultOrchestrator diff --git a/cli/command/stack/deploy.go b/cli/command/stack/deploy.go index f9866716a8..d01add7b98 100644 --- a/cli/command/stack/deploy.go +++ b/cli/command/stack/deploy.go @@ -19,7 +19,7 @@ func newDeployCommand(dockerCli command.Cli) *cobra.Command { Args: cli.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.Namespace = args[0] - if dockerCli.ClientInfo().HasKubernetes { + if dockerCli.ClientInfo().HasKubernetes() { kli, err := kubernetes.WrapCli(dockerCli, cmd) if err != nil { return err diff --git a/cli/command/stack/list.go b/cli/command/stack/list.go index 4db83765fe..2cb10c1716 100644 --- a/cli/command/stack/list.go +++ b/cli/command/stack/list.go @@ -18,7 +18,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { Short: "List stacks", Args: cli.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - if dockerCli.ClientInfo().HasKubernetes { + if dockerCli.ClientInfo().HasKubernetes() { kli, err := kubernetes.WrapCli(dockerCli, cmd) if err != nil { return err diff --git a/cli/command/stack/ps.go b/cli/command/stack/ps.go index cd8c32a28e..8e835201a2 100644 --- a/cli/command/stack/ps.go +++ b/cli/command/stack/ps.go @@ -19,7 +19,7 @@ func newPsCommand(dockerCli command.Cli) *cobra.Command { Args: cli.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.Namespace = args[0] - if dockerCli.ClientInfo().HasKubernetes { + if dockerCli.ClientInfo().HasKubernetes() { kli, err := kubernetes.WrapCli(dockerCli, cmd) if err != nil { return err diff --git a/cli/command/stack/remove.go b/cli/command/stack/remove.go index 8324ba09a2..e4dd913dbd 100644 --- a/cli/command/stack/remove.go +++ b/cli/command/stack/remove.go @@ -19,7 +19,7 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command { Args: cli.RequiresMinArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.Namespaces = args - if dockerCli.ClientInfo().HasKubernetes { + if dockerCli.ClientInfo().HasKubernetes() { kli, err := kubernetes.WrapCli(dockerCli, cmd) if err != nil { return err diff --git a/cli/command/stack/services.go b/cli/command/stack/services.go index b3331c3df4..7f427c170e 100644 --- a/cli/command/stack/services.go +++ b/cli/command/stack/services.go @@ -19,7 +19,7 @@ func newServicesCommand(dockerCli command.Cli) *cobra.Command { Args: cli.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.Namespace = args[0] - if dockerCli.ClientInfo().HasKubernetes { + if dockerCli.ClientInfo().HasKubernetes() { kli, err := kubernetes.WrapCli(dockerCli, cmd) if err != nil { return err diff --git a/cli/command/system/version.go b/cli/command/system/version.go index 31f441e53f..8223b6df80 100644 --- a/cli/command/system/version.go +++ b/cli/command/system/version.go @@ -137,7 +137,7 @@ func runVersion(dockerCli command.Cli, opts *versionOptions) error { Os: runtime.GOOS, Arch: runtime.GOARCH, Experimental: dockerCli.ClientInfo().HasExperimental, - Orchestrator: string(command.GetOrchestrator(dockerCli.ConfigFile().Orchestrator)), + Orchestrator: string(dockerCli.ClientInfo().Orchestrator), }, } diff --git a/cli/flags/common.go b/cli/flags/common.go index a07bc77a75..a8e2840426 100644 --- a/cli/flags/common.go +++ b/cli/flags/common.go @@ -30,12 +30,13 @@ var ( // CommonOptions are options common to both the client and the daemon. type CommonOptions struct { - Debug bool - Hosts []string - LogLevel string - TLS bool - TLSVerify bool - TLSOptions *tlsconfig.Options + Debug bool + Hosts []string + Orchestrator string + LogLevel string + TLS bool + TLSVerify bool + TLSOptions *tlsconfig.Options } // NewCommonOptions returns a new CommonOptions @@ -53,6 +54,7 @@ func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) { flags.StringVarP(&commonOpts.LogLevel, "log-level", "l", "info", `Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")`) flags.BoolVar(&commonOpts.TLS, "tls", false, "Use TLS; implied by --tlsverify") flags.BoolVar(&commonOpts.TLSVerify, FlagTLSVerify, dockerTLSVerify, "Use TLS and verify the remote") + flags.StringVar(&commonOpts.Orchestrator, "orchestrator", "", "Which orchestrator to use with the docker cli (swarm|kubernetes)") // TODO use flag flags.String("identity"}, "i", "", "Path to libtrust key file") diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index c96c3b674b..0b48f464cc 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -279,7 +279,7 @@ func areFlagsSupported(cmd *cobra.Command, details versionDetails) error { clientVersion := details.Client().ClientVersion() osType := details.ServerInfo().OSType hasExperimental := details.ServerInfo().HasExperimental - hasKubernetes := details.ClientInfo().HasKubernetes + hasKubernetes := details.ClientInfo().HasKubernetes() errs := []string{}