forked from flaccid/kunsul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
35 lines (27 loc) · 845 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package kunsul
import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
log "github.com/sirupsen/logrus"
)
var err error
func GetConfig() (config *rest.Config, err error) {
log.Debugf("KUBE:> %s","try using in-cluster authentication")
if config, err = rest.InClusterConfig(); err != nil {
if err != rest.ErrNotInCluster {
log.Error(err)
return nil, err
}
}
// else not in cluster
log.Debugf("KUBE:> %s","try outside-cluster authentication")
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
configOverrides := &clientcmd.ConfigOverrides{}
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
if config, err = kubeConfig.ClientConfig(); err != nil {
log.Error(err)
return nil, err
}
log.Debugf("CONFIG:> %s", config)
return config, nil
}