Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit 7906a9d

Browse files
authored
running the operator locally instead of in a cluster (#1190)
* adds documentation on how to run the operator locally
1 parent 832e238 commit 7906a9d

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ TEST ?= ./pkg/... ./api/... ./cmd/... ./controllers/... ./test/e2e/util/mongotes
4545
test: generate fmt vet manifests ## Run unit tests
4646
go test $(TEST) -coverprofile cover.out
4747

48-
manager: generate fmt vet ## Build manager binary
48+
manager: generate fmt vet ## Build operator binary
4949
go build -o bin/manager ./cmd/manager/main.go
5050

51-
run: install install-rbac ## Run against the configured Kubernetes cluster in ~/.kube/config
51+
run: install install-rbac ## Run the operator against the configured Kubernetes cluster in ~/.kube/config
5252
eval $$(scripts/dev/get_e2e_env_vars.py $(cleanup)); \
5353
go run ./cmd/manager/main.go
5454

55-
debug: install install-rbac
55+
debug: install install-rbac ## Run the operator in debug mode with dlv
5656
eval $$(scripts/dev/get_e2e_env_vars.py $(cleanup)); \
5757
dlv debug ./cmd/manager/main.go
5858

@@ -138,6 +138,9 @@ cleanup-e2e: ## Cleans up e2e test env
138138
# avoid interleaving tests with each other, we need to drop them all.
139139
kubectl delete pvc --all -n $(NAMESPACE) || true
140140

141+
generate-env-file: ## generates a local-test.env for local testing
142+
python scripts/dev/get_e2e_env_vars.py | cut -d' ' -f2 > .community-operator-dev/local-test.env
143+
141144
##@ Image
142145

143146
operator-image: ## Build and push the operator image

docs/run-operator-locally.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Quick start for building and running the operator locally
2+
3+
This document contains a quickstart guide to build and running (+debugging) the operator locally.
4+
Being able to run and build the binary locally can help with faster feedback-cycles.
5+
6+
## Prerequisites
7+
- Follow the general setup to be able to run e2e tests locally with our suite as described here, which includes the usage of [telepresence](https://www.getambassador.io/docs/telepresence/latest/quick-start/):
8+
- [contributing.md](contributing.md)
9+
- [build_operator_locally.md](build_operator_locally.md)
10+
- If above has been configured there should be either:
11+
- `$HOME/.kube/config`
12+
- `KUBECONFIG` environment variable pointing at a file
13+
- **Note**: either of these are necessary to be able to run the operator locally
14+
- Have a folder `.community-operator-dev`
15+
## Goals
16+
- Run the operator locally as a binary (optionally in debug mode) in command line or in an IDE
17+
- Run e2e tests locally
18+
19+
## Running The Operator locally
20+
1. Use the dedicated make target which exports the needed environment variables and builds & runs the operator binary
21+
22+
```sh
23+
make run
24+
```
25+
26+
2. For debugging one can use the following make target, which uses [dlv](https://github.com/go-delve/delve):
27+
28+
```sh
29+
make debug
30+
```
31+
32+
## Running e2e tests with the local operator
33+
- Our [e2e tests](../test/e2e), contains sub-steps that will install the following helm-chart: [operator.yaml](../helm-charts/charts/community-operator/templates/operator.yaml)
34+
- By default, the template chart sets the number of operator replicas to `1`. This will clash with our local running operator. With this in mind the solution is to set the replicas number to `0` temporarily.
35+
- Follow the guide on how to run `e2e` tests as described in our [contributing.md](contributing.md), for instance:
36+
37+
```sh
38+
make e2e-telepresence test=<test-name>
39+
```

0 commit comments

Comments
 (0)