Skip to content

Commit

Permalink
Makefile, webhook: add run-nowebhook (opendatahub-io#1286)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ykaliuta authored Oct 10, 2024
1 parent db0fa50 commit e8e266f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions controllers/webhook/nowebhook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build nowebhook

package webhook

import ctrl "sigs.k8s.io/controller-runtime"

func Init(mgr ctrl.Manager) {}
2 changes: 2 additions & 0 deletions controllers/webhook/webhook.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !nowebhook

/*
Copyright 2023.
Expand Down

0 comments on commit e8e266f

Please sign in to comment.