Skip to content

Commit a577c5c

Browse files
committed
feat: allow customizing generated webhook's name
closes kubernetes-sigs#865
1 parent b07ad66 commit a577c5c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

pkg/webhook/parser.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ type Config struct {
102102
// Name indicates the name of this webhook configuration. Should be a domain with at least three segments separated by dots
103103
Name string
104104

105+
// K8sName indicates the K8s name of this webhook configuration.
106+
K8sName string `marker:"k8sName,optional"`
107+
105108
// Path specifies that path that the API server should connect to this webhook on. Must be
106109
// prefixed with a '/validate-' or '/mutate-' depending on the type, and followed by
107110
// $GROUP-$VERSION-$KIND where all values are lower-cased and the periods in the group
@@ -370,6 +373,9 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
370373
supportedWebhookVersions := supportedWebhookVersions()
371374
mutatingCfgs := make(map[string][]admissionregv1.MutatingWebhook, len(supportedWebhookVersions))
372375
validatingCfgs := make(map[string][]admissionregv1.ValidatingWebhook, len(supportedWebhookVersions))
376+
mutatingWebhookConfigurationK8sName := "mutating-webhook-configuration"
377+
validatingWebhookConfigurationK8sName := "validating-webhook-configuration"
378+
373379
for _, root := range ctx.Roots {
374380
markerSet, err := markers.PackageMarkers(ctx.Collector, root)
375381
if err != nil {
@@ -395,6 +401,9 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
395401
for _, webhookVersion := range webhookVersions {
396402
mutatingCfgs[webhookVersion] = append(mutatingCfgs[webhookVersion], w)
397403
}
404+
if cfg.K8sName != "" {
405+
mutatingWebhookConfigurationK8sName = cfg.K8sName
406+
}
398407
} else {
399408
w, err := cfg.ToValidatingWebhook()
400409
if err != nil {
@@ -403,6 +412,9 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
403412
for _, webhookVersion := range webhookVersions {
404413
validatingCfgs[webhookVersion] = append(validatingCfgs[webhookVersion], w)
405414
}
415+
if cfg.K8sName != "" {
416+
validatingWebhookConfigurationK8sName = cfg.K8sName
417+
}
406418
}
407419
}
408420
}
@@ -418,7 +430,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
418430
Version: version,
419431
Kind: "MutatingWebhookConfiguration",
420432
})
421-
objRaw.SetName("mutating-webhook-configuration")
433+
objRaw.SetName(mutatingWebhookConfigurationK8sName)
422434
objRaw.Webhooks = cfgs
423435
for i := range objRaw.Webhooks {
424436
// SideEffects is required in admissionregistration/v1, if this is not set or set to `Some` or `Known`,
@@ -449,7 +461,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
449461
Version: version,
450462
Kind: "ValidatingWebhookConfiguration",
451463
})
452-
objRaw.SetName("validating-webhook-configuration")
464+
objRaw.SetName(validatingWebhookConfigurationK8sName)
453465
objRaw.Webhooks = cfgs
454466
for i := range objRaw.Webhooks {
455467
// SideEffects is required in admissionregistration/v1, if this is not set or set to `Some` or `Known`,

pkg/webhook/zz_generated.markerhelp.go

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)