From 095cef5851b4ced7ce40efc2449a10c648af1557 Mon Sep 17 00:00:00 2001 From: Rajdeep Das Date: Thu, 30 Nov 2023 19:25:04 +0530 Subject: [PATCH 1/2] Local dev / documentation improvement --- Makefile | 6 ++++-- docs/run-operator-locally.md | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 57aa50784..97a175258 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ test: generate fmt vet manifests ## Run unit tests manager: generate fmt vet ## Build operator binary go build -o bin/manager ./cmd/manager/main.go -run: install install-rbac ## Run the operator against the configured Kubernetes cluster in ~/.kube/config +run: install ## Run the operator against the configured Kubernetes cluster in ~/.kube/config eval $$(scripts/dev/get_e2e_env_vars.py $(cleanup)); \ go run ./cmd/manager/main.go @@ -116,6 +116,7 @@ manifests: controller-gen ## Generate manifests e.g. CRD, RBAC etc. # Run e2e tests locally using go build while also setting up a proxy in the shell to allow # the test to run as if it were inside the cluster. This enables mongodb connectivity while running locally. e2e-telepresence: cleanup-e2e install ## Run e2e tests locally using go build while also setting up a proxy e.g. make e2e-telepresence test=replica_set cleanup=true + export MDB_LOCAL_OPERATOR=true; \ telepresence connect; \ eval $$(scripts/dev/get_e2e_env_vars.py $(cleanup)); \ go test -v -timeout=30m -failfast $(options) ./test/e2e/$(test) ; \ @@ -139,7 +140,8 @@ cleanup-e2e: ## Cleans up e2e test env kubectl delete pv --all -n $(NAMESPACE) || true generate-env-file: ## generates a local-test.env for local testing - python scripts/dev/get_e2e_env_vars.py | cut -d' ' -f2 > .community-operator-dev/local-test.env + mkdir -p .community-operator-dev + { python scripts/dev/get_e2e_env_vars.py | tee >(cut -d' ' -f2 > .community-operator-dev/local-test.env) ;} > .community-operator-dev/local-test.export.env ##@ Image diff --git a/docs/run-operator-locally.md b/docs/run-operator-locally.md index 6b78a883e..65252b0f0 100644 --- a/docs/run-operator-locally.md +++ b/docs/run-operator-locally.md @@ -1,6 +1,6 @@ # Quick start for building and running the operator locally -This document contains a quickstart guide to build and running (+debugging) the operator locally. +This document contains a quickstart guide to build and running and debugging the operator locally. Being able to run and build the binary locally can help with faster feedback-cycles. ## Prerequisites @@ -12,6 +12,7 @@ Being able to run and build the binary locally can help with faster feedback-cyc - `KUBECONFIG` environment variable pointing at a file - **Note**: either of these are necessary to be able to run the operator locally - Have a folder `.community-operator-dev` +- *Optional - if you want to export the environment variables, you can run the following command*: `source .community-operator-dev/local-test.export.env` ## Goals - Run the operator locally as a binary (optionally in debug mode) in command line or in an IDE - Run e2e tests locally @@ -20,7 +21,7 @@ Being able to run and build the binary locally can help with faster feedback-cyc 1. Use the dedicated make target which exports the needed environment variables and builds & runs the operator binary ```sh -make run +make run ``` 2. For debugging one can use the following make target, which uses [dlv](https://github.com/go-delve/delve): From 8636498c3eb5faab92838a547b1782088f193efe Mon Sep 17 00:00:00 2001 From: Rajdeep Das Date: Thu, 30 Nov 2023 19:50:39 +0530 Subject: [PATCH 2/2] code review --- Makefile | 2 ++ docs/run-operator-locally.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 97a175258..1fdb6f56e 100644 --- a/Makefile +++ b/Makefile @@ -115,6 +115,8 @@ manifests: controller-gen ## Generate manifests e.g. CRD, RBAC etc. # Run e2e tests locally using go build while also setting up a proxy in the shell to allow # the test to run as if it were inside the cluster. This enables mongodb connectivity while running locally. +# "MDB_LOCAL_OPERATOR=true" ensures the operator pod is not spun up while running the e2e test - since you're +# running it locally. e2e-telepresence: cleanup-e2e install ## Run e2e tests locally using go build while also setting up a proxy e.g. make e2e-telepresence test=replica_set cleanup=true export MDB_LOCAL_OPERATOR=true; \ telepresence connect; \ diff --git a/docs/run-operator-locally.md b/docs/run-operator-locally.md index 65252b0f0..a46ecba56 100644 --- a/docs/run-operator-locally.md +++ b/docs/run-operator-locally.md @@ -12,7 +12,7 @@ Being able to run and build the binary locally can help with faster feedback-cyc - `KUBECONFIG` environment variable pointing at a file - **Note**: either of these are necessary to be able to run the operator locally - Have a folder `.community-operator-dev` -- *Optional - if you want to export the environment variables, you can run the following command*: `source .community-operator-dev/local-test.export.env` +- *Optional - if you want to export the environment variables, you can run the following command*: `source .community-operator-dev/local-test.export.env`. ( These environment variables are generated with the `make generate-env-file`) ## Goals - Run the operator locally as a binary (optionally in debug mode) in command line or in an IDE - Run e2e tests locally