Skip to content

Commit 6cf93e4

Browse files
committed
🌱 Bump c-r dependency, fix webhook testdata compilation
The webhook testdata referred to a very old controller-runtime version, update that. Then update the testdata examples to look like webhooks do nowadays and update the test script to check compilation to prevent future regressions.
1 parent 33e5fdc commit 6cf93e4

File tree

26 files changed

+466
-1658
lines changed

26 files changed

+466
-1658
lines changed

pkg/webhook/testdata/go.mod

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,64 @@
11
module testdata.kubebuilder.io/cronjob
22

3-
go 1.15
3+
go 1.25.0
44

55
require (
6-
k8s.io/api v0.19.2
7-
k8s.io/apimachinery v0.19.2
8-
sigs.k8s.io/controller-runtime v0.7.0
6+
k8s.io/apimachinery v0.35.0
7+
sigs.k8s.io/controller-runtime v0.23.1
8+
)
9+
10+
require (
11+
github.com/beorn7/perks v1.0.1 // indirect
12+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
13+
github.com/davecgh/go-spew v1.1.1 // indirect
14+
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
15+
github.com/evanphx/json-patch v4.9.0+incompatible // indirect
16+
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
17+
github.com/fsnotify/fsnotify v1.9.0 // indirect
18+
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
19+
github.com/go-logr/logr v1.4.3 // indirect
20+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
21+
github.com/go-openapi/jsonreference v0.20.2 // indirect
22+
github.com/go-openapi/swag v0.23.0 // indirect
23+
github.com/google/btree v1.1.3 // indirect
24+
github.com/google/gnostic-models v0.7.0 // indirect
25+
github.com/google/go-cmp v0.7.0 // indirect
26+
github.com/google/uuid v1.6.0 // indirect
27+
github.com/josharian/intern v1.0.0 // indirect
28+
github.com/json-iterator/go v1.1.12 // indirect
29+
github.com/mailru/easyjson v0.7.7 // indirect
30+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
31+
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
32+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
33+
github.com/pmezard/go-difflib v1.0.0 // indirect
34+
github.com/prometheus/client_golang v1.23.2 // indirect
35+
github.com/prometheus/client_model v0.6.2 // indirect
36+
github.com/prometheus/common v0.66.1 // indirect
37+
github.com/prometheus/procfs v0.16.1 // indirect
38+
github.com/spf13/pflag v1.0.9 // indirect
39+
github.com/x448/float16 v0.8.4 // indirect
40+
go.yaml.in/yaml/v2 v2.4.3 // indirect
41+
go.yaml.in/yaml/v3 v3.0.4 // indirect
42+
golang.org/x/net v0.47.0 // indirect
43+
golang.org/x/oauth2 v0.30.0 // indirect
44+
golang.org/x/sync v0.18.0 // indirect
45+
golang.org/x/sys v0.38.0 // indirect
46+
golang.org/x/term v0.37.0 // indirect
47+
golang.org/x/text v0.31.0 // indirect
48+
golang.org/x/time v0.9.0 // indirect
49+
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
50+
google.golang.org/protobuf v1.36.8 // indirect
51+
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
52+
gopkg.in/inf.v0 v0.9.1 // indirect
53+
gopkg.in/yaml.v3 v3.0.1 // indirect
54+
k8s.io/api v0.35.0 // indirect
55+
k8s.io/apiextensions-apiserver v0.35.0 // indirect
56+
k8s.io/client-go v0.35.0 // indirect
57+
k8s.io/klog/v2 v2.130.1 // indirect
58+
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
59+
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect
60+
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
61+
sigs.k8s.io/randfill v1.0.0 // indirect
62+
sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482 // indirect
63+
sigs.k8s.io/yaml v1.6.0 // indirect
964
)

pkg/webhook/testdata/go.sum

Lines changed: 149 additions & 698 deletions
Large diffs are not rendered by default.

pkg/webhook/testdata/invalid-admissionReviewVersionsRequired/cronjob_types.go

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

pkg/webhook/testdata/invalid-admissionReviewVersionsRequired/webhook.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,42 @@ limitations under the License.
1616
package cronjob
1717

1818
import (
19-
"k8s.io/apimachinery/pkg/runtime"
19+
"context"
20+
21+
cronjobv1 "testdata.kubebuilder.io/cronjob"
22+
2023
ctrl "sigs.k8s.io/controller-runtime"
21-
"sigs.k8s.io/controller-runtime/pkg/webhook"
24+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2225
)
2326

