-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (54 loc) · 1.78 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"flag"
"time"
"github.com/golang/glog"
// If new flags are needed this will need to be reconfigured
flags "k8s.io/ingress-gce/pkg/flags"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
// this package is only need for authing with CKE clusters.
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)
func main() {
flags.Register()
flag.Parse()
stopCh := make(chan struct{})
config, err := determineConfig()
if err != nil {
glog.Fatalf("Error building kubeconfig: %s", err.Error())
return
}
kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
glog.Fatalf("Error building kubernetes clientset: %s", err.Error())
}
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30)
controller := NewController(kubeClient, kubeInformerFactory)
go kubeInformerFactory.Start(stopCh)
if err = controller.Run(2, stopCh); err != nil {
glog.Fatalf("Error running controller: %s", err.Error())
}
}
// determineConfig determines if we are running in a cluster or out side
// and gets the appropriate configuration to talk with kubernetes
func determineConfig() (*rest.Config, error) {
var config *rest.Config
var err error
// determine whether to use in cluster config or out of cluster config
// if kuebconfigPath is not specified, default to in cluster config
// otherwise, use out of cluster config
if flags.F.KubeConfigFile == "" {
glog.Info("Using in cluster k8s config")
config, err = rest.InClusterConfig()
} else {
glog.Info("Using out of cluster k8s config:", flags.F.KubeConfigFile)
config, err = clientcmd.BuildConfigFromFlags("", flags.F.KubeConfigFile)
}
if err != nil {
return nil, err
}
return config, nil
}