mirror of
https://github.com/kubernetes/client-go.git
synced 2025-08-28 11:41:49 +00:00
Explicit namespace from kubeconfig should override in-cluster config
Kubernetes-commit: 63b5650885acf6c2f4e68c8140ade2964bc2c6cb
This commit is contained in:
parent
a4c9f96ebf
commit
7972aac9f3
@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
|
||||||
|
"k8s.io/client-go/pkg/api"
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||||
)
|
)
|
||||||
@ -134,12 +135,26 @@ func (config *DeferredLoadingClientConfig) Namespace() (string, bool, error) {
|
|||||||
return "", false, err
|
return "", false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ns, ok, err := mergedKubeConfig.Namespace()
|
ns, overridden, err := mergedKubeConfig.Namespace()
|
||||||
// if we get an error and it is not empty config, or if the merged config defined an explicit namespace, or
|
// if we get an error and it is not empty config, or if the merged config defined an explicit namespace, or
|
||||||
// if in-cluster config is not possible, return immediately
|
// if in-cluster config is not possible, return immediately
|
||||||
if (err != nil && !IsEmptyConfig(err)) || ok || !config.icc.Possible() {
|
if (err != nil && !IsEmptyConfig(err)) || overridden || !config.icc.Possible() {
|
||||||
// return on any error except empty config
|
// return on any error except empty config
|
||||||
return ns, ok, err
|
return ns, overridden, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ns) > 0 {
|
||||||
|
// if we got a non-default namespace from the kubeconfig, use it
|
||||||
|
if ns != api.NamespaceDefault {
|
||||||
|
return ns, false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we got a default namespace, determine whether it was explicit or implicit
|
||||||
|
if raw, err := mergedKubeConfig.RawConfig(); err == nil {
|
||||||
|
if context := raw.Contexts[raw.CurrentContext]; context != nil && len(context.Namespace) > 0 {
|
||||||
|
return ns, false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(4).Infof("Using in-cluster namespace")
|
glog.V(4).Infof("Using in-cluster namespace")
|
||||||
|
Loading…
Reference in New Issue
Block a user