-
Notifications
You must be signed in to change notification settings - Fork 4
/
add.go
54 lines (44 loc) · 1.47 KB
/
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
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
package webhook
import (
extensionswebhook "github.com/gardener/gardener/extensions/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)
const (
// WebhookName is the name of the webhook acl ACL extension.
WebhookName = "acl-webhook"
// WebhookPath is the path where the webhook listen to.
WebhookPath = "/mutate"
)
var (
logger = log.Log.WithName(WebhookName)
// DefaultAddOptions are the default AddOptions for AddToManager.
DefaultAddOptions = AddOptions{}
)
// AddOptions are options to apply when adding the webhook to the manager.
type AddOptions struct {
AllowedCIDRs []string
}
// AddToManagerWithOptions creates a webhook with the given options and adds it to the manager.
func AddToManagerWithOptions(
mgr manager.Manager,
options AddOptions,
) error {
logger.Info("Adding webhook to manager")
decoder := admission.NewDecoder(mgr.GetScheme())
mgr.GetWebhookServer().Register(WebhookPath, &webhook.Admission{Handler: &EnvoyFilterWebhook{
Client: mgr.GetClient(),
AdditionalAllowedCIDRs: options.AllowedCIDRs,
Decoder: decoder,
}})
return nil
}
// AddToManager creates a webhook with the default options and adds it to the manager.
func AddToManager(mgr manager.Manager) (*extensionswebhook.Webhook, error) {
return nil, AddToManagerWithOptions(
mgr,
DefaultAddOptions,
)
}