From 1c1300bef652847875daa8fdaf6279117e299af6 Mon Sep 17 00:00:00 2001 From: Mathieu Champlon Date: Tue, 15 May 2018 16:56:45 +0200 Subject: [PATCH 1/2] Imply all Kubernetes namespaces for docker stack list when orchestrator is all or Kubernetes * Add "kubernetes" struct in config file with "allNamespaces" option, to opt-out this behavior when set as "disabled" Signed-off-by: Mathieu Champlon --- cli/command/stack/kubernetes/list.go | 8 ++++++++ cli/config/configfile/file.go | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/cli/command/stack/kubernetes/list.go b/cli/command/stack/kubernetes/list.go index 4a429731a5..f6efd050aa 100644 --- a/cli/command/stack/kubernetes/list.go +++ b/cli/command/stack/kubernetes/list.go @@ -10,6 +10,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/stack/options" + "github.com/docker/cli/cli/config/configfile" "github.com/pkg/errors" core_v1 "k8s.io/api/core/v1" apierrs "k8s.io/apimachinery/pkg/api/errors" @@ -19,11 +20,18 @@ import ( // GetStacks lists the kubernetes stacks func GetStacks(kubeCli *KubeCli, opts options.List) ([]*formatter.Stack, error) { if opts.AllNamespaces || len(opts.Namespaces) == 0 { + if isAllNamespacesDisabled(kubeCli.ConfigFile().Kubernetes) { + opts.AllNamespaces = true + } return getStacksWithAllNamespaces(kubeCli, opts) } return getStacksWithNamespaces(kubeCli, opts, removeDuplicates(opts.Namespaces)) } +func isAllNamespacesDisabled(kubeCliConfig *configfile.KubernetesConfig) bool { + return kubeCliConfig == nil || kubeCliConfig != nil && kubeCliConfig.AllNamespaces != "disabled" +} + func getStacks(kubeCli *KubeCli, opts options.List) ([]*formatter.Stack, error) { composeClient, err := kubeCli.composeClient() if err != nil { diff --git a/cli/config/configfile/file.go b/cli/config/configfile/file.go index 5653306622..f658385e16 100644 --- a/cli/config/configfile/file.go +++ b/cli/config/configfile/file.go @@ -46,6 +46,7 @@ type ConfigFile struct { Proxies map[string]ProxyConfig `json:"proxies,omitempty"` Experimental string `json:"experimental,omitempty"` Orchestrator string `json:"orchestrator,omitempty"` + Kubernetes *KubernetesConfig `json:"kubernetes,omitempty"` } // ProxyConfig contains proxy configuration settings @@ -56,6 +57,11 @@ type ProxyConfig struct { FTPProxy string `json:"ftpProxy,omitempty"` } +// KubernetesConfig contains Kubernetes orchestrator settings +type KubernetesConfig struct { + AllNamespaces string `json:"allNamespaces,omitempty"` +} + // New initializes an empty configuration file for the given filename 'fn' func New(fn string) *ConfigFile { return &ConfigFile{ From 770daef564c534b9122efd1e6a0c0dfff8573bc1 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Thu, 24 May 2018 16:25:01 +0200 Subject: [PATCH 2/2] --orchestrator flag is now a persistent flag Signed-off-by: Silvin Lubecki --- cli/flags/common.go | 2 -- cmd/docker/docker.go | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/flags/common.go b/cli/flags/common.go index 9c37aed648..46c3d9d68b 100644 --- a/cli/flags/common.go +++ b/cli/flags/common.go @@ -55,8 +55,6 @@ func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) { flags.StringVarP(&commonOpts.LogLevel, "log-level", "l", "info", `Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")`) flags.BoolVar(&commonOpts.TLS, "tls", dockerTLS, "Use TLS; implied by --tlsverify") flags.BoolVar(&commonOpts.TLSVerify, FlagTLSVerify, dockerTLSVerify, "Use TLS and verify the remote") - flags.StringVar(&commonOpts.Orchestrator, "orchestrator", "", "Orchestrator to use (swarm|kubernetes|all) (experimental)") - flags.SetAnnotation("orchestrator", "experimentalCLI", nil) // TODO use flag flags.String("identity"}, "i", "", "Path to libtrust key file") diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index 68136657d9..c6a2b90933 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -51,6 +51,11 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command { flags.StringVar(&opts.ConfigDir, "config", cliconfig.Dir(), "Location of client config files") opts.Common.InstallFlags(flags) + // Install persistent flags + persistentFlags := cmd.PersistentFlags() + persistentFlags.StringVar(&opts.Common.Orchestrator, "orchestrator", "", "Orchestrator to use (swarm|kubernetes|all) (experimental)") + persistentFlags.SetAnnotation("orchestrator", "experimentalCLI", nil) + setFlagErrorFunc(dockerCli, cmd, flags, opts) setHelpFunc(dockerCli, cmd, flags, opts)