-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (40 loc) · 1.1 KB
/
main.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"flag"
"github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
"os"
"path/filepath"
// or
_ "k8s.io/client-go/plugin/pkg/client/auth"
)
var k8s *kubernetes.Clientset
func main() {
inCluster := os.Getenv("IN_CLUSTER")
var config *rest.Config
var err error
if inCluster == "true" {
config, err = rest.InClusterConfig()
} else {
var kubeconfig *string
if home := homedir.HomeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.Parse()
config, err = clientcmd.BuildConfigFromFlags("", *kubeconfig)
}
logrus.Debug("Connecting to cluster...")
k8s, err = kubernetes.NewForConfig(config)
if err != nil {
logrus.Debug("Connection failed!")
panic(err.Error())
}
logrus.Debug("Successfully connected!")
initTlsUpdater()
}