Fix stack ls behaviour with Kubernetes and variout --namespace flag values

Signed-off-by: Mathieu Champlon <mathieu.champlon@docker.com>
This commit is contained in:
Mathieu Champlon 2018-05-09 07:57:58 +02:00
parent f097831eb3
commit 2af66bed41
2 changed files with 3 additions and 16 deletions

View File

@ -27,7 +27,7 @@ func NewStackCommand(dockerCli command.Cli) *cobra.Command {
newServicesCommand(dockerCli), newServicesCommand(dockerCli),
) )
flags := cmd.PersistentFlags() flags := cmd.PersistentFlags()
flags.String("namespace", "default", "Kubernetes namespace to use") flags.String("namespace", "", "Kubernetes namespace to use")
flags.SetAnnotation("namespace", "kubernetes", nil) flags.SetAnnotation("namespace", "kubernetes", nil)
flags.SetAnnotation("namespace", "experimentalCLI", nil) flags.SetAnnotation("namespace", "experimentalCLI", nil)
flags.String("kubeconfig", "", "Kubernetes config file") flags.String("kubeconfig", "", "Kubernetes config file")

View File

@ -1,12 +1,8 @@
package kubernetes package kubernetes
import ( import (
"os"
"path/filepath"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/cli/kubernetes" "github.com/docker/cli/kubernetes"
"github.com/docker/docker/pkg/homedir"
flag "github.com/spf13/pflag" flag "github.com/spf13/pflag"
kubeclient "k8s.io/client-go/kubernetes" kubeclient "k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
@ -44,19 +40,10 @@ func WrapCli(dockerCli command.Cli, opts Options) (*KubeCli, error) {
cli := &KubeCli{ cli := &KubeCli{
Cli: dockerCli, Cli: dockerCli,
} }
kubeConfig := opts.Config clientConfig := kubernetes.NewKubernetesConfig(opts.Config)
if kubeConfig == "" {
if config := os.Getenv("KUBECONFIG"); config != "" {
kubeConfig = config
} else {
kubeConfig = filepath.Join(homedir.Get(), ".kube/config")
}
}
clientConfig := kubernetes.NewKubernetesConfig(kubeConfig)
cli.kubeNamespace = opts.Namespace cli.kubeNamespace = opts.Namespace
if opts.Namespace == "default" { if opts.Namespace == "" {
configNamespace, _, err := clientConfig.Namespace() configNamespace, _, err := clientConfig.Namespace()
if err != nil { if err != nil {
return nil, err return nil, err