From d1f07bb4ddbe6dad5e6a590e53b33c6d78c7f18e Mon Sep 17 00:00:00 2001 From: Alper Rifat Ulucinar Date: Tue, 23 Jan 2024 17:04:34 +0300 Subject: [PATCH] Only start the conversion webhooks if they are enabled via the controller.Options.StartWebhooks Signed-off-by: Alper Rifat Ulucinar --- pkg/controller/options.go | 4 ++++ pkg/pipeline/templates/controller.go.tmpl | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/controller/options.go b/pkg/controller/options.go index 353ef866..1bba55cb 100644 --- a/pkg/controller/options.go +++ b/pkg/controller/options.go @@ -45,6 +45,10 @@ type Options struct { // PollJitter adds the specified jitter to the configured reconcile period // of the up-to-date resources in managed.Reconciler. PollJitter time.Duration + + // StartWebhooks enables starting of the conversion webhooks by the + // provider's controllerruntime.Manager. + StartWebhooks bool } // ESSOptions for External Secret Stores. diff --git a/pkg/pipeline/templates/controller.go.tmpl b/pkg/pipeline/templates/controller.go.tmpl index 8e526825..5b584dc2 100644 --- a/pkg/pipeline/templates/controller.go.tmpl +++ b/pkg/pipeline/templates/controller.go.tmpl @@ -99,10 +99,13 @@ func Setup(mgr ctrl.Manager, o tjcontroller.Options) error { {{- end}} // register webhooks for the kind {{ .TypePackageAlias }}{{ .CRD.Kind }} - if err := ctrl.NewWebhookManagedBy(mgr). + // if they're enabled. + if o.StartWebhooks { + if err := ctrl.NewWebhookManagedBy(mgr). For(&{{ .TypePackageAlias }}{{ .CRD.Kind }}{}). Complete(); err != nil { - return errors.Wrap(err, "cannot register webhook for the kind {{ .TypePackageAlias }}{{ .CRD.Kind }}") + return errors.Wrap(err, "cannot register webhook for the kind {{ .TypePackageAlias }}{{ .CRD.Kind }}") + } } r := managed.NewReconciler(mgr, xpresource.ManagedKind({{ .TypePackageAlias }}{{ .CRD.Kind }}_GroupVersionKind), opts...)