@@ -42,7 +42,7 @@ type WebhookBuilder struct {
4242 gvk schema.GroupVersionKind
4343 mgr manager.Manager
4444 config * rest.Config
45- recoverPanic bool
45+ recoverPanic * bool
4646 logConstructor func (base logr.Logger , req * admission.Request ) logr.Logger
4747 err error
4848}
@@ -84,8 +84,9 @@ func (blder *WebhookBuilder) WithLogConstructor(logConstructor func(base logr.Lo
8484}
8585
8686// RecoverPanic indicates whether panics caused by the webhook should be recovered.
87- func (blder * WebhookBuilder ) RecoverPanic () * WebhookBuilder {
88- blder .recoverPanic = true
87+ // Defaults to true.
88+ func (blder * WebhookBuilder ) RecoverPanic (recoverPanic bool ) * WebhookBuilder {
89+ blder .recoverPanic = & recoverPanic
8990 return blder
9091}
9192
@@ -169,10 +170,18 @@ func (blder *WebhookBuilder) registerDefaultingWebhook() {
169170
170171func (blder * WebhookBuilder ) getDefaultingWebhook () * admission.Webhook {
171172 if defaulter := blder .customDefaulter ; defaulter != nil {
172- return admission .WithCustomDefaulter (blder .mgr .GetScheme (), blder .apiType , defaulter ).WithRecoverPanic (blder .recoverPanic )
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
173178 }
174179 if defaulter , ok := blder .apiType .(admission.Defaulter ); ok {
175- return admission .DefaultingWebhookFor (blder .mgr .GetScheme (), defaulter ).WithRecoverPanic (blder .recoverPanic )
180+ w := admission .DefaultingWebhookFor (blder .mgr .GetScheme (), defaulter )
181+ if blder .recoverPanic != nil {
182+ w = w .WithRecoverPanic (* blder .recoverPanic )
183+ }
184+ return w
176185 }
177186 log .Info (
178187 "skip registering a mutating webhook, object does not implement admission.Defaulter or WithDefaulter wasn't called" ,
@@ -200,10 +209,18 @@ func (blder *WebhookBuilder) registerValidatingWebhook() {
200209
201210func (blder * WebhookBuilder ) getValidatingWebhook () * admission.Webhook {
202211 if validator := blder .customValidator ; validator != nil {
203- return admission .WithCustomValidator (blder .mgr .GetScheme (), blder .apiType , validator ).WithRecoverPanic (blder .recoverPanic )
212+ w := admission .WithCustomValidator (blder .mgr .GetScheme (), blder .apiType , validator )
213+ if blder .recoverPanic != nil {
214+ w = w .WithRecoverPanic (* blder .recoverPanic )
215+ }
216+ return w
204217 }
205218 if validator , ok := blder .apiType .(admission.Validator ); ok {
206- return admission .ValidatingWebhookFor (blder .mgr .GetScheme (), validator ).WithRecoverPanic (blder .recoverPanic )
219+ w := admission .ValidatingWebhookFor (blder .mgr .GetScheme (), validator )
220+ if blder .recoverPanic != nil {
221+ w = w .WithRecoverPanic (* blder .recoverPanic )
222+ }
223+ return w
207224 }
208225 log .Info (
209226 "skip registering a validating webhook, object does not implement admission.Validator or WithValidator wasn't called" ,
0 commit comments