mirror of https://github.com/docker/cli.git
Merge pull request #1055 from mat007/fix-invalid-orchestrator-silently-ignored
Make an error for an invalid orchestrator
This commit is contained in:
commit
161bc1ed3c
|
@ -166,7 +166,10 @@ 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(hasExperimental, opts.Common.Orchestrator, cli.configFile.Orchestrator)
|
orchestrator, err := GetOrchestrator(hasExperimental, opts.Common.Orchestrator, cli.configFile.Orchestrator)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
cli.clientInfo = ClientInfo{
|
cli.clientInfo = ClientInfo{
|
||||||
DefaultVersion: cli.client.ClientVersion(),
|
DefaultVersion: cli.client.ClientVersion(),
|
||||||
HasExperimental: hasExperimental,
|
HasExperimental: hasExperimental,
|
||||||
|
|
|
@ -19,41 +19,39 @@ const (
|
||||||
envVarDockerOrchestrator = "DOCKER_ORCHESTRATOR"
|
envVarDockerOrchestrator = "DOCKER_ORCHESTRATOR"
|
||||||
)
|
)
|
||||||
|
|
||||||
func normalize(flag string) Orchestrator {
|
func normalize(value string) (Orchestrator, error) {
|
||||||
switch flag {
|
switch value {
|
||||||
case "kubernetes":
|
case "kubernetes":
|
||||||
return OrchestratorKubernetes
|
return OrchestratorKubernetes, nil
|
||||||
case "swarm":
|
case "swarm":
|
||||||
return OrchestratorSwarm
|
return OrchestratorSwarm, nil
|
||||||
|
case "":
|
||||||
|
return orchestratorUnset, nil
|
||||||
default:
|
default:
|
||||||
return orchestratorUnset
|
return defaultOrchestrator, fmt.Errorf("specified orchestrator %q is invalid, please use either kubernetes or swarm", value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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(isExperimental bool, flagValue, value string) Orchestrator {
|
func GetOrchestrator(isExperimental bool, flagValue, value string) (Orchestrator, error) {
|
||||||
// Non experimental CLI has kubernetes disabled
|
// Non experimental CLI has kubernetes disabled
|
||||||
if !isExperimental {
|
if !isExperimental {
|
||||||
return defaultOrchestrator
|
return defaultOrchestrator, nil
|
||||||
}
|
}
|
||||||
// Check flag
|
// Check flag
|
||||||
if o := normalize(flagValue); o != orchestratorUnset {
|
if o, err := normalize(flagValue); o != orchestratorUnset {
|
||||||
return o
|
return o, err
|
||||||
}
|
}
|
||||||
// Check environment variable
|
// Check environment variable
|
||||||
env := os.Getenv(envVarDockerOrchestrator)
|
env := os.Getenv(envVarDockerOrchestrator)
|
||||||
if o := normalize(env); o != orchestratorUnset {
|
if o, err := normalize(env); o != orchestratorUnset {
|
||||||
return o
|
return o, err
|
||||||
}
|
}
|
||||||
// Check specified orchestrator
|
// Check specified orchestrator
|
||||||
if o := normalize(value); o != orchestratorUnset {
|
if o, err := normalize(value); o != orchestratorUnset {
|
||||||
return o
|
return o, err
|
||||||
}
|
|
||||||
|
|
||||||
if value != "" {
|
|
||||||
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, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue