mirror of https://github.com/docker/cli.git
Move cli/command/orchestrator to cli/command
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
f960d2d5f3
commit
0508c09494
|
@ -1,10 +1,9 @@
|
||||||
package orchestrator
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/cli/cli/command"
|
|
||||||
cliconfig "github.com/docker/cli/cli/config"
|
cliconfig "github.com/docker/cli/cli/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,37 +12,37 @@ type Orchestrator string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Kubernetes orchestrator
|
// Kubernetes orchestrator
|
||||||
Kubernetes = Orchestrator("kubernetes")
|
OrchestratorKubernetes = Orchestrator("kubernetes")
|
||||||
// Swarm orchestrator
|
// Swarm orchestrator
|
||||||
Swarm = Orchestrator("swarm")
|
OrchestratorSwarm = Orchestrator("swarm")
|
||||||
unset = Orchestrator("unset")
|
orchestratorUnset = Orchestrator("unset")
|
||||||
|
|
||||||
defaultOrchestrator = Swarm
|
defaultOrchestrator = OrchestratorSwarm
|
||||||
dockerOrchestrator = "DOCKER_ORCHESTRATOR"
|
dockerOrchestrator = "DOCKER_ORCHESTRATOR"
|
||||||
)
|
)
|
||||||
|
|
||||||
func normalize(flag string) Orchestrator {
|
func normalize(flag string) Orchestrator {
|
||||||
switch strings.ToLower(flag) {
|
switch strings.ToLower(flag) {
|
||||||
case "kubernetes", "k8s":
|
case "kubernetes", "k8s":
|
||||||
return Kubernetes
|
return OrchestratorKubernetes
|
||||||
case "swarm", "swarmkit":
|
case "swarm", "swarmkit":
|
||||||
return Swarm
|
return OrchestratorSwarm
|
||||||
default:
|
default:
|
||||||
return unset
|
return orchestratorUnset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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(dockerCli command.Cli) Orchestrator {
|
func GetOrchestrator(dockerCli Cli) Orchestrator {
|
||||||
// Check environment variable
|
// Check environment variable
|
||||||
env := os.Getenv(dockerOrchestrator)
|
env := os.Getenv(dockerOrchestrator)
|
||||||
if o := normalize(env); o != unset {
|
if o := normalize(env); o != orchestratorUnset {
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
// Check config file
|
// Check config file
|
||||||
if configFile := cliconfig.LoadDefaultConfigFile(dockerCli.Err()); configFile != nil {
|
if configFile := cliconfig.LoadDefaultConfigFile(dockerCli.Err()); configFile != nil {
|
||||||
if o := normalize(configFile.Orchestrator); o != unset {
|
if o := normalize(configFile.Orchestrator); o != orchestratorUnset {
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,7 +3,6 @@ package stack
|
||||||
import (
|
import (
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/cli/command/orchestrator"
|
|
||||||
"github.com/docker/cli/cli/command/stack/kubernetes"
|
"github.com/docker/cli/cli/command/stack/kubernetes"
|
||||||
"github.com/docker/cli/cli/command/stack/swarm"
|
"github.com/docker/cli/cli/command/stack/swarm"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -18,10 +17,10 @@ func NewStackCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
RunE: command.ShowHelp(dockerCli.Err()),
|
RunE: command.ShowHelp(dockerCli.Err()),
|
||||||
Annotations: map[string]string{"version": "1.25"},
|
Annotations: map[string]string{"version": "1.25"},
|
||||||
}
|
}
|
||||||
switch orchestrator.GetOrchestrator(dockerCli) {
|
switch command.GetOrchestrator(dockerCli) {
|
||||||
case orchestrator.Kubernetes:
|
case command.OrchestratorKubernetes:
|
||||||
kubernetes.AddStackCommands(cmd, dockerCli)
|
kubernetes.AddStackCommands(cmd, dockerCli)
|
||||||
case orchestrator.Swarm:
|
case command.OrchestratorSwarm:
|
||||||
swarm.AddStackCommands(cmd, dockerCli)
|
swarm.AddStackCommands(cmd, dockerCli)
|
||||||
}
|
}
|
||||||
return cmd
|
return cmd
|
||||||
|
@ -30,10 +29,12 @@ func NewStackCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
// NewTopLevelDeployCommand returns a command for `docker deploy`
|
// NewTopLevelDeployCommand returns a command for `docker deploy`
|
||||||
func NewTopLevelDeployCommand(dockerCli command.Cli) *cobra.Command {
|
func NewTopLevelDeployCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
var cmd *cobra.Command
|
var cmd *cobra.Command
|
||||||
switch orchestrator.GetOrchestrator(dockerCli) {
|
switch command.GetOrchestrator(dockerCli) {
|
||||||
case orchestrator.Kubernetes:
|
case command.OrchestratorKubernetes:
|
||||||
cmd = kubernetes.NewTopLevelDeployCommand(dockerCli)
|
cmd = kubernetes.NewTopLevelDeployCommand(dockerCli)
|
||||||
case orchestrator.Swarm:
|
case command.OrchestratorSwarm:
|
||||||
|
cmd = swarm.NewTopLevelDeployCommand(dockerCli)
|
||||||
|
default:
|
||||||
cmd = swarm.NewTopLevelDeployCommand(dockerCli)
|
cmd = swarm.NewTopLevelDeployCommand(dockerCli)
|
||||||
}
|
}
|
||||||
// Remove the aliases at the top level
|
// Remove the aliases at the top level
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/cli/command/orchestrator"
|
|
||||||
"github.com/docker/cli/templates"
|
"github.com/docker/cli/templates"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -139,7 +138,7 @@ func runVersion(dockerCli *command.DockerCli, 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(orchestrator.GetOrchestrator(dockerCli)),
|
Orchestrator: string(command.GetOrchestrator(dockerCli)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
vd.Client.Platform.Name = cli.PlatformName
|
vd.Client.Platform.Name = cli.PlatformName
|
||||||
|
|
Loading…
Reference in New Issue