2019-05-13 21:33:01 +03:00
|
|
|
package webhooks
|
2019-02-07 19:22:04 +02:00
|
|
|
|
|
|
|
import (
|
2019-03-04 20:40:02 +02:00
|
|
|
"context"
|
|
|
|
"crypto/tls"
|
2023-11-17 15:19:53 +01:00
|
|
|
"fmt"
|
2019-03-04 20:40:02 +02:00
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2020-03-17 11:05:20 -07:00
|
|
|
"github.com/go-logr/logr"
|
2020-04-27 18:38:03 +05:30
|
|
|
"github.com/julienschmidt/httprouter"
|
2023-07-31 16:51:23 +02:00
|
|
|
"github.com/kyverno/kyverno/api/kyverno"
|
2023-04-04 12:23:20 +02:00
|
|
|
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
2020-10-07 11:12:31 -07:00
|
|
|
"github.com/kyverno/kyverno/pkg/config"
|
2022-10-19 15:12:55 +02:00
|
|
|
"github.com/kyverno/kyverno/pkg/logging"
|
2022-11-09 11:52:20 +01:00
|
|
|
"github.com/kyverno/kyverno/pkg/metrics"
|
2022-09-06 17:43:04 +02:00
|
|
|
"github.com/kyverno/kyverno/pkg/toggle"
|
2022-10-12 08:52:42 +02:00
|
|
|
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
|
|
|
|
runtimeutils "github.com/kyverno/kyverno/pkg/utils/runtime"
|
2022-03-31 17:34:10 +02:00
|
|
|
"github.com/kyverno/kyverno/pkg/webhooks/handlers"
|
2022-04-06 22:43:07 +02:00
|
|
|
admissionv1 "k8s.io/api/admission/v1"
|
2022-10-12 08:52:42 +02:00
|
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2023-02-15 10:37:36 +01:00
|
|
|
rbacv1listers "k8s.io/client-go/listers/rbac/v1"
|
2019-02-07 19:22:04 +02:00
|
|
|
)
|
|
|
|
|
2022-05-16 16:36:21 +02:00
|
|
|
type Server interface {
|
|
|
|
// Run TLS server in separate thread and returns control immediately
|
2024-01-31 00:08:15 +02:00
|
|
|
Run()
|
2022-05-16 16:36:21 +02:00
|
|
|
// Stop TLS server and returns control after the server is shut down
|
2023-01-12 12:47:40 +08:00
|
|
|
Stop()
|
2022-05-16 16:36:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type server struct {
|
2022-10-12 08:52:42 +02:00
|
|
|
server *http.Server
|
|
|
|
runtime runtimeutils.Runtime
|
2023-06-22 13:12:36 +02:00
|
|
|
mwcClient controllerutils.DeleteCollectionClient
|
|
|
|
vwcClient controllerutils.DeleteCollectionClient
|
|
|
|
leaseClient controllerutils.DeleteClient
|
2019-03-04 20:40:02 +02:00
|
|
|
}
|
|
|
|
|
2022-05-16 16:36:21 +02:00
|
|
|
type TlsProvider func() ([]byte, []byte, error)
|
|
|
|
|
|
|
|
// NewServer creates new instance of server accordingly to given configuration
|
|
|
|
func NewServer(
|
2023-06-12 17:36:12 +02:00
|
|
|
ctx context.Context,
|
2022-09-26 17:55:46 +02:00
|
|
|
policyHandlers PolicyHandlers,
|
|
|
|
resourceHandlers ResourceHandlers,
|
2022-12-15 10:53:22 +01:00
|
|
|
exceptionHandlers ExceptionHandlers,
|
2025-02-05 17:01:11 +02:00
|
|
|
celExceptionHandlers CELExceptionHandlers,
|
2024-02-02 22:34:50 +05:30
|
|
|
globalContextHandlers GlobalContextHandlers,
|
2022-05-16 16:36:21 +02:00
|
|
|
configuration config.Configuration,
|
2022-11-30 14:37:53 +01:00
|
|
|
metricsConfig metrics.MetricsConfigManager,
|
2022-10-21 17:17:49 +01:00
|
|
|
debugModeOpts DebugModeOptions,
|
2022-10-12 08:52:42 +02:00
|
|
|
tlsProvider TlsProvider,
|
2023-06-22 13:12:36 +02:00
|
|
|
mwcClient controllerutils.DeleteCollectionClient,
|
|
|
|
vwcClient controllerutils.DeleteCollectionClient,
|
|
|
|
leaseClient controllerutils.DeleteClient,
|
2022-10-12 08:52:42 +02:00
|
|
|
runtime runtimeutils.Runtime,
|
2023-02-15 10:37:36 +01:00
|
|
|
rbLister rbacv1listers.RoleBindingLister,
|
|
|
|
crbLister rbacv1listers.ClusterRoleBindingLister,
|
2023-04-04 12:23:20 +02:00
|
|
|
discovery dclient.IDiscovery,
|
2023-11-17 15:19:53 +01:00
|
|
|
webhookServerPort int32,
|
2022-05-16 16:36:21 +02:00
|
|
|
) Server {
|
2020-04-27 18:38:03 +05:30
|
|
|
mux := httprouter.New()
|
2022-05-16 16:36:21 +02:00
|
|
|
resourceLogger := logger.WithName("resource")
|
|
|
|
policyLogger := logger.WithName("policy")
|
2022-12-15 09:34:44 +01:00
|
|
|
exceptionLogger := logger.WithName("exception")
|
2025-02-05 17:01:11 +02:00
|
|
|
celExceptionLogger := logger.WithName("cel-exception")
|
2024-02-02 22:34:50 +05:30
|
|
|
globalContextLogger := logger.WithName("globalcontext")
|
2022-05-16 16:36:21 +02:00
|
|
|
verifyLogger := logger.WithName("verify")
|
2025-01-28 10:06:30 +01:00
|
|
|
vpolLogger := logger.WithName("vpol")
|
|
|
|
registerWebhookHandlersWithAll(
|
2022-11-23 07:50:55 +01:00
|
|
|
mux,
|
|
|
|
"MUTATE",
|
|
|
|
config.MutatingWebhookServicePath,
|
2025-02-04 13:52:48 +01:00
|
|
|
resourceHandlers.Mutation,
|
2022-11-25 09:58:13 +01:00
|
|
|
func(handler handlers.AdmissionHandler) handlers.HttpHandler {
|
|
|
|
return handler.
|
|
|
|
WithFilter(configuration).
|
2023-06-12 17:36:12 +02:00
|
|
|
WithProtection(toggle.FromContext(ctx).ProtectManagedResources()).
|
2023-04-04 12:23:20 +02:00
|
|
|
WithDump(debugModeOpts.DumpPayload).
|
|
|
|
WithTopLevelGVK(discovery).
|
|
|
|
WithRoles(rbLister, crbLister).
|
2022-11-25 09:58:13 +01:00
|
|
|
WithOperationFilter(admissionv1.Create, admissionv1.Update, admissionv1.Connect).
|
2022-11-30 14:37:53 +01:00
|
|
|
WithMetrics(resourceLogger, metricsConfig.Config(), metrics.WebhookMutating).
|
2022-11-25 09:58:13 +01:00
|
|
|
WithAdmission(resourceLogger.WithName("mutate"))
|
|
|
|
},
|
2022-11-23 07:50:55 +01:00
|
|
|
)
|
2025-01-28 10:06:30 +01:00
|
|
|
registerWebhookHandlersWithAll(
|
2022-11-23 07:50:55 +01:00
|
|
|
mux,
|
|
|
|
"VALIDATE",
|
|
|
|
config.ValidatingWebhookServicePath,
|
2025-02-04 13:52:48 +01:00
|
|
|
resourceHandlers.Validation,
|
2022-11-25 09:58:13 +01:00
|
|
|
func(handler handlers.AdmissionHandler) handlers.HttpHandler {
|
|
|
|
return handler.
|
|
|
|
WithFilter(configuration).
|
2023-06-12 17:36:12 +02:00
|
|
|
WithProtection(toggle.FromContext(ctx).ProtectManagedResources()).
|
2023-04-04 12:23:20 +02:00
|
|
|
WithDump(debugModeOpts.DumpPayload).
|
|
|
|
WithTopLevelGVK(discovery).
|
|
|
|
WithRoles(rbLister, crbLister).
|
2022-11-30 14:37:53 +01:00
|
|
|
WithMetrics(resourceLogger, metricsConfig.Config(), metrics.WebhookValidating).
|
2022-11-25 09:58:13 +01:00
|
|
|
WithAdmission(resourceLogger.WithName("validate"))
|
|
|
|
},
|
2022-11-23 07:50:55 +01:00
|
|
|
)
|
2025-01-28 10:06:30 +01:00
|
|
|
registerWebhookHandlers(
|
|
|
|
mux,
|
|
|
|
"VPOL",
|
|
|
|
config.ValidatingPolicyServicePath,
|
2025-02-04 13:52:48 +01:00
|
|
|
resourceHandlers.ValidatingPolicies,
|
2025-01-28 10:06:30 +01:00
|
|
|
func(handler handlers.AdmissionHandler) handlers.HttpHandler {
|
|
|
|
return handler.
|
|
|
|
WithFilter(configuration).
|
|
|
|
WithProtection(toggle.FromContext(ctx).ProtectManagedResources()).
|
|
|
|
WithDump(debugModeOpts.DumpPayload).
|
|
|
|
WithTopLevelGVK(discovery).
|
|
|
|
WithRoles(rbLister, crbLister).
|
2025-02-04 13:52:48 +01:00
|
|
|
WithMetrics(resourceLogger, metricsConfig.Config(), metrics.WebhookValidating).
|
2025-01-28 10:06:30 +01:00
|
|
|
WithAdmission(vpolLogger.WithName("validate"))
|
|
|
|
},
|
|
|
|
)
|
2022-11-09 11:52:20 +01:00
|
|
|
mux.HandlerFunc(
|
|
|
|
"POST",
|
|
|
|
config.PolicyMutatingWebhookServicePath,
|
2025-02-04 13:52:48 +01:00
|
|
|
handlerFunc("MUTATE", policyHandlers.Mutation, "").
|
2023-04-04 12:23:20 +02:00
|
|
|
WithDump(debugModeOpts.DumpPayload).
|
2022-11-30 14:37:53 +01:00
|
|
|
WithMetrics(policyLogger, metricsConfig.Config(), metrics.WebhookMutating).
|
2022-11-23 07:50:55 +01:00
|
|
|
WithAdmission(policyLogger.WithName("mutate")).
|
2023-08-24 08:45:58 +02:00
|
|
|
ToHandlerFunc("MUTATE"),
|
2022-11-09 11:52:20 +01:00
|
|
|
)
|
|
|
|
mux.HandlerFunc(
|
|
|
|
"POST",
|
|
|
|
config.PolicyValidatingWebhookServicePath,
|
2025-02-04 13:52:48 +01:00
|
|
|
handlerFunc("VALIDATE", policyHandlers.Validation, "").
|
2023-04-04 12:23:20 +02:00
|
|
|
WithDump(debugModeOpts.DumpPayload).
|
2022-11-25 09:58:13 +01:00
|
|
|
WithSubResourceFilter().
|
2022-11-30 14:37:53 +01:00
|
|
|
WithMetrics(policyLogger, metricsConfig.Config(), metrics.WebhookValidating).
|
2022-11-23 07:50:55 +01:00
|
|
|
WithAdmission(policyLogger.WithName("validate")).
|
2023-08-24 08:45:58 +02:00
|
|
|
ToHandlerFunc("VALIDATE"),
|
2022-11-09 11:52:20 +01:00
|
|
|
)
|
2022-12-15 09:34:44 +01:00
|
|
|
mux.HandlerFunc(
|
|
|
|
"POST",
|
|
|
|
config.ExceptionValidatingWebhookServicePath,
|
2025-02-04 13:52:48 +01:00
|
|
|
handlerFunc("VALIDATE", exceptionHandlers.Validation, "").
|
2023-04-04 12:23:20 +02:00
|
|
|
WithDump(debugModeOpts.DumpPayload).
|
2022-12-15 09:34:44 +01:00
|
|
|
WithSubResourceFilter().
|
|
|
|
WithMetrics(exceptionLogger, metricsConfig.Config(), metrics.WebhookValidating).
|
|
|
|
WithAdmission(exceptionLogger.WithName("validate")).
|
2023-08-24 08:45:58 +02:00
|
|
|
ToHandlerFunc("VALIDATE"),
|
2022-12-15 09:34:44 +01:00
|
|
|
)
|
2025-02-05 17:01:11 +02:00
|
|
|
mux.HandlerFunc(
|
|
|
|
"POST",
|
|
|
|
config.CELExceptionValidatingWebhookServicePath,
|
|
|
|
handlerFunc("VALIDATE", celExceptionHandlers.Validation, "").
|
|
|
|
WithDump(debugModeOpts.DumpPayload).
|
|
|
|
WithSubResourceFilter().
|
|
|
|
WithMetrics(celExceptionLogger, metricsConfig.Config(), metrics.WebhookValidating).
|
|
|
|
WithAdmission(celExceptionLogger.WithName("validate")).
|
|
|
|
ToHandlerFunc("VALIDATE"),
|
|
|
|
)
|
2024-02-02 22:34:50 +05:30
|
|
|
mux.HandlerFunc(
|
|
|
|
"POST",
|
|
|
|
config.GlobalContextValidatingWebhookServicePath,
|
2025-02-04 13:52:48 +01:00
|
|
|
handlerFunc("VALIDATE", globalContextHandlers.Validation, "").
|
2024-02-02 22:34:50 +05:30
|
|
|
WithDump(debugModeOpts.DumpPayload).
|
|
|
|
WithSubResourceFilter().
|
|
|
|
WithMetrics(globalContextLogger, metricsConfig.Config(), metrics.WebhookValidating).
|
|
|
|
WithAdmission(globalContextLogger.WithName("validate")).
|
|
|
|
ToHandlerFunc("VALIDATE"),
|
|
|
|
)
|
2022-11-09 11:52:20 +01:00
|
|
|
mux.HandlerFunc(
|
|
|
|
"POST",
|
|
|
|
config.VerifyMutatingWebhookServicePath,
|
2022-11-23 07:50:55 +01:00
|
|
|
handlers.FromAdmissionFunc("VERIFY", handlers.Verify).
|
|
|
|
WithAdmission(verifyLogger.WithName("mutate")).
|
2023-08-24 08:45:58 +02:00
|
|
|
ToHandlerFunc("VERIFY"),
|
2022-11-09 11:52:20 +01:00
|
|
|
)
|
2022-10-12 08:52:42 +02:00
|
|
|
mux.HandlerFunc("GET", config.LivenessServicePath, handlers.Probe(runtime.IsLive))
|
|
|
|
mux.HandlerFunc("GET", config.ReadinessServicePath, handlers.Probe(runtime.IsReady))
|
2022-05-16 16:36:21 +02:00
|
|
|
return &server{
|
|
|
|
server: &http.Server{
|
2023-11-17 15:19:53 +01:00
|
|
|
Addr: fmt.Sprintf(":%d", webhookServerPort),
|
2022-05-16 16:36:21 +02:00
|
|
|
TLSConfig: &tls.Config{
|
|
|
|
GetCertificate: func(*tls.ClientHelloInfo) (*tls.Certificate, error) {
|
|
|
|
certPem, keyPem, err := tlsProvider()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
pair, err := tls.X509KeyPair(certPem, keyPem)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &pair, nil
|
|
|
|
},
|
|
|
|
MinVersion: tls.VersionTLS12,
|
2023-05-26 15:15:12 +02:00
|
|
|
CipherSuites: []uint16{
|
|
|
|
// AEADs w/ ECDHE
|
|
|
|
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
|
|
|
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
|
|
|
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
|
|
|
|
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
|
|
|
|
},
|
2022-05-10 11:55:39 +02:00
|
|
|
},
|
2022-08-24 15:08:24 +02:00
|
|
|
Handler: mux,
|
|
|
|
ReadTimeout: 30 * time.Second,
|
|
|
|
WriteTimeout: 30 * time.Second,
|
|
|
|
ReadHeaderTimeout: 30 * time.Second,
|
2022-10-19 14:09:04 +02:00
|
|
|
IdleTimeout: 5 * time.Minute,
|
2022-10-19 15:12:55 +02:00
|
|
|
ErrorLog: logging.StdLogger(logger.WithName("server"), ""),
|
2022-05-10 11:55:39 +02:00
|
|
|
},
|
2022-10-12 08:52:42 +02:00
|
|
|
mwcClient: mwcClient,
|
|
|
|
vwcClient: vwcClient,
|
|
|
|
leaseClient: leaseClient,
|
|
|
|
runtime: runtime,
|
2019-03-04 20:40:02 +02:00
|
|
|
}
|
2019-02-21 20:31:18 +02:00
|
|
|
}
|
|
|
|
|
2024-01-31 00:08:15 +02:00
|
|
|
func (s *server) Run() {
|
2022-05-16 16:36:21 +02:00
|
|
|
go func() {
|
2024-01-31 00:08:15 +02:00
|
|
|
if err := s.server.ListenAndServeTLS("", ""); err != nil {
|
|
|
|
logging.Error(err, "failed to start server")
|
2022-05-05 14:06:18 -07:00
|
|
|
}
|
2022-05-16 16:36:21 +02:00
|
|
|
}()
|
2021-07-09 18:01:46 -07:00
|
|
|
}
|
2021-03-23 10:34:03 -07:00
|
|
|
|
2023-01-12 12:47:40 +08:00
|
|
|
func (s *server) Stop() {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
|
|
defer cancel()
|
2022-07-27 16:45:06 +08:00
|
|
|
s.cleanup(ctx)
|
2022-05-16 16:36:21 +02:00
|
|
|
err := s.server.Shutdown(ctx)
|
2022-05-05 14:06:18 -07:00
|
|
|
if err != nil {
|
2022-05-16 16:36:21 +02:00
|
|
|
logger.Error(err, "shutting down server")
|
|
|
|
err = s.server.Close()
|
2022-05-05 14:06:18 -07:00
|
|
|
if err != nil {
|
2022-05-16 16:36:21 +02:00
|
|
|
logger.Error(err, "server shut down failed")
|
2022-05-05 14:06:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-27 16:45:06 +08:00
|
|
|
func (s *server) cleanup(ctx context.Context) {
|
2022-10-12 08:52:42 +02:00
|
|
|
if s.runtime.IsGoingDown() {
|
|
|
|
deleteLease := func(name string) {
|
|
|
|
if err := s.leaseClient.Delete(ctx, name, metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
|
|
|
|
logger.Error(err, "failed to clean up lease", "name", name)
|
2024-09-04 16:29:59 +05:30
|
|
|
} else if err == nil {
|
2025-02-13 20:32:02 +05:30
|
|
|
logger.V(2).Info("successfully deleted leases", "label", kyverno.LabelWebhookManagedBy)
|
2022-10-12 08:52:42 +02:00
|
|
|
}
|
|
|
|
}
|
2023-01-12 12:47:40 +08:00
|
|
|
deleteVwc := func() {
|
|
|
|
if err := s.vwcClient.DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{
|
2023-07-31 16:51:23 +02:00
|
|
|
LabelSelector: kyverno.LabelWebhookManagedBy,
|
2023-01-12 12:47:40 +08:00
|
|
|
}); err != nil && !apierrors.IsNotFound(err) {
|
2023-07-31 16:51:23 +02:00
|
|
|
logger.Error(err, "failed to clean up validating webhook configuration", "label", kyverno.LabelWebhookManagedBy)
|
2024-09-04 16:29:59 +05:30
|
|
|
} else if err == nil {
|
2025-02-13 20:32:02 +05:30
|
|
|
logger.V(2).Info("successfully deleted validating webhook configurations", "label", kyverno.LabelWebhookManagedBy)
|
2022-10-12 08:52:42 +02:00
|
|
|
}
|
|
|
|
}
|
2023-01-12 12:47:40 +08:00
|
|
|
deleteMwc := func() {
|
|
|
|
if err := s.mwcClient.DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{
|
2023-07-31 16:51:23 +02:00
|
|
|
LabelSelector: kyverno.LabelWebhookManagedBy,
|
2023-01-12 12:47:40 +08:00
|
|
|
}); err != nil && !apierrors.IsNotFound(err) {
|
2023-07-31 16:51:23 +02:00
|
|
|
logger.Error(err, "failed to clean up mutating webhook configuration", "label", kyverno.LabelWebhookManagedBy)
|
2024-09-04 16:29:59 +05:30
|
|
|
} else if err == nil {
|
2025-02-13 20:32:02 +05:30
|
|
|
logger.V(2).Info("successfully deleted mutating webhook configurations", "label", kyverno.LabelWebhookManagedBy)
|
2022-10-12 08:52:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
deleteLease("kyvernopre-lock")
|
2022-11-03 10:19:38 +00:00
|
|
|
deleteLease("kyverno-health")
|
2023-01-12 12:47:40 +08:00
|
|
|
deleteVwc()
|
|
|
|
deleteMwc()
|
2022-10-12 08:52:42 +02:00
|
|
|
}
|
2022-07-27 16:45:06 +08:00
|
|
|
}
|
|
|
|
|
2022-09-26 17:55:46 +02:00
|
|
|
func registerWebhookHandlers(
|
|
|
|
mux *httprouter.Router,
|
2022-11-23 07:50:55 +01:00
|
|
|
name string,
|
2022-09-26 17:55:46 +02:00
|
|
|
basePath string,
|
2025-02-04 13:52:48 +01:00
|
|
|
handler Handler,
|
2022-11-25 09:58:13 +01:00
|
|
|
builder func(handler handlers.AdmissionHandler) handlers.HttpHandler,
|
2022-09-26 17:55:46 +02:00
|
|
|
) {
|
2025-02-04 13:52:48 +01:00
|
|
|
ignore := handlerFunc(name, handler, "ignore")
|
|
|
|
fail := handlerFunc(name, handler, "fail")
|
2023-08-24 08:45:58 +02:00
|
|
|
mux.HandlerFunc("POST", basePath+"/ignore", builder(ignore).ToHandlerFunc(name))
|
|
|
|
mux.HandlerFunc("POST", basePath+"/fail", builder(fail).ToHandlerFunc(name))
|
2024-01-27 21:00:22 +08:00
|
|
|
mux.HandlerFunc("POST", basePath+"/ignore"+config.FineGrainedWebhookPath+"/*policy", builder(ignore).ToHandlerFunc(name))
|
|
|
|
mux.HandlerFunc("POST", basePath+"/fail"+config.FineGrainedWebhookPath+"/*policy", builder(fail).ToHandlerFunc(name))
|
2022-09-26 17:55:46 +02:00
|
|
|
}
|
2025-01-28 10:06:30 +01:00
|
|
|
|
|
|
|
func registerWebhookHandlersWithAll(
|
|
|
|
mux *httprouter.Router,
|
|
|
|
name string,
|
|
|
|
basePath string,
|
2025-02-04 13:52:48 +01:00
|
|
|
handler Handler,
|
2025-01-28 10:06:30 +01:00
|
|
|
builder func(handler handlers.AdmissionHandler) handlers.HttpHandler,
|
|
|
|
) {
|
2025-02-04 13:52:48 +01:00
|
|
|
all := handlerFunc(name, handler, "all")
|
|
|
|
mux.HandlerFunc("POST", basePath, builder(all).ToHandlerFunc(name))
|
|
|
|
registerWebhookHandlers(mux, name, basePath, handler, builder)
|
|
|
|
}
|
|
|
|
|
|
|
|
func handlerFunc(name string, handler Handler, failurePolicy string) handlers.AdmissionHandler {
|
|
|
|
return handlers.FromAdmissionFunc(
|
2025-01-28 10:06:30 +01:00
|
|
|
name,
|
|
|
|
func(ctx context.Context, logger logr.Logger, request handlers.AdmissionRequest, startTime time.Time) admissionv1.AdmissionResponse {
|
2025-02-04 13:52:48 +01:00
|
|
|
return handler.Execute(ctx, logger, request, failurePolicy, startTime)
|
2025-01-28 10:06:30 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|