Skip to content

Commit eea1a48

Browse files
committed
Use setup-envtest from 0.19 controller-runtime repo
The controller-runtime package that operator uses remains at 0.17 This PR is intentionally minimal to unblock CI environment and minimize cherry-pick conflict.
1 parent b99f578 commit eea1a48

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,4 @@ _output
9494
*.swo
9595
*~
9696

97-
# controller-runtime testenv binaries
98-
testbin/*
99-
10097
3scale-operator

Makefile

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,9 @@ test-manifests-version:
8282
# Run e2e tests
8383
TEST_E2E_PKGS_APPS = $(shell $(GO) list ./... | grep 'github.com/3scale/3scale-operator/controllers/apps')
8484
TEST_E2E_PKGS_CAPABILITIES = $(shell $(GO) list ./... | grep 'github.com/3scale/3scale-operator/controllers/capabilities')
85-
ENVTEST_ASSETS_DIR=$(PROJECT_PATH)/testbin
86-
test-e2e: generate fmt vet manifests
87-
mkdir -p ${ENVTEST_ASSETS_DIR}
88-
test -f $(ENVTEST_ASSETS_DIR)/setup-envtest.sh || curl -sSLo $(ENVTEST_ASSETS_DIR)/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.0/hack/setup-envtest.sh
89-
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); USE_EXISTING_CLUSTER=true $(GO) test $(TEST_E2E_PKGS_APPS) -coverprofile cover.out -ginkgo.v -v -timeout 0
90-
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); USE_EXISTING_CLUSTER=true $(GO) test $(TEST_E2E_PKGS_CAPABILITIES) -coverprofile cover.out -v -timeout 0
85+
test-e2e: generate fmt vet manifests setup-envtest
86+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" USE_EXISTING_CLUSTER=true $(GO) test $(TEST_E2E_PKGS_APPS) -coverprofile cover.out -ginkgo.v -v -timeout 0
87+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" USE_EXISTING_CLUSTER=true $(GO) test $(TEST_E2E_PKGS_CAPABILITIES) -coverprofile cover.out -v -timeout 0
9188

9289

9390
# Build manager binary
@@ -160,6 +157,46 @@ $(KUSTOMIZE):
160157
.PHONY: kustomize
161158
kustomize: $(KUSTOMIZE)
162159

160+
## Location to install dependencies to
161+
LOCALBIN ?= $(PROJECT_PATH)/bin
162+
$(LOCALBIN):
163+
mkdir -p $(LOCALBIN)
164+
165+
ENVTEST ?= $(LOCALBIN)/setup-envtest
166+
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
167+
ENVTEST_VERSION ?= release-0.19 ## pinning to 0.19 to match golang 1.22 in CI environment
168+
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
169+
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
170+
171+
.PHONY: setup-envtest
172+
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
173+
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
174+
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
175+
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
176+
exit 1; \
177+
}
178+
179+
.PHONY: envtest
180+
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
181+
$(ENVTEST): $(LOCALBIN)
182+
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
183+
184+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
185+
# $1 - target path with name of binary
186+
# $2 - package url which can be installed
187+
# $3 - specific version of package
188+
define go-install-tool
189+
@[ -f "$(1)-$(3)" ] || { \
190+
set -e; \
191+
package=$(2)@$(3) ;\
192+
echo "Downloading $${package}" ;\
193+
rm -f $(1) || true ;\
194+
GOBIN=$(LOCALBIN) go install $${package} ;\
195+
mv $(1) $(1)-$(3) ;\
196+
} ;\
197+
ln -sf $(1)-$(3) $(1)
198+
endef
199+
163200
OPERATOR_SDK = $(PROJECT_PATH)/bin/operator-sdk
164201
# Note: release file patterns changed after v1.2.0
165202
# More info https://sdk.operatorframework.io/docs/installation/

0 commit comments

Comments
 (0)