Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: v.oleynikov <vasily.oleynikov@flant.com>
  • Loading branch information
duckhawk committed Mar 22, 2024
1 parent 7455a6c commit 8d60a20
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions images/webhooks/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
corev1 "k8s.io/api/core/v1"
"net/http"
"os"
"webhooks/v1alpha1"
"webhooks/validators"
)

Expand Down Expand Up @@ -61,29 +62,51 @@ func main() {

cfg := initFlags()

mt := kwhmutating.MutatorFunc(validators.PodSchedulerMutation)
pscMF := kwhmutating.MutatorFunc(validators.PodSchedulerMutation)

mcfg := kwhmutating.WebhookConfig{
pscMCfg := kwhmutating.WebhookConfig{
ID: "PodSchedulerMutation",
Obj: &corev1.Pod{},
Mutator: mt,
Mutator: pscMF,
Logger: logger,
}
wh, err := kwhmutating.NewWebhook(mcfg)
pscWh, err := kwhmutating.NewWebhook(pscMCfg)
if err != nil {
fmt.Fprintf(os.Stderr, "error creating webhook: %s", err)
os.Exit(1)
}

// Get the handler for our webhook.
whHandler, err := kwhhttp.HandlerFor(kwhhttp.HandlerConfig{Webhook: wh, Logger: logger})
pscWhHandler, err := kwhhttp.HandlerFor(kwhhttp.HandlerConfig{Webhook: pscWh, Logger: logger})
if err != nil {
fmt.Fprintf(os.Stderr, "error creating webhook handler: %s", err)
os.Exit(1)
}

scuMF := kwhmutating.MutatorFunc(validators.StorageClassUpdate)

scuMCfg := kwhmutating.WebhookConfig{
ID: "StorageClassUpdate",
Obj: &v1alpha1.LocalStorageClass{},
Mutator: scuMF,
Logger: logger,
}
scuWh, err := kwhmutating.NewWebhook(scuMCfg)
if err != nil {
fmt.Fprintf(os.Stderr, "error creating webhook: %s", err)
os.Exit(1)
}

// Get the handler for our webhook.
scuWhHandler, err := kwhhttp.HandlerFor(kwhhttp.HandlerConfig{Webhook: scuWh, Logger: logger})
if err != nil {
fmt.Fprintf(os.Stderr, "error creating webhook handler: %s", err)
os.Exit(1)
}

mux := http.NewServeMux()
mux.Handle("/pod-scheduler-mutation", whHandler)
mux.Handle("/pod-scheduler-mutation", pscWhHandler)
mux.Handle("/storage-class-update", scuWhHandler)
mux.HandleFunc("/healthz", httpHandlerHealthz)

logger.Infof("Listening on %s", port)
Expand Down

0 comments on commit 8d60a20

Please sign in to comment.