mirror of https://github.com/docker/cli.git
Fix using the namespace specified in the kubeconfig file.
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
This commit is contained in:
parent
c31b61bff4
commit
f0aa126b03
|
@ -43,11 +43,7 @@ func NewOptions(flags *flag.FlagSet) Options {
|
|||
func WrapCli(dockerCli command.Cli, opts Options) (*KubeCli, error) {
|
||||
var err error
|
||||
cli := &KubeCli{
|
||||
Cli: dockerCli,
|
||||
kubeNamespace: "default",
|
||||
}
|
||||
if opts.Namespace != "" {
|
||||
cli.kubeNamespace = opts.Namespace
|
||||
Cli: dockerCli,
|
||||
}
|
||||
kubeConfig := opts.Config
|
||||
if kubeConfig == "" {
|
||||
|
@ -57,7 +53,19 @@ func WrapCli(dockerCli command.Cli, opts Options) (*KubeCli, error) {
|
|||
kubeConfig = filepath.Join(homedir.Get(), ".kube/config")
|
||||
}
|
||||
}
|
||||
config, err := kubernetes.NewKubernetesConfig(kubeConfig)
|
||||
|
||||
clientConfig := kubernetes.NewKubernetesConfig(kubeConfig)
|
||||
|
||||
cli.kubeNamespace = opts.Namespace
|
||||
if opts.Namespace == "default" {
|
||||
configNamespace, _, err := clientConfig.Namespace()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cli.kubeNamespace = configNamespace
|
||||
}
|
||||
|
||||
config, err := clientConfig.ClientConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -228,7 +228,8 @@ func getKubernetesVersion(dockerCli command.Cli, kubeConfig string) *kubernetesV
|
|||
Kubernetes: "Unknown",
|
||||
StackAPI: "Unknown",
|
||||
}
|
||||
config, err := kubernetes.NewKubernetesConfig(kubeConfig)
|
||||
clientConfig := kubernetes.NewKubernetesConfig(kubeConfig)
|
||||
config, err := clientConfig.ClientConfig()
|
||||
if err != nil {
|
||||
logrus.Debugf("failed to get Kubernetes configuration: %s", err)
|
||||
return &version
|
||||
|
|
|
@ -5,14 +5,13 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/docker/docker/pkg/homedir"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
// NewKubernetesConfig resolves the path to the desired Kubernetes configuration file, depending
|
||||
// environment variable and command line flag.
|
||||
func NewKubernetesConfig(configFlag string) (*restclient.Config, error) {
|
||||
kubeConfig := configFlag
|
||||
// NewKubernetesConfig resolves the path to the desired Kubernetes configuration file based on
|
||||
// the KUBECONFIG environment variable and command line flags.
|
||||
func NewKubernetesConfig(configPath string) clientcmd.ClientConfig {
|
||||
kubeConfig := configPath
|
||||
if kubeConfig == "" {
|
||||
if config := os.Getenv("KUBECONFIG"); config != "" {
|
||||
kubeConfig = config
|
||||
|
@ -20,5 +19,8 @@ func NewKubernetesConfig(configFlag string) (*restclient.Config, error) {
|
|||
kubeConfig = filepath.Join(homedir.Get(), ".kube/config")
|
||||
}
|
||||
}
|
||||
return clientcmd.BuildConfigFromFlags("", kubeConfig)
|
||||
|
||||
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
||||
&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeConfig},
|
||||
&clientcmd.ConfigOverrides{})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue