-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
48 lines (37 loc) · 990 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
48
package main
import (
"math/rand"
"os"
"os/signal"
"strings"
"time"
"k8s.io/component-base/logs"
"k8s.io/klog/v2"
_ "k8s.io/component-base/metrics/prometheus/clientgo" // load all the prometheus client-go plugins
_ "k8s.io/component-base/metrics/prometheus/version" // for version metric registration
)
func main() {
rand.Seed(time.Now().UnixNano())
logs.InitLogs()
defer logs.FlushLogs()
cloud, err := newCloud()
if err != nil {
klog.ErrorS(err, "hcloud-connect failed")
os.Exit(1)
}
// on start register with the load balancer
err = cloud.Register()
if err != nil && !strings.Contains(err.Error(), "target_already_defined") {
klog.ErrorS(err, "hcloud-connect failed")
os.Exit(1)
}
klog.InfoS("hcloud-connect waiting for shutdown...")
// wait for stop signal then unregister
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
if err := cloud.Deregister(); err != nil {
klog.ErrorS(err, "hcloud-connect failed")
os.Exit(1)
}
}