forked from mystiq/dex
storage/kubernetes: set CurrentContext when the Kubeconfig file contains only one context
This commit is contained in:
parent
6c4ad8c04d
commit
9de16f2c45
1 changed files with 5 additions and 1 deletions
|
@ -348,7 +348,11 @@ func inClusterConfig() (cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace
|
||||||
|
|
||||||
func currentContext(config *k8sapi.Config) (cluster k8sapi.Cluster, user k8sapi.AuthInfo, ns string, err error) {
|
func currentContext(config *k8sapi.Config) (cluster k8sapi.Cluster, user k8sapi.AuthInfo, ns string, err error) {
|
||||||
if config.CurrentContext == "" {
|
if config.CurrentContext == "" {
|
||||||
return cluster, user, "", errors.New("kubeconfig has no current context")
|
if len(config.Contexts) == 1 {
|
||||||
|
config.CurrentContext = config.Contexts[0].Name
|
||||||
|
} else {
|
||||||
|
return cluster, user, "", errors.New("kubeconfig has no current context")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
context, ok := func() (k8sapi.Context, bool) {
|
context, ok := func() (k8sapi.Context, bool) {
|
||||||
for _, namedContext := range config.Contexts {
|
for _, namedContext := range config.Contexts {
|
||||||
|
|
Loading…
Reference in a new issue