-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (49 loc) · 1.34 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
package main
import (
"os"
"os/signal"
"strings"
"syscall"
"time"
log "github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/kang-makes/cilium-nodeport-deleter/deleter"
)
func main() {
// Flag and environment parsing.
pflag.String("log-level", "info", "Log level (verbosity)")
pflag.String("cilium-url", "unix:///var/run/cilium/cilium.sock", "URL where to talk to cilium socket")
pflag.Parse()
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.SetEnvPrefix("NODEPORT_DELETER")
viper.AutomaticEnv()
if err := viper.BindPFlags(pflag.CommandLine); err != nil {
panic(err.Error())
}
// Logging
lvl, _ := log.ParseLevel(viper.GetString("log-level"))
log.SetLevel(lvl)
// Signal management
sigChan := make(chan os.Signal, 10)
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)
nodePortDeleter, err := deleter.New(viper.GetString("cilium-url"))
timer := time.NewTimer(10 * time.Second)
if err != nil {
log.Errorf("Unrecoverable error while deleting services: %v", err)
return
}
for {
err := nodePortDeleter.DeleteServices()
if err != nil {
log.Errorf("Error return by service deleter: %s", err)
}
select {
case signal := <-sigChan:
log.Printf("Caught %s, shutting down...", signal.String())
return
case <-timer.C:
timer.Reset(10 * time.Second)
}
}
}