-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (42 loc) · 1.23 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
package main
import (
"net/http"
"os"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)
func init() {
log.SetLogger(zap.New(zap.UseDevMode(true)))
}
func main() {
entryLog := log.Log.WithName("entrypoint")
options := manager.Options{}
mgr, err := manager.New(config.GetConfigOrDie(), options)
if err != nil {
entryLog.Error(err, "unable to set up overall controller manager")
os.Exit(1)
}
entryLog.Info("setting up webhook server")
hookServer := mgr.GetWebhookServer()
endpoint := &webhook.Admission{
Handler: &networkHealthSidecarInjector{
Client: mgr.GetClient(),
},
}
hookServer.Register("/webhook", endpoint)
hookServer.WebhookMux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("ok"))
if err != nil {
entryLog.Error(err, "unable to write health check response")
}
})
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
entryLog.Error(err, "unable to run manager")
os.Exit(1)
}
}