-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (51 loc) · 1.26 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
package main
import (
"flag"
"log"
"path/filepath"
"github.com/found-it/kube-informer/inform/controller"
"github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
)
type arguments struct {
kubeconfig string
incluster bool
}
func getArguments() arguments {
var args arguments
if home := homedir.HomeDir(); home != "" {
flag.StringVar(&args.kubeconfig, "kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
flag.StringVar(&args.kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.BoolVar(&args.incluster, "in-cluster", false, "Use in-cluster config")
flag.Parse()
return args
}
func main() {
logrus.Info("Shared Informer app started")
arg := getArguments()
var config *rest.Config
var err error
if arg.incluster {
config, err = rest.InClusterConfig()
if err != nil {
log.Panic(err.Error())
}
} else {
config, err = clientcmd.BuildConfigFromFlags("", arg.kubeconfig)
if err != nil {
log.Panic(err.Error())
}
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Panic(err.Error())
}
controller.
NewController(clientset, 0).
Run()
}