-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (49 loc) · 1.74 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
package main
import (
"flag"
"log"
"time"
kubeInformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"github.com/ashwin901/social-book-operator/controller"
"github.com/ashwin901/social-book-operator/pkg/client/clientset/versioned"
"github.com/ashwin901/social-book-operator/pkg/client/informers/externalversions"
)
func main() {
configFile := flag.String("config", "/.kube/config", "kube config file path")
flag.Parse()
config, err := clientcmd.BuildConfigFromFlags("", *configFile)
if err != nil {
log.Printf("Error %s while building config for %s", err.Error(), *configFile)
// if there is an error, try to get config from inside the cluster
config, err = rest.InClusterConfig()
if err != nil {
log.Printf("Error %s while building config from inside the cluster", err.Error())
return
}
}
// kubernetes clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Printf("Error %s while creating clientset", err.Error())
return
}
// clientset from the generated code for the new group
customClientset, err := versioned.NewForConfig(config)
if err != nil {
log.Printf("Error %s while creating customm clientset: ", err.Error())
return
}
ch := make(chan struct{})
factory := kubeInformers.NewSharedInformerFactory(clientset, 10*time.Minute)
customFactory := externalversions.NewSharedInformerFactory(customClientset, 10*time.Minute)
// initializing controller
controller := controller.NewController(clientset, customClientset, customFactory.Operators().V1alpha1().SocialBooks(), factory)
// initialising all the requested informers
customFactory.Start(ch)
factory.Start(ch)
// start the controller
controller.Run(ch)
}