/
webhook.go
36 lines (32 loc) · 972 Bytes
/
webhook.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
package main
import (
"context"
"github.com/istio-conductor/istiofilter/pkg/patch"
"github.com/istio-conductor/istiofilter/pkg/store/informer"
"github.com/istio-conductor/istiofilter/webhook"
"github.com/sirupsen/logrus"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)
type Config struct {
Port int `json:"port"`
CertFile string `json:"certFile"`
KeyFile string `json:"keyFile"`
PrivilegeNamespaces []string `json:"privilegeNamespaces"`
}
func Serve(ctx context.Context, c *Config) error {
logrus.Debug("begin webhook serve")
cfg, err := config.GetConfig()
if err != nil {
return err
}
logrus.Debug("create informer store")
store, err := informer.New(c.PrivilegeNamespaces, cfg)
if err != nil {
return err
}
store.Start(ctx.Done())
logrus.Debug("create patcher")
patcher := patch.New(store)
logrus.Debug("webhook running")
return webhook.Run(ctx, c.Port, c.CertFile, c.KeyFile, patcher)
}