mirror of https://github.com/docker/cli.git
Set a global orchestrator flag
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
12c0825a4c
commit
5d375b348a
|
@ -136,11 +136,12 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Experimental field")
|
return errors.Wrap(err, "Experimental field")
|
||||||
}
|
}
|
||||||
orchestrator := GetOrchestrator(cli.configFile.Orchestrator)
|
orchestrator := GetOrchestrator(opts.Common.Orchestrator, cli.configFile.Orchestrator)
|
||||||
cli.clientInfo = ClientInfo{
|
cli.clientInfo = ClientInfo{
|
||||||
DefaultVersion: cli.client.ClientVersion(),
|
DefaultVersion: cli.client.ClientVersion(),
|
||||||
HasExperimental: hasExperimental,
|
HasExperimental: hasExperimental,
|
||||||
HasKubernetes: orchestrator == OrchestratorKubernetes,
|
HasKubernetes: orchestrator == OrchestratorKubernetes,
|
||||||
|
Orchestrator: orchestrator,
|
||||||
}
|
}
|
||||||
cli.initializeFromClient()
|
cli.initializeFromClient()
|
||||||
return nil
|
return nil
|
||||||
|
@ -207,6 +208,7 @@ type ClientInfo struct {
|
||||||
HasExperimental bool
|
HasExperimental bool
|
||||||
HasKubernetes bool
|
HasKubernetes bool
|
||||||
DefaultVersion string
|
DefaultVersion string
|
||||||
|
Orchestrator Orchestrator
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDockerCli returns a DockerCli instance with IO output and error streams set by in, out and err.
|
// NewDockerCli returns a DockerCli instance with IO output and error streams set by in, out and err.
|
||||||
|
|
|
@ -33,19 +33,23 @@ func normalize(flag string) Orchestrator {
|
||||||
|
|
||||||
// GetOrchestrator checks DOCKER_ORCHESTRATOR environment variable and configuration file
|
// GetOrchestrator checks DOCKER_ORCHESTRATOR environment variable and configuration file
|
||||||
// orchestrator value and returns user defined Orchestrator.
|
// 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
|
// Check environment variable
|
||||||
env := os.Getenv(dockerOrchestrator)
|
env := os.Getenv(dockerOrchestrator)
|
||||||
if o := normalize(env); o != orchestratorUnset {
|
if o := normalize(env); o != orchestratorUnset {
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
// Check specified orchestrator
|
// Check specified orchestrator
|
||||||
if o := normalize(orchestrator); o != orchestratorUnset {
|
if o := normalize(value); o != orchestratorUnset {
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
if orchestrator != "" {
|
if value != "" {
|
||||||
fmt.Fprintf(os.Stderr, "Specified orchestrator %q is invalid. Please use either kubernetes or swarm\n", orchestrator)
|
fmt.Fprintf(os.Stderr, "Specified orchestrator %q is invalid. Please use either kubernetes or swarm\n", value)
|
||||||
}
|
}
|
||||||
// Nothing set, use default orchestrator
|
// Nothing set, use default orchestrator
|
||||||
return defaultOrchestrator
|
return defaultOrchestrator
|
||||||
|
|
|
@ -19,7 +19,7 @@ func newDeployCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Args: cli.ExactArgs(1),
|
Args: cli.ExactArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
opts.Namespace = args[0]
|
opts.Namespace = args[0]
|
||||||
if dockerCli.ClientInfo().HasKubernetes {
|
if dockerCli.ClientInfo().HasKubernetes() {
|
||||||
kli, err := kubernetes.WrapCli(dockerCli, cmd)
|
kli, err := kubernetes.WrapCli(dockerCli, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -18,7 +18,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Short: "List stacks",
|
Short: "List stacks",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if dockerCli.ClientInfo().HasKubernetes {
|
if dockerCli.ClientInfo().HasKubernetes() {
|
||||||
kli, err := kubernetes.WrapCli(dockerCli, cmd)
|
kli, err := kubernetes.WrapCli(dockerCli, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -19,7 +19,7 @@ func newPsCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Args: cli.ExactArgs(1),
|
Args: cli.ExactArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
opts.Namespace = args[0]
|
opts.Namespace = args[0]
|
||||||
if dockerCli.ClientInfo().HasKubernetes {
|
if dockerCli.ClientInfo().HasKubernetes() {
|
||||||
kli, err := kubernetes.WrapCli(dockerCli, cmd)
|
kli, err := kubernetes.WrapCli(dockerCli, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -19,7 +19,7 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Args: cli.RequiresMinArgs(1),
|
Args: cli.RequiresMinArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
opts.Namespaces = args
|
opts.Namespaces = args
|
||||||
if dockerCli.ClientInfo().HasKubernetes {
|
if dockerCli.ClientInfo().HasKubernetes() {
|
||||||
kli, err := kubernetes.WrapCli(dockerCli, cmd)
|
kli, err := kubernetes.WrapCli(dockerCli, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -19,7 +19,7 @@ func newServicesCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Args: cli.ExactArgs(1),
|
Args: cli.ExactArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
opts.Namespace = args[0]
|
opts.Namespace = args[0]
|
||||||
if dockerCli.ClientInfo().HasKubernetes {
|
if dockerCli.ClientInfo().HasKubernetes() {
|
||||||
kli, err := kubernetes.WrapCli(dockerCli, cmd)
|
kli, err := kubernetes.WrapCli(dockerCli, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -137,7 +137,7 @@ func runVersion(dockerCli command.Cli, opts *versionOptions) error {
|
||||||
Os: runtime.GOOS,
|
Os: runtime.GOOS,
|
||||||
Arch: runtime.GOARCH,
|
Arch: runtime.GOARCH,
|
||||||
Experimental: dockerCli.ClientInfo().HasExperimental,
|
Experimental: dockerCli.ClientInfo().HasExperimental,
|
||||||
Orchestrator: string(command.GetOrchestrator(dockerCli.ConfigFile().Orchestrator)),
|
Orchestrator: string(dockerCli.ClientInfo().Orchestrator),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,13 @@ var (
|
||||||
|
|
||||||
// CommonOptions are options common to both the client and the daemon.
|
// CommonOptions are options common to both the client and the daemon.
|
||||||
type CommonOptions struct {
|
type CommonOptions struct {
|
||||||
Debug bool
|
Debug bool
|
||||||
Hosts []string
|
Hosts []string
|
||||||
LogLevel string
|
Orchestrator string
|
||||||
TLS bool
|
LogLevel string
|
||||||
TLSVerify bool
|
TLS bool
|
||||||
TLSOptions *tlsconfig.Options
|
TLSVerify bool
|
||||||
|
TLSOptions *tlsconfig.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommonOptions returns a new CommonOptions
|
// 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.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.TLS, "tls", false, "Use TLS; implied by --tlsverify")
|
||||||
flags.BoolVar(&commonOpts.TLSVerify, FlagTLSVerify, dockerTLSVerify, "Use TLS and verify the remote")
|
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")
|
// TODO use flag flags.String("identity"}, "i", "", "Path to libtrust key file")
|
||||||
|
|
||||||
|
|
|
@ -279,7 +279,7 @@ func areFlagsSupported(cmd *cobra.Command, details versionDetails) error {
|
||||||
clientVersion := details.Client().ClientVersion()
|
clientVersion := details.Client().ClientVersion()
|
||||||
osType := details.ServerInfo().OSType
|
osType := details.ServerInfo().OSType
|
||||||
hasExperimental := details.ServerInfo().HasExperimental
|
hasExperimental := details.ServerInfo().HasExperimental
|
||||||
hasKubernetes := details.ClientInfo().HasKubernetes
|
hasKubernetes := details.ClientInfo().HasKubernetes()
|
||||||
|
|
||||||
errs := []string{}
|
errs := []string{}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue