From e8e266f543d7f944ecec92fe7cdf85f616471171 Mon Sep 17 00:00:00 2001 From: Yauheni Kaliuta Date: Thu, 10 Oct 2024 12:03:15 +0300 Subject: [PATCH] Makefile, webhook: add run-nowebhook (#1286) Make it possible to compile operator without webhook enabled (with -tags nowebhook). Create a stub webhook.Init() function for that. Add run-nowebhook target to run webhook locally. It requires `make install` to be executed on the cluster beforehand. Since it repeats `make run`, move the command to a variable. Also use variable RUN_ARGS for operator arguments. It makes it possible to override them from the command line. In VSCode it is possible to debug it with the following example launch.json configuration: ``` { "name": "Debug Operator No Webhook", "type": "go", "request": "launch", "mode": "debug", "program": "main.go", "buildFlags": [ "-tags", "nowebhook" ], "env": { "OPERATOR_NAMESPACE": "opendatahub-operator-system", "DEFAULT_MANIFESTS_PATH": "./opt/manifests" }, "args": [ "--log-mode=devel" ], "cwd": "${workspaceFolder}", } ``` Signed-off-by: Yauheni Kaliuta --- Makefile | 9 ++++++++- controllers/webhook/nowebhook.go | 7 +++++++ controllers/webhook/webhook.go | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 controllers/webhook/nowebhook.go diff --git a/Makefile b/Makefile index 9fdf869a51b..7ba0b5047ed 100644 --- a/Makefile +++ b/Makefile @@ -180,9 +180,16 @@ api-docs: crd-ref-docs ## Creates API docs using https://github.com/elastic/crd- build: generate fmt vet ## Build manager binary. go build -o bin/manager main.go +RUN_ARGS = --log-mode=devel +GO_RUN_MAIN = OPERATOR_NAMESPACE=$(OPERATOR_NAMESPACE) DEFAULT_MANIFESTS_PATH=$(DEFAULT_MANIFESTS_PATH) go run $(GO_RUN_ARGS) ./main.go $(RUN_ARGS) .PHONY: run run: manifests generate fmt vet ## Run a controller from your host. - OPERATOR_NAMESPACE=$(OPERATOR_NAMESPACE) DEFAULT_MANIFESTS_PATH=${DEFAULT_MANIFESTS_PATH} go run ./main.go --log-mode=devel + $(GO_RUN_MAIN) + +.PHONY: run-nowebhook +run-nowebhook: GO_RUN_ARGS += -tags nowebhook +run-nowebhook: manifests generate fmt vet ## Run a controller from your host without webhook enabled + $(GO_RUN_MAIN) .PHONY: image-build image-build: # unit-test ## Build image with the manager. diff --git a/controllers/webhook/nowebhook.go b/controllers/webhook/nowebhook.go new file mode 100644 index 00000000000..dc8eefe7533 --- /dev/null +++ b/controllers/webhook/nowebhook.go @@ -0,0 +1,7 @@ +//go:build nowebhook + +package webhook + +import ctrl "sigs.k8s.io/controller-runtime" + +func Init(mgr ctrl.Manager) {} diff --git a/controllers/webhook/webhook.go b/controllers/webhook/webhook.go index 29739e2af00..5a539667b91 100644 --- a/controllers/webhook/webhook.go +++ b/controllers/webhook/webhook.go @@ -1,3 +1,5 @@ +//go:build !nowebhook + /* Copyright 2023.