-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
74 lines (65 loc) · 1.57 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
71
72
73
74
package main
import (
"flag"
nodeporthandler "github.com/crc-org/routes-controller/pkg/node-port-handler"
routeshandler "github.com/crc-org/routes-controller/pkg/routes-handler"
routeclientset "github.com/openshift/client-go/route/clientset/versioned"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"os"
"os/signal"
"syscall"
)
var (
master string
kubeconfig string
debug bool
)
func main() {
// setup args
flag.BoolVar(&debug, "debug", false, "Print debug info")
flag.StringVar(&master, "master", "", "master url")
flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
flag.Parse()
// setup logging
if debug {
log.SetLevel(log.DebugLevel)
}
// build config
config, err := clientcmd.BuildConfigFromFlags(master, kubeconfig)
if err != nil {
log.Fatal(err)
return
}
// setup informer stop channel
stop := make(chan struct{})
defer close(stop)
// run node port handler
nodePortClientSet, err := kubernetes.NewForConfig(config)
if err != nil {
log.Fatal(err)
return
}
nodePortHandler := nodeporthandler.NodePortHandler(nodePortClientSet)
go func() {
nodePortHandler.Run(stop)
}()
// run routes handler
routesClientSet, err := routeclientset.NewForConfig(config)
if err != nil {
log.Fatal(err)
return
}
routePortHandler := routeshandler.RoutesHandler(routesClientSet)
go func() {
routePortHandler.Run(stop)
}()
// block until sigterm
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, syscall.SIGTERM)
select {
case <-signalCh:
return
}
}