From 8ffeffb0c72757a3cd74818117e3a786e4cc5d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Sch=C3=BCnemann?= Date: Mon, 10 Nov 2025 17:17:56 +0100 Subject: [PATCH 1/2] fix: apply webhook configurations correctly --- pkg/init/webhooks/init.go | 39 +++++++++++++++++++--------------- pkg/init/webhooks/init_test.go | 9 +++++++- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/pkg/init/webhooks/init.go b/pkg/init/webhooks/init.go index efda162..8ab0d6d 100644 --- a/pkg/init/webhooks/init.go +++ b/pkg/init/webhooks/init.go @@ -10,7 +10,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/webhook" ) var ( @@ -66,11 +65,21 @@ func GenerateCertificate(ctx context.Context, c client.Client, options ...CertOp return err } +// APITypes defines an API type along with whether it has a validator and/or defaulter webhook. +type APITypes struct { + // Obj is the API type object. + Obj client.Object + // Validator indicates whether the type has a validating webhook. + Validator bool + // Defaulter indicates whether the type has a mutating webhook. + Defaulter bool +} + func Install( ctx context.Context, c client.Client, scheme *runtime.Scheme, - apiTypes []client.Object, + apiTypes []APITypes, options ...InstallOption, ) error { opts := &installOptions{ @@ -104,16 +113,14 @@ func Install( } } - for _, o := range apiTypes { - _, isCustomValidator := o.(webhook.CustomValidator) - if isCustomValidator { - if err := applyValidatingWebhook(ctx, opts, o); err != nil { + for _, t := range apiTypes { + if t.Validator { + if err := applyValidatingWebhook(ctx, opts, t.Obj); err != nil { return err } } - _, isCustomDefaulter := o.(webhook.CustomDefaulter) - if isCustomDefaulter { - if err := applyMutatingWebhook(ctx, opts, o); err != nil { + if t.Defaulter { + if err := applyMutatingWebhook(ctx, opts, t.Obj); err != nil { return err } } @@ -127,7 +134,7 @@ func Uninstall( ctx context.Context, c client.Client, scheme *runtime.Scheme, - apiTypes []client.Object, + apiTypes []APITypes, options ...InstallOption, ) error { opts := &installOptions{ @@ -148,16 +155,14 @@ func Uninstall( } } - for _, o := range apiTypes { - _, isCustomValidator := o.(webhook.CustomValidator) - if isCustomValidator { - if err := removeValidatingWebhook(ctx, opts, o); err != nil { + for _, t := range apiTypes { + if t.Validator { + if err := removeValidatingWebhook(ctx, opts, t.Obj); err != nil { return err } } - _, isCustomDefaulter := o.(webhook.CustomDefaulter) - if isCustomDefaulter { - if err := removeMutatingWebhook(ctx, opts, o); err != nil { + if t.Defaulter { + if err := removeMutatingWebhook(ctx, opts, t.Obj); err != nil { return err } } diff --git a/pkg/init/webhooks/init_test.go b/pkg/init/webhooks/init_test.go index f7374e7..bfe7a79 100644 --- a/pkg/init/webhooks/init_test.go +++ b/pkg/init/webhooks/init_test.go @@ -271,7 +271,14 @@ func Test_Install(t *testing.T) { t.Fatal(err) } - testErr := Install(ctx, c, c.Scheme(), []client.Object{&TestObj{}}, tC.options...) + apiTypes := []APITypes{ + { + Obj: &TestObj{}, + Validator: true, + Defaulter: true, + }, + } + testErr := Install(ctx, c, c.Scheme(), apiTypes, tC.options...) if err := tC.validate(ctx, c, t, testErr); err != nil { t.Fatal(err) From 9318f6f2ffa3858fe9784b7ffafa3e09a6d9dfbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Sch=C3=BCnemann?= Date: Mon, 10 Nov 2025 18:03:03 +0100 Subject: [PATCH 2/2] feat: release v0.24.0 --- VERSION | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 217167d..a283725 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.23.4-dev \ No newline at end of file +v0.24.0 \ No newline at end of file diff --git a/go.mod b/go.mod index 9c2882e..a6977d0 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/google/uuid v1.6.0 github.com/onsi/ginkgo/v2 v2.27.2 github.com/onsi/gomega v1.38.2 - github.com/openmcp-project/controller-utils/api v0.23.4 + github.com/openmcp-project/controller-utils/api v0.24.0 github.com/spf13/pflag v1.0.10 github.com/stretchr/testify v1.11.1 go.uber.org/zap v1.27.0