From 202682a542eb868342523c625e4d2c5cece8747c Mon Sep 17 00:00:00 2001 From: Chandan Kumar Date: Wed, 27 Nov 2024 17:02:03 +0530 Subject: [PATCH] Fix functional tests and pre-commit Signed-off-by: Chandan Kumar --- api/v1beta1/watcher_webhook.go | 2 +- api/v1beta1/watcherapi_webhook.go | 2 +- api/v1beta1/watcherapplier_webhook.go | 2 +- api/v1beta1/watcherdecisionengine_webhook.go | 2 +- api/v1beta1/webhook_suite_test.go | 28 ++++++++++++++------ hack/clean_local_webhook.sh | 0 hack/run_with_local_webhook.sh | 0 main.go | 4 +-- 8 files changed, 26 insertions(+), 14 deletions(-) mode change 100644 => 100755 hack/clean_local_webhook.sh mode change 100644 => 100755 hack/run_with_local_webhook.sh diff --git a/api/v1beta1/watcher_webhook.go b/api/v1beta1/watcher_webhook.go index 1c9c997..0f18f3d 100644 --- a/api/v1beta1/watcher_webhook.go +++ b/api/v1beta1/watcher_webhook.go @@ -60,7 +60,7 @@ func (r *Watcher) ValidateCreate() (admission.Warnings, error) { } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *Watcher) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { +func (r *Watcher) ValidateUpdate(runtime.Object) (admission.Warnings, error) { watcherlog.Info("validate update", "name", r.Name) // TODO(user): fill in your validation logic upon object update. diff --git a/api/v1beta1/watcherapi_webhook.go b/api/v1beta1/watcherapi_webhook.go index 7e1c774..772dddb 100644 --- a/api/v1beta1/watcherapi_webhook.go +++ b/api/v1beta1/watcherapi_webhook.go @@ -60,7 +60,7 @@ func (r *WatcherAPI) ValidateCreate() (admission.Warnings, error) { } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *WatcherAPI) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { +func (r *WatcherAPI) ValidateUpdate(runtime.Object) (admission.Warnings, error) { watcherapilog.Info("validate update", "name", r.Name) // TODO(user): fill in your validation logic upon object update. diff --git a/api/v1beta1/watcherapplier_webhook.go b/api/v1beta1/watcherapplier_webhook.go index 1de0662..70c79fb 100644 --- a/api/v1beta1/watcherapplier_webhook.go +++ b/api/v1beta1/watcherapplier_webhook.go @@ -60,7 +60,7 @@ func (r *WatcherApplier) ValidateCreate() (admission.Warnings, error) { } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *WatcherApplier) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { +func (r *WatcherApplier) ValidateUpdate(runtime.Object) (admission.Warnings, error) { watcherapplierlog.Info("validate update", "name", r.Name) // TODO(user): fill in your validation logic upon object update. diff --git a/api/v1beta1/watcherdecisionengine_webhook.go b/api/v1beta1/watcherdecisionengine_webhook.go index 21f8cca..825988e 100644 --- a/api/v1beta1/watcherdecisionengine_webhook.go +++ b/api/v1beta1/watcherdecisionengine_webhook.go @@ -60,7 +60,7 @@ func (r *WatcherDecisionEngine) ValidateCreate() (admission.Warnings, error) { } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *WatcherDecisionEngine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { +func (r *WatcherDecisionEngine) ValidateUpdate(runtime.Object) (admission.Warnings, error) { watcherdecisionenginelog.Info("validate update", "name", r.Name) // TODO(user): fill in your validation logic upon object update. diff --git a/api/v1beta1/webhook_suite_test.go b/api/v1beta1/webhook_suite_test.go index 8ac63e2..b837fc9 100644 --- a/api/v1beta1/webhook_suite_test.go +++ b/api/v1beta1/webhook_suite_test.go @@ -25,8 +25,8 @@ import ( "testing" "time" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" //revive:disable:dot-imports + . "github.com/onsi/gomega" //revive:disable:dot-imports admissionv1beta1 "k8s.io/api/admission/v1beta1" //+kubebuilder:scaffold:imports @@ -37,6 +37,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/envtest" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" + "sigs.k8s.io/controller-runtime/pkg/webhook" + + metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" ) // These tests use Ginkgo (BDD-style Go testing framework). Refer to @@ -65,6 +68,10 @@ var _ = BeforeSuite(func() { ErrorIfCRDPathMissing: false, WebhookInstallOptions: envtest.WebhookInstallOptions{ Paths: []string{filepath.Join("..", "..", "config", "webhook")}, + // NOTE(gibi): if localhost is resolved to ::1 (ipv6) then starting + // the webhook fails as it try to parse the address as ipv4 and + // failing on the colons in ::1 + LocalServingHost: "127.0.0.1", }, } @@ -90,12 +97,17 @@ var _ = BeforeSuite(func() { // start webhook server using Manager webhookInstallOptions := &testEnv.WebhookInstallOptions mgr, err := ctrl.NewManager(cfg, ctrl.Options{ - Scheme: scheme, - Host: webhookInstallOptions.LocalServingHost, - Port: webhookInstallOptions.LocalServingPort, - CertDir: webhookInstallOptions.LocalServingCertDir, - LeaderElection: false, - MetricsBindAddress: "0", + Scheme: scheme, + Metrics: metricsserver.Options{ + BindAddress: "0", + }, + WebhookServer: webhook.NewServer( + webhook.Options{ + Host: webhookInstallOptions.LocalServingHost, + Port: webhookInstallOptions.LocalServingPort, + CertDir: webhookInstallOptions.LocalServingCertDir, + }), + LeaderElection: false, }) Expect(err).NotTo(HaveOccurred()) diff --git a/hack/clean_local_webhook.sh b/hack/clean_local_webhook.sh old mode 100644 new mode 100755 diff --git a/hack/run_with_local_webhook.sh b/hack/run_with_local_webhook.sh old mode 100644 new mode 100755 diff --git a/main.go b/main.go index c89670c..73bd4ac 100644 --- a/main.go +++ b/main.go @@ -164,7 +164,7 @@ func main() { setupLog.Error(err, "unable to create webhook", "webhook", "WatcherDecisionEngine") os.Exit(1) } - } + } if err := mgr.AddHealthzCheck("healthz", checker); err != nil { setupLog.Error(err, "unable to set up health check") os.Exit(1) @@ -179,4 +179,4 @@ func main() { setupLog.Error(err, "problem running manager") os.Exit(1) } -} \ No newline at end of file +}