-
Notifications
You must be signed in to change notification settings - Fork 8
/
kubernetes-deployment-restart-controller.go
52 lines (41 loc) · 1.98 KB
/
kubernetes-deployment-restart-controller.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
package main
import (
"fmt"
"net/http"
"os"
"runtime"
"time"
"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/xing/kubernetes-deployment-restart-controller/src/controller"
"github.com/xing/kubernetes-deployment-restart-controller/src/util"
)
var options struct {
RestartCheckPeriod int `short:"c" long:"restart-check-period" env:"RESTART_CHECK_PERIOD" description:"Time interval to check for pending restarts in milliseconds" default:"500"`
RestartGracePeriod int `short:"r" long:"restart-grace-period" env:"RESTART_GRACE_PERIOD" description:"Time interval to compact restarts in seconds" default:"5"`
IgnoredErrors []string `long:"ignored-errors" env:"IGNORED_ERRORS" env-delim:";" description:"List of error patterns to just warn of, instead of exiting the controller. Useful if previously legal objects are not valid anymore but have not yet been updated, e.g. on admission control changes. ENV var splits on ; (semicolon)."`
Verbose int `short:"v" long:"verbose" env:"VERBOSE" description:"Be verbose"`
Version bool `long:"version" description:"Print version information and exit"`
}
// VERSION represents the current version of the release.
const VERSION = "v1.3.0"
func main() {
util.ParseArgs(&options)
if options.Version {
printVersion()
return
}
http.Handle("/metrics", promhttp.Handler())
addr := fmt.Sprintf("0.0.0.0:10254")
go func() { glog.Fatal(http.ListenAndServe(addr, nil)) }()
controller := controller.NewDeploymentConfigController(time.Duration(options.RestartCheckPeriod)*time.Millisecond, time.Duration(options.RestartGracePeriod)*time.Second, options.IgnoredErrors)
util.InstallSignalHandler(controller.Stop)
err := controller.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "Controller terminated: %s", err)
os.Exit(1)
}
}
func printVersion() {
fmt.Printf("kubernetes-deployment-restart-controller %s %s/%s %s\n", VERSION, runtime.GOOS, runtime.GOARCH, runtime.Version())
}