-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (59 loc) · 1.83 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"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"log"
clientset "gitweb/pkg/client/clientset/versioned"
"k8s.io/client-go/informers"
pwinformers "gitweb/pkg/client/informers/externalversions"
kubeinformers "k8s.io/client-go/informers"
"gitweb/pkg"
"os/signal"
"os"
"syscall"
)
var (
masterURL string
kubeconfig string
)
func main() {
flag.Parse()
stopCh := SetupSignalHandler()
kubeConfigPath := "/Users/sijie/.kube/config"
cfg,err := clientcmd.BuildConfigFromFlags(masterURL,kubeConfigPath)
if err != nil {
log.Fatal("Error building kubeconfig: %s", err.Error())
}
kubeclient := kubernetes.NewForConfigOrDie(cfg)
gwclient,err := clientset.NewForConfig(cfg)
if err != nil {
log.Fatal("Error building example clientset: %s", err.Error())
}
informerFactory := informers.NewSharedInformerFactoryWithOptions(kubeclient, 0, informers.WithTweakListOptions(func(opt *metav1.ListOptions) {
}))
informerFactory = kubeinformers.NewSharedInformerFactory(kubeclient, time.Second*30)
podInformer := informerFactory.Core().V1().Pods()
gwInformerFactory := pwinformers.NewSharedInformerFactory(gwclient,time.Second*30)
controller := pkg.NewGitWebController(kubeclient,gwInformerFactory.Samplecrd().V1().Foos(),podInformer,gwclient)
go gwInformerFactory.Start(stopCh)
go informerFactory.Start(stopCh)
controller.Run(stopCh)
}
var onlyOneSignalHandler = make(chan struct{})
var shutdownSignals = []os.Signal{os.Interrupt, syscall.SIGTERM}
func SetupSignalHandler() (stopCh <-chan struct{}) {
close(onlyOneSignalHandler) // panics when called twice
stop := make(chan struct{})
c := make(chan os.Signal, 2)
signal.Notify(c, shutdownSignals...)
go func() {
<-c
close(stop)
<-c
os.Exit(1) // second signal. Exit directly.
}()
return stop
}