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),
)
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", "experimentalCLI", nil)
flags.String("kubeconfig", "", "Kubernetes config file")

View File

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