Skip to content

Commit

Permalink
Fix functional tests and pre-commit
Browse files Browse the repository at this point in the history
Signed-off-by: Chandan Kumar <[email protected]>
  • Loading branch information
raukadah committed Nov 27, 2024
1 parent feb8447 commit 202682a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/watcher_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/watcherapi_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/watcherapplier_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/watcherdecisionengine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 20 additions & 8 deletions api/v1beta1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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",
},
}

Expand All @@ -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())

Expand Down
Empty file modified hack/clean_local_webhook.sh
100644 → 100755
Empty file.
Empty file modified hack/run_with_local_webhook.sh
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -179,4 +179,4 @@ func main() {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}
}

0 comments on commit 202682a

Please sign in to comment.