You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: configure ENVTEST binaries for IDE execution and project-specific setup
- Installs ENVTEST binaries in the project’s `./bin/envtest` directory for isolation.
- Configures `setup-envtest` binary to be downloaded based on the controller-runtime release version to ensure compatibility with the project’s dependencies.
- Updates `suite_test.go` to dynamically locate and set the binary assets directory for seamless IDE debugging.
- Introduces `getFirstFoundEnvTestBinaryDir` to detect ENVTEST binaries in the project directory when running tests outside the Makefile context.
1. **Ease of IDE Debugging**:
- By setting the `BinaryAssetsDirectory` dynamically, contributors can debug tests in their preferred IDEs (e.g., GoLand, VSCode) without requiring additional environment configuration such as setting `KUBEBUILDER_ASSETS`.
2. **Project-Specific Binaries**:
- Installing binaries inside the project avoids conflicts with other projects or system-wide installations, particularly useful for contributors with restricted environments (e.g., corporate laptops).
3. **Consistency**:
- Using `setup-envtest` from the matching controller-runtime release avoids compatibility issues, such as those outlined in [#2744](kubernetes-sigs/controller-runtime#2744) and [#2646](kubernetes-sigs/controller-runtime#2646).
4. **Simplified Contributor Onboarding**:
- New contributors often face a learning curve to:
- Understand ENVTEST and its dependency on binaries.
- Configure `KUBEBUILDER_ASSETS` manually.
- Set up their IDE for debugging tests.
- This setup minimizes friction and ensures tests can be run consistently across different environments.
While setting `KUBEBUILDER_ASSETS` is sufficient for experienced contributors, this change makes it easier for newcomers and supports debugging directly in IDEs without additional configuration.
go test -count=1 -v ./test/extension-developer-e2e/...
153
153
154
-
.PHONY: test-unit
155
154
ENVTEST_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
155
+
CONTROLLER_RUNTIME_VERSION := release-$(shell go list -m sigs.k8s.io/controller-runtime | awk '{print $$2}' | sed -E 's/^v([0-9]+)\.([0-9]+)\..*/\1.\2/')
156
156
UNIT_TEST_DIRS := $(shell go list ./... | grep -v /test/)
157
157
COVERAGE_UNIT_DIR := $(ROOT_DIR)/coverage/unit
158
-
test-unit: $(SETUP_ENVTEST)#HELP Run the unit tests
158
+
159
+
.PHONY: setup-envtest #HELP Install setup-envtest binary in the bin directory.
160
+
setup-envtest:
161
+
mkdir -p $(ROOT_DIR)/bin
162
+
GOBIN=$(ROOT_DIR)/bin go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(CONTROLLER_RUNTIME_VERSION)
163
+
$(ROOT_DIR)/bin/setup-envtest use -p env $(ENVTEST_VERSION)$(SETUP_ENVTEST_BIN_DIR_OVERRIDE)
0 commit comments