forked from hooksie1/cmsnr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutating.go
56 lines (49 loc) · 1.39 KB
/
mutating.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
package cmd
import (
"os"
"github.com/gamer22026/cmsnr/pkg/server"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)
// mutatingCmd represents the mutating command
var mutatingCmd = &cobra.Command{
Use: "mutating",
Short: "Mutating starts the cmsnr mutating webhook",
Run: mutateServer,
}
func init() {
startCmd.AddCommand(mutatingCmd)
}
func mutateServer(cmd *cobra.Command, args []string) {
port := viper.GetInt("port")
registry := viper.GetString("registry")
log.Debugf("mutating webhook port: %d", port)
log.Info("setting up webhook server")
mgr, err := manager.New(config.GetConfigOrDie(), manager.Options{})
if err != nil {
log.Error(err)
os.Exit(1)
}
injector := server.SidecarInjector{
Client: mgr.GetClient(),
Namespace: namespace,
Registry: registry,
}
log.Info("setting up server")
mgrServer := mgr.GetWebhookServer()
mgrServer.Port = port
mgrServer.CertDir = "/var/lib/cmsnr"
mgrServer.Register("/mutate", &webhook.Admission{
Handler: &injector,
})
log.Info("starting webhook server")
if err := mgrServer.Start(signals.SetupSignalHandler()); err != nil {
log.Errorf("unable to start webhook server: %s", err)
os.Exit(1)
}
}