@@ -37,6 +37,7 @@ import (
37
37
// WebhookBuilder builds a Webhook.
38
38
type WebhookBuilder struct {
39
39
apiType runtime.Object
40
+ mutatorFactory admission.HandlerFactory
40
41
customDefaulter admission.CustomDefaulter
41
42
customValidator admission.CustomValidator
42
43
gvk schema.GroupVersionKind
@@ -65,6 +66,12 @@ func (blder *WebhookBuilder) For(apiType runtime.Object) *WebhookBuilder {
65
66
return blder
66
67
}
67
68
69
+ // WithMutationHandler takes an admission.ObjectHandler interface, a MutatingWebhook will be wired for this type.
70
+ func (blder * WebhookBuilder ) WithMutatorFactory (factory admission.HandlerFactory ) * WebhookBuilder {
71
+ blder .mutatorFactory = factory
72
+ return blder
73
+ }
74
+
68
75
// WithDefaulter takes an admission.CustomDefaulter interface, a MutatingWebhook will be wired for this type.
69
76
func (blder * WebhookBuilder ) WithDefaulter (defaulter admission.CustomDefaulter ) * WebhookBuilder {
70
77
blder .customDefaulter = defaulter
@@ -169,14 +176,19 @@ func (blder *WebhookBuilder) registerDefaultingWebhook() {
169
176
}
170
177
171
178
func (blder * WebhookBuilder ) getDefaultingWebhook () * admission.Webhook {
172
- if defaulter := blder .customDefaulter ; defaulter != nil {
173
- w := admission .WithCustomDefaulter (blder .mgr .GetScheme (), blder .apiType , defaulter )
174
- if blder .recoverPanic != nil {
175
- w = w .WithRecoverPanic (* blder .recoverPanic )
176
- }
177
- return w
179
+ var w * admission.Webhook
180
+ if factory := blder .mutatorFactory ; factory != nil {
181
+ w = admission .WithHandlerFactory (blder .mgr .GetScheme (), blder .apiType , factory )
182
+ } else if defaulter := blder .customDefaulter ; defaulter != nil {
183
+ w = admission .WithCustomDefaulter (blder .mgr .GetScheme (), blder .apiType , defaulter )
178
184
}
179
- return nil
185
+ if w == nil {
186
+ return nil
187
+ }
188
+ if blder .recoverPanic != nil {
189
+ w = w .WithRecoverPanic (* blder .recoverPanic )
190
+ }
191
+ return w
180
192
}
181
193
182
194
// registerValidatingWebhook registers a validating webhook if necessary.
0 commit comments