@@ -37,19 +37,19 @@ import (
37
37
38
38
// WebhookBuilder builds a Webhook.
39
39
type 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
53
53
}
54
54
55
55
// WebhookManagedBy returns a new webhook builder.
@@ -99,21 +99,21 @@ func (blder *WebhookBuilder) RecoverPanic(recoverPanic bool) *WebhookBuilder {
99
99
100
100
// WithCustomPath overrides the webhook's default path by the customPath
101
101
// Deprecated: WithCustomPath should not be used anymore.
102
- // Please use WithValidatingCustomPath or WithDefaultingCustomPath instead.
102
+ // Please use WithValidatorCustomPath or WithDefaulterCustomPath instead.
103
103
func (blder * WebhookBuilder ) WithCustomPath (customPath string ) * WebhookBuilder {
104
104
blder .customPath = customPath
105
105
return blder
106
106
}
107
107
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
111
111
return blder
112
112
}
113
113
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
117
117
return blder
118
118
}
119
119
@@ -156,7 +156,7 @@ func (blder *WebhookBuilder) setLogConstructor() {
156
156
}
157
157
158
158
func (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 != "" )
160
160
}
161
161
162
162
func (blder * WebhookBuilder ) registerWebhooks () error {
@@ -171,15 +171,14 @@ func (blder *WebhookBuilder) registerWebhooks() error {
171
171
}
172
172
173
173
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
183
182
}
184
183
185
184
// Register webhook(s) for type
@@ -206,8 +205,8 @@ func (blder *WebhookBuilder) registerDefaultingWebhook() error {
206
205
if mwh != nil {
207
206
mwh .LogConstructor = blder .logConstructor
208
207
path := generateMutatePath (blder .gvk )
209
- if blder .defaultingCustomPath != "" {
210
- generatedCustomPath , err := generateCustomPath (blder .defaultingCustomPath )
208
+ if blder .customDefaulterCustomPath != "" {
209
+ generatedCustomPath , err := generateCustomPath (blder .customDefaulterCustomPath )
211
210
if err != nil {
212
211
return err
213
212
}
@@ -244,8 +243,8 @@ func (blder *WebhookBuilder) registerValidatingWebhook() error {
244
243
if vwh != nil {
245
244
vwh .LogConstructor = blder .logConstructor
246
245
path := generateValidatePath (blder .gvk )
247
- if blder .validatingCustomPath != "" {
248
- generatedCustomPath , err := generateCustomPath (blder .validatingCustomPath )
246
+ if blder .customValidatorCustomPath != "" {
247
+ generatedCustomPath , err := generateCustomPath (blder .customValidatorCustomPath )
249
248
if err != nil {
250
249
return err
251
250
}
0 commit comments