24-
func (c *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error {
25-
return ctrl.NewWebhookManagedBy(mgr).
26-
For(c).
27+
type webhook struct{}
28+
29+
func (w *webhook) SetupWebhookWithManager(mgr ctrl.Manager) error {
30+
return ctrl.NewWebhookManagedBy(mgr, &cronjobv1.CronJob{}).
31+
WithDefaulter(w).
32+
WithValidator(w).
2733
Complete()
2834
}
2935

3036
// +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10
3137
// +kubebuilder:webhook:verbs=create;update,path=/validate-testdata-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=validation.cronjob.testdata.kubebuilder.io,sideEffects=NoneOnDryRun,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1
3238
// +kubebuilder:webhook:webhookVersions=v1,verbs=create;update,path=/mutate-testdata-kubebuilder-io-v1-cronjob,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=testdata.kubebuilder.io,resources=cronjobs,versions=v1,name=default.cronjob.testdata.kubebuilder.io,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1;v1beta1
3339

34-
var _ webhook.Defaulter = &CronJob{}
35-
var _ webhook.Validator = &CronJob{}
40+
var _ admission.Defaulter[*cronjobv1.CronJob] = &webhook{}
41+
var _ admission.Validator[*cronjobv1.CronJob] = &webhook{}
3642

37-
func (c *CronJob) Default() {
43+
func (w *webhook) Default(_ context.Context, _ *cronjobv1.CronJob) error {
44+
return nil
3845
}
3946

40-
func (c *CronJob) ValidateCreate() error {
41-
return nil
47+
func (w *webhook) ValidateCreate(_ context.Context, _ *cronjobv1.CronJob) (admission.Warnings, error) {
48+
return nil, nil
4249
}
4350

44-
func (c *CronJob) ValidateUpdate(_ runtime.Object) error {
45-
return nil
51+
func (w *webhook) ValidateUpdate(_ context.Context, _, _ *cronjobv1.CronJob) (admission.Warnings, error) {
52+
return nil, nil
4653
}
4754

48-
func (c *CronJob) ValidateDelete() error {
49-
return nil
55+
func (w *webhook) ValidateDelete(_ context.Context, _ *cronjobv1.CronJob) (admission.Warnings, error) {
56+
return nil, nil
5057
}

pkg/webhook/testdata/invalid-multiple-webhookconfigurations/cronjob_types.go

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

pkg/webhook/testdata/invalid-multiple-webhookconfigurations/webhook.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ limitations under the License.
1616
package cronjob
1717

1818
import (
19-
"k8s.io/apimachinery/pkg/runtime"
19+
"context"
20+
21+
cronjobv1 "testdata.kubebuilder.io/cronjob"
22+
2023
ctrl "sigs.k8s.io/controller-runtime"
21-
"sigs.k8s.io/controller-runtime/pkg/webhook"
24+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2225
)
2326

24-
func (c *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error {
25-
return ctrl.NewWebhookManagedBy(mgr).
26-
For(c).
27+
type webhook struct{}
28+
29+
func (w *webhook) SetupWebhookWithManager(mgr ctrl.Manager) error {
30+
return ctrl.NewWebhookManagedBy(mgr, &cronjobv1.CronJob{}).
31+
WithDefaulter(w).
32+
WithValidator(w).
2733
Complete()
2834
}
2935

@@ -33,20 +39,21 @@ func (c *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error {
3339
// +kubebuilder:webhookconfiguration:mutating=true,name=foo
3440
// +kubebuilder:webhookconfiguration:mutating=true,name=bar
3541

36-
var _ webhook.Defaulter = &CronJob{}
37-
var _ webhook.Validator = &CronJob{}
42+
var _ admission.Defaulter[*cronjobv1.CronJob] = &webhook{}
43+
var _ admission.Validator[*cronjobv1.CronJob] = &webhook{}
3844

39-
func (c *CronJob) Default() {
45+
func (w *webhook) Default(_ context.Context, _ *cronjobv1.CronJob) error {
46+
return nil
4047
}
4148

42-
func (c *CronJob) ValidateCreate() error {
43-
return nil
49+
func (w *webhook) ValidateCreate(_ context.Context, _ *cronjobv1.CronJob) (admission.Warnings, error) {
50+
return nil, nil
4451
}
4552

46-
func (c *CronJob) ValidateUpdate(_ runtime.Object) error {
47-
return nil
53+
func (w *webhook) ValidateUpdate(_ context.Context, _, _ *cronjobv1.CronJob) (admission.Warnings, error) {
54+
return nil, nil
4855
}
4956

50-
func (c *CronJob) ValidateDelete() error {
51-
return nil
57+
func (w *webhook) ValidateDelete(_ context.Context, _ *cronjobv1.CronJob) (admission.Warnings, error) {
58+
return nil, nil
5259
}

pkg/webhook/testdata/invalid-path-and-url/cronjob_types.go

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

0 commit comments

Comments
 (0)