forked from mewil/tailscale-ingress-controller
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
47 lines (40 loc) · 892 Bytes
/
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
package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
func main() {
config, err := rest.InClusterConfig()
if err != nil {
log.Fatal("TIS: failed to get kubernetes config:", err)
}
client, err := kubernetes.NewForConfig(config)
if err != nil {
log.Fatal("TIS: failed to create kubernetes client", err)
}
tsAuthKey := os.Getenv("TS_AUTHKEY")
if tsAuthKey == "" {
log.Fatal("TIS: missing TS_AUTHKEY")
}
cHttp := NewHttpController(tsAuthKey)
cTcp := NewTcpController(tsAuthKey)
ctx, cancel := context.WithCancel(context.Background())
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-s
cHttp.shutdown()
cTcp.shutdown()
log.Println("shutting down")
cancel()
os.Exit(0)
}()
go cHttp.listen(ctx, client)
go cTcp.listen(ctx, client)
<-s
}