kubernetes-sigs / kubebuilder

Kubebuilder - SDK for building Kubernetes APIs using CRDs
http://book.kubebuilder.io
Apache License 2.0
7.9k stars 1.45k forks source link

Unable to Add Additional Webhooks Without Forcing Re-scaffold #4146

Open camilamacedo86 opened 2 months ago

camilamacedo86 commented 2 months ago

What broke? What's expected?

When trying to add an additional webhook (e.g., conversion webhook) to an API where other webhooks (like defaulting or validation) are already scaffolded, Kubebuilder throws an error stating that the webhook files already exist. Currently, the only workaround is to use the --force option, which leads to the entire webhook being re-scaffolded, overwriting any custom implementation added by the user. This behavior results in lost code and makes it difficult to incrementally add webhooks.

Kubebuilder should allow adding additional webhooks without forcing the user to use --force and without overwriting existing implementation. It should:

Such as we do in the main.go and for the test-e2e as well. See the WebhookTestUpdater for test-e2e. We need ensure that webhooks follow the same: https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/golang/v4/scaffolds/internal/templates/test/e2e/test.go#L58-L103

Reproducing this issue

kubebuilder create api --group batch --version v1 --kind CronJob --resource=true --controller=true
kubebuilder create webhook --group batch --version v1 --kind CronJob --defaulting --programmatic-validation
kubebuilder create webhook --group batch --version v1 --kind CronJob --conversion
kubebuilder create webhook --group batch --version v1 --kind CronJob --conversion --force

Expected Behavior/Request Kubebuilder should scaffold only the specific webhook (e.g., conversion) requested without overwriting the existing webhook code. It should intelligently detect existing webhooks and add the necessary logic for the new type while keeping the current implementation intact.

KubeBuilder (CLI) Version

4.2.0

PROJECT version

No response

Plugin versions

No response

Other versions

No response

Extra Labels

No response

fischor commented 1 month ago

/assign Would like to start once #4150 is merged

camilamacedo86 commented 4 days ago

We cannot skip. We will need to create new kubebuilder scaffold markers to fix this issue.