-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
94 lines (80 loc) · 2.84 KB
/
main.go
File metadata and controls
94 lines (80 loc) · 2.84 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"flag"
"os"
"time"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
)
var scheme = runtime.NewScheme()
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
}
func main() {
var (
metricsAddr string
probeAddr string
leaderElectionID string
notReadyThreshold time.Duration
reconcileInterval time.Duration
)
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&leaderElectionID, "leader-election-id", "node-taint-controller.example.com", "The ID of the leader election.")
flag.DurationVar(¬ReadyThreshold, "not-ready-threshold", 5*time.Minute, "Duration a node must be NotReady before tainting.")
flag.DurationVar(&reconcileInterval, "reconcile-interval", 30*time.Second, "How often to re-check node status.")
opts := zap.Options{Development: false}
opts.BindFlags(flag.CommandLine)
flag.Parse()
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
klog.SetLogger(ctrl.Log)
log := ctrl.Log.WithName("setup")
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Metrics: metricsserver.Options{BindAddress: metricsAddr},
HealthProbeBindAddress: probeAddr,
LeaderElection: true,
LeaderElectionID: leaderElectionID,
})
if err != nil {
log.Error(err, "unable to create manager")
os.Exit(1)
}
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
log.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
log.Error(err, "unable to set up ready check")
os.Exit(1)
}
notifier := NewNotifierFromEnv()
if notifier != nil {
log.Info("notifications enabled via SHOUTRRR_URLS")
}
reconciler := &NodeTaintReconciler{
Client: mgr.GetClient(),
NotReadyThreshold: notReadyThreshold,
ReconcileInterval: reconcileInterval,
NotReadySince: make(map[string]time.Time),
Notifier: notifier,
}
if err := ctrl.NewControllerManagedBy(mgr).
For(&corev1.Node{}).
Complete(reconciler); err != nil {
log.Error(err, "unable to create controller")
os.Exit(1)
}
log.Info("starting manager", "notReadyThreshold", notReadyThreshold, "reconcileInterval", reconcileInterval)
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
log.Error(err, "problem running manager")
os.Exit(1)
}
}