-
Notifications
You must be signed in to change notification settings - Fork 451
/
add.go
28 lines (23 loc) · 823 Bytes
/
add.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
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package kubernetesservicehost
import (
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)
const (
// HandlerName is the name of the webhook handler.
HandlerName = "kubernetes-service-host"
// WebhookPath is the path at which the handler should be registered.
WebhookPath = "/webhooks/kubernetes-service-host"
)
// AddToManager adds Handler to the given manager.
func (h *Handler) AddToManager(mgr manager.Manager) error {
webhook := admission.
WithCustomDefaulter(mgr.GetScheme(), &corev1.Pod{}, h).
WithRecoverPanic(true)
mgr.GetWebhookServer().Register(WebhookPath, webhook)
return nil
}