-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (59 loc) · 1.33 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
61
62
63
64
65
66
67
68
69
package main
import (
"context"
"flag"
"github.com/zezaeoh/knurse/internal/config"
"github.com/zezaeoh/knurse/internal/webhook/cacerts"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/webhook/certificates"
"log"
"os"
"strconv"
"knative.dev/pkg/injection/sharedmain"
"knative.dev/pkg/signals"
"knative.dev/pkg/webhook"
)
const (
defaultWebhookSecretName = "knurse-tls"
defaultServiceName = "knurse"
defaultPort = 8443
)
// init initialize configs
func init() {
config.InitFlags(flag.CommandLine)
}
func main() {
wsn := os.Getenv("KNURSE_WEBHOOK_SECRET_NAME")
if wsn == "" {
wsn = defaultWebhookSecretName
}
sn := os.Getenv("KNURSE_SERVICE_NAME")
if sn == "" {
sn = defaultServiceName
}
port, err := strconv.Atoi(os.Getenv("KNURSE_WEBHOOK_PORT"))
if err != nil {
port = defaultPort
}
ctx := webhook.WithOptions(signals.NewContext(), webhook.Options{
ServiceName: sn,
Port: port,
SecretName: wsn,
})
sharedmain.MainWithContext(ctx, "knurse",
certificates.NewController,
caCertsAdmissionController,
)
}
func caCertsAdmissionController(ctx context.Context, _ configmap.Watcher) *controller.Impl {
cfg, err := config.LoadConfig()
if err != nil {
log.Fatalf("Fail to get config: %s", err)
}
return cacerts.NewAdmissionController(
ctx,
cfg,
nil,
)
}