@@ -37,19 +37,19 @@ import (
3737
3838// WebhookBuilder builds a Webhook.
3939type WebhookBuilder struct {
40- apiType runtime.Object
41- customDefaulter admission.CustomDefaulter
42- customDefaulterOpts []admission.DefaulterOption
43- customValidator admission.CustomValidator
44- customPath string
45- validatingCustomPath string
46- defaultingCustomPath string
47- gvk schema.GroupVersionKind
48- mgr manager.Manager
49- config * rest.Config
50- recoverPanic * bool
51- logConstructor func (base logr.Logger , req * admission.Request ) logr.Logger
52- err error
40+ apiType runtime.Object
41+ customDefaulter admission.CustomDefaulter
42+ customDefaulterOpts []admission.DefaulterOption
43+ customValidator admission.CustomValidator
44+ customPath string
45+ customValidatorCustomPath string
46+ customDefaulterCustomPath string
47+ gvk schema.GroupVersionKind
48+ mgr manager.Manager
49+ config * rest.Config
50+ recoverPanic * bool
51+ logConstructor func (base logr.Logger , req * admission.Request ) logr.Logger
52+ err error
5353}
5454
5555// WebhookManagedBy returns a new webhook builder.
@@ -99,21 +99,21 @@ func (blder *WebhookBuilder) RecoverPanic(recoverPanic bool) *WebhookBuilder {
9999
100100// WithCustomPath overrides the webhook's default path by the customPath
101101// Deprecated: WithCustomPath should not be used anymore.
102- // Please use WithValidatingCustomPath or WithDefaultingCustomPath instead.
102+ // Please use WithValidatorCustomPath or WithDefaulterCustomPath instead.
103103func (blder * WebhookBuilder ) WithCustomPath (customPath string ) * WebhookBuilder {
104104 blder .customPath = customPath
105105 return blder
106106}
107107
108- // WithValidatingCustomPath overrides the webhook's default validating path by the customPath
109- func (blder * WebhookBuilder ) WithValidatingCustomPath (customPath string ) * WebhookBuilder {
110- blder .validatingCustomPath = customPath
108+ // WithValidatorCustomPath overrides the path of the Validator.
109+ func (blder * WebhookBuilder ) WithValidatorCustomPath (customPath string ) * WebhookBuilder {
110+ blder .customValidatorCustomPath = customPath
111111 return blder
112112}
113113
114- // WithDefaultingCustomPath overrides the webhook's default defaulting path by the customPath
115- func (blder * WebhookBuilder ) WithDefaultingCustomPath (customPath string ) * WebhookBuilder {
116- blder .defaultingCustomPath = customPath
114+ // WithDefaulterCustomPath overrides the path of the Defaulter.
115+ func (blder * WebhookBuilder ) WithDefaulterCustomPath (customPath string ) * WebhookBuilder {
116+ blder .customDefaulterCustomPath = customPath
117117 return blder
118118}
119119
@@ -156,7 +156,7 @@ func (blder *WebhookBuilder) setLogConstructor() {
156156}
157157
158158func (blder * WebhookBuilder ) isThereCustomPathConflict () bool {
159- return (blder .customPath != "" && blder .customDefaulter != nil && blder .customValidator != nil ) || (blder .customPath != "" && blder .defaultingCustomPath != "" ) || (blder .customPath != "" && blder .validatingCustomPath != "" )
159+ return (blder .customPath != "" && blder .customDefaulter != nil && blder .customValidator != nil ) || (blder .customPath != "" && blder .customDefaulterCustomPath != "" ) || (blder .customPath != "" && blder .customValidatorCustomPath != "" )
160160}
161161
162162func (blder * WebhookBuilder ) registerWebhooks () error {
@@ -171,15 +171,14 @@ func (blder *WebhookBuilder) registerWebhooks() error {
171171 }
172172
173173 if blder .isThereCustomPathConflict () {
174- return errors .New ("only one of the custom defaulter or custom validtor should be set when using WithCustomPath. Otherwise, WithDefaultingCustomPath() and WithValidatingCustomPath() should be used." )
175- } else {
176- if blder .customPath != "" {
177- // isThereCustomPathConflict() already checks for potential conflicts.
178- // Since we are sure that only one of customDefaulter or customValidator will be used,
179- // we can set set both defaultingCustomPath and validatingCustomPath.
180- blder .defaultingCustomPath = blder .customPath
181- blder .validatingCustomPath = blder .customPath
182- }
174+ return errors .New ("only one of CustomDefaulter or CustomValidator should be set when using WithCustomPath. Otherwise, WithDefaulterCustomPath() and WithValidatorCustomPath() should be used" )
175+ }
176+ if blder .customPath != "" {
177+ // isThereCustomPathConflict() already checks for potential conflicts.
178+ // Since we are sure that only one of customDefaulter or customValidator will be used,
179+ // we can set both customDefaulterCustomPath and validatingCustomPath.
180+ blder .customDefaulterCustomPath = blder .customPath
181+ blder .customValidatorCustomPath = blder .customPath
183182 }
184183
185184 // Register webhook(s) for type
@@ -206,8 +205,8 @@ func (blder *WebhookBuilder) registerDefaultingWebhook() error {
206205 if mwh != nil {
207206 mwh .LogConstructor = blder .logConstructor
208207 path := generateMutatePath (blder .gvk )
209- if blder .defaultingCustomPath != "" {
210- generatedCustomPath , err := generateCustomPath (blder .defaultingCustomPath )
208+ if blder .customDefaulterCustomPath != "" {
209+ generatedCustomPath , err := generateCustomPath (blder .customDefaulterCustomPath )
211210 if err != nil {
212211 return err
213212 }
@@ -244,8 +243,8 @@ func (blder *WebhookBuilder) registerValidatingWebhook() error {
244243 if vwh != nil {
245244 vwh .LogConstructor = blder .logConstructor
246245 path := generateValidatePath (blder .gvk )
247- if blder .validatingCustomPath != "" {
248- generatedCustomPath , err := generateCustomPath (blder .validatingCustomPath )
246+ if blder .customValidatorCustomPath != "" {
247+ generatedCustomPath , err := generateCustomPath (blder .customValidatorCustomPath )
249248 if err != nil {
250249 return err
251250 }
0 commit comments