Skip to content

Commit

Permalink
Refactor + fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
  • Loading branch information
silvin-lubecki committed Jun 21, 2018
1 parent ba06122 commit 8c67022
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
3 changes: 0 additions & 3 deletions cli/command/orchestrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ func TestOrchestratorSwitch(t *testing.T) {
cli := &DockerCli{client: apiclient, err: os.Stderr}
cliconfig.SetDir(dir.Path())
options := flags.NewClientOptions()
if testcase.flagOrchestrator != "" {
options.Common.StackOrchestrator = testcase.flagOrchestrator
}
err := cli.Initialize(options)
assert.NilError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions cli/command/stack/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ func checkSupportedFlag(cmd *cobra.Command, orchestrator command.Orchestrator) e
return
}
if _, ok := f.Annotations["kubernetes"]; ok && !orchestrator.HasKubernetes() {
errs = append(errs, fmt.Sprintf("\"--%s\" is only supported on a Docker cli with kubernetes features enabled", f.Name))
errs = append(errs, fmt.Sprintf(`"--%s" is only supported on a Docker cli with kubernetes features enabled`, f.Name))
}
if _, ok := f.Annotations["swarm"]; ok && !orchestrator.HasSwarm() {
errs = append(errs, fmt.Sprintf("\"--%s\" is only supported on a Docker cli with swarm features enabled", f.Name))
errs = append(errs, fmt.Sprintf(`"--%s" is only supported on a Docker cli with swarm features enabled`, f.Name))
}
})
for _, subcmd := range cmd.Commands() {
Expand Down
2 changes: 1 addition & 1 deletion cli/command/stack/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func newDeployCommand(dockerCli command.Cli, common *commonOptions) *cobra.Comma
case common.orchestrator.HasAll():
return errUnsupportedAllOrchestrator
case common.orchestrator.HasKubernetes():
kli, err := kubernetes.WrapCli(dockerCli, kubernetes.NewOptions(cmd.Flags()), common.orchestrator)
kli, err := kubernetes.WrapCli(dockerCli, kubernetes.NewOptions(cmd.Flags(), common.orchestrator))
if err != nil {
return err
}
Expand Down
15 changes: 9 additions & 6 deletions cli/command/stack/kubernetes/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ type KubeCli struct {

// Options contains resolved parameters to initialize kubernetes clients
type Options struct {
Namespace string
Config string
Namespace string
Config string
Orchestrator command.Orchestrator
}

// NewOptions returns an Options initialized with command line flags
func NewOptions(flags *flag.FlagSet) Options {
var opts Options
func NewOptions(flags *flag.FlagSet, orchestrator command.Orchestrator) Options {
opts := Options{
Orchestrator: orchestrator,
}
if namespace, err := flags.GetString("namespace"); err == nil {
opts.Namespace = namespace
}
Expand All @@ -46,7 +49,7 @@ func AddNamespaceFlag(flags *flag.FlagSet) {
}

// WrapCli wraps command.Cli with kubernetes specifics
func WrapCli(dockerCli command.Cli, opts Options, orchestrator command.Orchestrator) (*KubeCli, error) {
func WrapCli(dockerCli command.Cli, opts Options) (*KubeCli, error) {
cli := &KubeCli{
Cli: dockerCli,
}
Expand All @@ -73,7 +76,7 @@ func WrapCli(dockerCli command.Cli, opts Options, orchestrator command.Orchestra
}
cli.clientSet = clientSet

if orchestrator.HasAll() {
if opts.Orchestrator.HasAll() {
if err := cli.checkHostsMatch(); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/stack/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func runList(cmd *cobra.Command, dockerCli command.Cli, opts options.List, orche
stacks = append(stacks, ss...)
}
if orchestrator.HasKubernetes() {
kubeCli, err := kubernetes.WrapCli(dockerCli, kubernetes.NewOptions(cmd.Flags()), orchestrator)
kubeCli, err := kubernetes.WrapCli(dockerCli, kubernetes.NewOptions(cmd.Flags(), orchestrator))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/stack/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func newPsCommand(dockerCli command.Cli, common *commonOptions) *cobra.Command {
case common.orchestrator.HasAll():
return errUnsupportedAllOrchestrator
case common.orchestrator.HasKubernetes():
kli, err := kubernetes.WrapCli(dockerCli, kubernetes.NewOptions(cmd.Flags()), common.orchestrator)
kli, err := kubernetes.WrapCli(dockerCli, kubernetes.NewOptions(cmd.Flags(), common.orchestrator))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/stack/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func newRemoveCommand(dockerCli command.Cli, common *commonOptions) *cobra.Comma
case common.orchestrator.HasAll():
return errUnsupportedAllOrchestrator
case common.orchestrator.HasKubernetes():
kli, err := kubernetes.WrapCli(dockerCli, kubernetes.NewOptions(cmd.Flags()), common.orchestrator)
kli, err := kubernetes.WrapCli(dockerCli, kubernetes.NewOptions(cmd.Flags(), common.orchestrator))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/stack/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func newServicesCommand(dockerCli command.Cli, common *commonOptions) *cobra.Com
case common.orchestrator.HasAll():
return errUnsupportedAllOrchestrator
case common.orchestrator.HasKubernetes():
kli, err := kubernetes.WrapCli(dockerCli, kubernetes.NewOptions(cmd.Flags()), common.orchestrator)
kli, err := kubernetes.WrapCli(dockerCli, kubernetes.NewOptions(cmd.Flags(), common.orchestrator))
if err != nil {
return err
}
Expand Down

0 comments on commit 8c67022

Please sign in to comment.