-
Notifications
You must be signed in to change notification settings - Fork 62
/
main.go
59 lines (47 loc) · 1.29 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
//go:generate go run pkg/codegen/cleanup/main.go
//go:generate go run ./pkg/codegen
package main
import (
"fmt"
"os"
"github.com/rancher/webhook/pkg/server"
_ "github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io"
"github.com/rancher/wrangler/v3/pkg/k8scheck"
"github.com/rancher/wrangler/v3/pkg/kubeconfig"
"github.com/rancher/wrangler/v3/pkg/ratelimit"
"github.com/rancher/wrangler/v3/pkg/signals"
"github.com/sirupsen/logrus"
)
var (
Version = "dev"
GitCommit = "HEAD"
)
func main() {
if err := run(); err != nil {
logrus.Fatal(err)
}
}
func run() error {
if os.Getenv("CATTLE_DEBUG") == "true" || os.Getenv("RANCHER_DEBUG") == "true" {
logrus.SetLevel(logrus.DebugLevel)
}
if os.Getenv("CATTLE_TRACE") == "true" {
logrus.SetLevel(logrus.TraceLevel)
}
logrus.Infof("Rancher-webhook version %s is starting", fmt.Sprintf("%s (%s)", Version, GitCommit))
cfg, err := kubeconfig.GetNonInteractiveClientConfig(os.Getenv("KUBECONFIG")).ClientConfig()
if err != nil {
return err
}
cfg.RateLimiter = ratelimit.None
ctx := signals.SetupSignalContext()
err = k8scheck.Wait(ctx, *cfg)
if err != nil {
return err
}
if err := server.ListenAndServe(ctx, cfg, os.Getenv("ENABLE_MCM") != "false"); err != nil {
return err
}
<-ctx.Done()
return nil
}