Skip to content

Commit 11684fe

Browse files
⚠️ (go/v4) decouple webhooks from APIs - Move Webhooks from api/<version> or api/<group>/<version> to internal/webhook/<version> or internal/webhook/<group>/<version>
This PR decouples the webhooks from the API, aligning with the recent breaking changes introduced in controller-runtime to ensure that kubebuilder still compatbile with its next release. Webhooks are now scaffolded under `internal/webhook` to comply with the latest standards. **Context:** Controller-runtime deprecated and removed the webhook methods in favor of CustomInterfaces (see [controller-runtime#2641](kubernetes-sigs/controller-runtime#2641)). The motivation for this change is outlined in [controller-runtime#2596](kubernetes-sigs/controller-runtime#2596). See that the current master branch already reflects these changes, using the CustomInterfaces: [kubebuilder#4060](kubernetes-sigs#4060). **Changes:** - Webhooks are now scaffolded in `internal/webhook/<version>` or `internal/webhook/<group>/<version>`. - However, to ensure backwards compatibility, a new `--legacy` flag is introduced. Running `kubebuilder create webhook [options] --legacy` will scaffold webhooks in the legacy location for projects that need to retain the old structure. However, users will still to address the breaking changes in the source code by replacing the old methods by the new CustomInterfaces.
1 parent 983a929 commit 11684fe

File tree

81 files changed

+1807
-1250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1807
-1250
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This test ensure that the legacy webhook path
2+
# still working. The option is deprecated
3+
# and should be removed when we no longer need
4+
# to support go/v4 plugin.
5+
name: Legacy Webhook Path
6+
7+
on:
8+
push:
9+
paths:
10+
- 'testdata/**'
11+
- '.github/workflows/legacy-webhook-path.yml'
12+
pull_request:
13+
paths:
14+
- 'testdata/**'
15+
- '.github/workflows/legacy-webhook-path.yml'
16+
17+
jobs:
18+
webhook-legacy-path:
19+
name: Verify Legacy Webhook Path
20+
runs-on: ubuntu-latest
21+
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
22+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
23+
steps:
24+
- name: Clone the code
25+
uses: actions/checkout@v4
26+
- name: Setup Go
27+
uses: actions/setup-go@v5
28+
with:
29+
go-version: '1.22.3'
30+
- name: Run make test-legacy
31+
run: make test-legacy
32+

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ docs/book/src/docs
2525
# skip testdata go.sum, since it may have
2626
# different result depending on go version
2727
/testdata/**/go.sum
28-
/docs/book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1/bin
28+
/docs/book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1/bin
29+
/testdata/**legacy**

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,10 @@ test-license: ## Run the license check
164164
.PHONY: test-spaces
165165
test-spaces: ## Run the trailing spaces check
166166
./test/check_spaces.sh
167+
168+
## TODO: Remove me when go/v4 plugin be removed
169+
## Deprecated
170+
.PHONY: test-legacy
171+
test-legacy: ## Run the tests to validate legacy path for webhooks
172+
rm -rf ./testdata/**legacy**/
173+
./test/testdata/legacy-webhook-path.sh

docs/book/src/cronjob-tutorial/testdata/project/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RUN go mod download
1414
# Copy the go source
1515
COPY cmd/main.go cmd/main.go
1616
COPY api/ api/
17-
COPY internal/controller/ internal/controller/
17+
COPY internal/ internal/
1818

1919
# Build
2020
# the GOARCH has not a default value to allow the binary be built according to the host where the command

docs/book/src/cronjob-tutorial/testdata/project/api/v1/webhook_suite_test.go

Lines changed: 0 additions & 147 deletions
This file was deleted.

docs/book/src/cronjob-tutorial/testdata/project/api/v1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/book/src/cronjob-tutorial/testdata/project/cmd/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838

3939
batchv1 "tutorial.kubebuilder.io/project/api/v1"
4040
"tutorial.kubebuilder.io/project/internal/controller"
41+
webhookbatchv1 "tutorial.kubebuilder.io/project/internal/webhook/v1"
4142
// +kubebuilder:scaffold:imports
4243
)
4344

@@ -183,7 +184,7 @@ func main() {
183184
*/
184185
// nolint:goconst
185186
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
186-
if err = (&batchv1.CronJob{}).SetupWebhookWithManager(mgr); err != nil {
187+
if err = webhookbatchv1.SetupCronJobWebhookWithManager(mgr); err != nil {
187188
setupLog.Error(err, "unable to create webhook", "webhook", "CronJob")
188189
os.Exit(1)
189190
}

0 commit comments

Comments
 (0)