@@ -21,6 +21,7 @@ import (
21
21
"strings"
22
22
23
23
"k8s.io/apimachinery/pkg/runtime"
24
+ "k8s.io/apimachinery/pkg/runtime/schema"
24
25
"k8s.io/client-go/rest"
25
26
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
26
27
"sigs.k8s.io/controller-runtime/pkg/client/config"
@@ -249,9 +250,6 @@ func (blder *Builder) doWebhook() error {
249
250
return err
250
251
}
251
252
252
- partialPath := strings .Replace (gvk .Group , "." , "-" , - 1 ) + "-" +
253
- gvk .Version + "-" + strings .ToLower (gvk .Kind )
254
-
255
253
// TODO: When the conversion webhook lands, we need to handle all registered versions of a given group-kind.
256
254
// A potential workflow for defaulting webhook
257
255
// 1) a bespoke (non-hub) version comes in
@@ -267,7 +265,7 @@ func (blder *Builder) doWebhook() error {
267
265
if defaulter , isDefaulter := blder .apiType .(admission.Defaulter ); isDefaulter {
268
266
mwh := admission .DefaultingWebhookFor (defaulter )
269
267
if mwh != nil {
270
- path := "/mutate-" + partialPath
268
+ path := generateMutatePath ( gvk )
271
269
log .Info ("Registering a mutating webhook" ,
272
270
"GVK" , gvk ,
273
271
"path" , path )
@@ -279,7 +277,7 @@ func (blder *Builder) doWebhook() error {
279
277
if validator , isValidator := blder .apiType .(admission.Validator ); isValidator {
280
278
vwh := admission .ValidatingWebhookFor (validator )
281
279
if vwh != nil {
282
- path := "/validate-" + partialPath
280
+ path := generateValidatePath ( gvk )
283
281
log .Info ("Registering a validating webhook" ,
284
282
"GVK" , gvk ,
285
283
"path" , path )
@@ -289,3 +287,13 @@ func (blder *Builder) doWebhook() error {
289
287
290
288
return err
291
289
}
290
+
291
+ func generateMutatePath (gvk schema.GroupVersionKind ) string {
292
+ return "/mutate-" + strings .Replace (gvk .Group , "." , "-" , - 1 ) + "-" +
293
+ gvk .Version + "-" + strings .ToLower (gvk .Kind )
294
+ }
295
+
296
+ func generateValidatePath (gvk schema.GroupVersionKind ) string {
297
+ return "/validate-" + strings .Replace (gvk .Group , "." , "-" , - 1 ) + "-" +
298
+ gvk .Version + "-" + strings .ToLower (gvk .Kind )
299
+ }
0 commit comments