Set a global orchestrator flag
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: 5d375b348a
Component: cli
This commit is contained in:
committed by
Silvin Lubecki
parent
d7b5fca8a7
commit
effda473ed
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user