mirror of https://github.com/docker/cli.git
Warn if DOCKER_ORCHESTRATOR is still used but not DOCKER_STACK_ORCHESTRATOR
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
e02c28f40a
commit
e8c87f7cb3
|
@ -2,6 +2,7 @@ package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ const (
|
||||||
|
|
||||||
defaultOrchestrator = OrchestratorSwarm
|
defaultOrchestrator = OrchestratorSwarm
|
||||||
envVarDockerStackOrchestrator = "DOCKER_STACK_ORCHESTRATOR"
|
envVarDockerStackOrchestrator = "DOCKER_STACK_ORCHESTRATOR"
|
||||||
|
envVarDockerOrchestrator = "DOCKER_ORCHESTRATOR"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HasKubernetes returns true if defined orchestrator has Kubernetes capabilities.
|
// HasKubernetes returns true if defined orchestrator has Kubernetes capabilities.
|
||||||
|
@ -53,13 +55,16 @@ func normalize(value string) (Orchestrator, error) {
|
||||||
|
|
||||||
// GetStackOrchestrator checks DOCKER_STACK_ORCHESTRATOR environment variable and configuration file
|
// GetStackOrchestrator checks DOCKER_STACK_ORCHESTRATOR environment variable and configuration file
|
||||||
// orchestrator value and returns user defined Orchestrator.
|
// orchestrator value and returns user defined Orchestrator.
|
||||||
func GetStackOrchestrator(flagValue, value string) (Orchestrator, error) {
|
func GetStackOrchestrator(flagValue, value string, stderr io.Writer) (Orchestrator, error) {
|
||||||
// Check flag
|
// Check flag
|
||||||
if o, err := normalize(flagValue); o != orchestratorUnset {
|
if o, err := normalize(flagValue); o != orchestratorUnset {
|
||||||
return o, err
|
return o, err
|
||||||
}
|
}
|
||||||
// Check environment variable
|
// Check environment variable
|
||||||
env := os.Getenv(envVarDockerStackOrchestrator)
|
env := os.Getenv(envVarDockerStackOrchestrator)
|
||||||
|
if env == "" && os.Getenv(envVarDockerOrchestrator) != "" {
|
||||||
|
fmt.Fprintf(stderr, "WARNING: experimental environment variable %s is set. Please use %s instead\n", envVarDockerOrchestrator, envVarDockerStackOrchestrator)
|
||||||
|
}
|
||||||
if o, err := normalize(env); o != orchestratorUnset {
|
if o, err := normalize(env); o != orchestratorUnset {
|
||||||
return o, err
|
return o, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -107,7 +108,7 @@ func TestOrchestratorSwitch(t *testing.T) {
|
||||||
err := cli.Initialize(options)
|
err := cli.Initialize(options)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
orchestrator, err := GetStackOrchestrator(testcase.flagOrchestrator, cli.ConfigFile().StackOrchestrator)
|
orchestrator, err := GetStackOrchestrator(testcase.flagOrchestrator, cli.ConfigFile().StackOrchestrator, ioutil.Discard)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Check(t, is.Equal(testcase.expectedKubernetes, orchestrator.HasKubernetes()))
|
assert.Check(t, is.Equal(testcase.expectedKubernetes, orchestrator.HasKubernetes()))
|
||||||
assert.Check(t, is.Equal(testcase.expectedSwarm, orchestrator.HasSwarm()))
|
assert.Check(t, is.Equal(testcase.expectedSwarm, orchestrator.HasSwarm()))
|
||||||
|
|
|
@ -3,6 +3,7 @@ package stack
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
|
@ -26,7 +27,7 @@ func NewStackCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Short: "Manage Docker stacks",
|
Short: "Manage Docker stacks",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
orchestrator, err := getOrchestrator(dockerCli.ConfigFile(), cmd)
|
orchestrator, err := getOrchestrator(dockerCli.ConfigFile(), cmd, dockerCli.Err())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -71,12 +72,12 @@ func NewTopLevelDeployCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOrchestrator(config *configfile.ConfigFile, cmd *cobra.Command) (command.Orchestrator, error) {
|
func getOrchestrator(config *configfile.ConfigFile, cmd *cobra.Command, stderr io.Writer) (command.Orchestrator, error) {
|
||||||
var orchestratorFlag string
|
var orchestratorFlag string
|
||||||
if o, err := cmd.Flags().GetString("orchestrator"); err == nil {
|
if o, err := cmd.Flags().GetString("orchestrator"); err == nil {
|
||||||
orchestratorFlag = o
|
orchestratorFlag = o
|
||||||
}
|
}
|
||||||
return command.GetStackOrchestrator(orchestratorFlag, config.StackOrchestrator)
|
return command.GetStackOrchestrator(orchestratorFlag, config.StackOrchestrator, stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func hideOrchestrationFlags(cmd *cobra.Command, orchestrator command.Orchestrator) {
|
func hideOrchestrationFlags(cmd *cobra.Command, orchestrator command.Orchestrator) {
|
||||||
|
|
|
@ -126,7 +126,7 @@ func runVersion(dockerCli command.Cli, opts *versionOptions) error {
|
||||||
return cli.StatusError{StatusCode: 64, Status: err.Error()}
|
return cli.StatusError{StatusCode: 64, Status: err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
orchestrator, err := command.GetStackOrchestrator("", dockerCli.ConfigFile().StackOrchestrator)
|
orchestrator, err := command.GetStackOrchestrator("", dockerCli.ConfigFile().StackOrchestrator, dockerCli.Err())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.StatusError{StatusCode: 64, Status: err.Error()}
|
return cli.StatusError{StatusCode: 64, Status: err.Error()}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue