From cb64222c7734485fb64e41319419e69ff8bef4f7 Mon Sep 17 00:00:00 2001 From: James Peach Date: Tue, 21 Dec 2021 08:59:44 +1100 Subject: [PATCH] fix(ci): set kubebuilder assets directory (#3577) The `dev/tools` make target installs testing dependencies into $CI_TOOLS_DIR, but the wiring between this and the kubebuilder envtest framework was broken. Make sure that we set the `KUBEBUILDER_ASSETS` environment variable so that the envtest framework can find its dependencies correctly. Signed-off-by: James Peach (cherry picked from commit a9b64a383aabb4214687d10048c3e7f6de4caa05) --- mk/dev.mk | 1 + mk/test.mk | 8 ++++---- pkg/plugins/resources/k8s/native/Makefile | 11 ++++------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/mk/dev.mk b/mk/dev.mk index ceacc7a146c7..e862644a10a0 100644 --- a/mk/dev.mk +++ b/mk/dev.mk @@ -281,4 +281,5 @@ dev/envrc: $(KUBECONFIG_DIR)/kind-kuma-current ## Generate .envrc @for prog in $(BUILD_RELEASE_BINARIES) $(BUILD_TEST_BINARIES) ; do \ echo "PATH_add $(BUILD_ARTIFACTS_DIR)/$$prog" ; \ done >> .envrc + @echo 'export KUBEBUILDER_ASSETS=$${CI_TOOLS_DIR}' >> .envrc @direnv allow diff --git a/mk/test.mk b/mk/test.mk index 8e21cfdd2483..fdc09b4f00aa 100644 --- a/mk/test.mk +++ b/mk/test.mk @@ -10,10 +10,10 @@ BUILD_COVERAGE_DIR ?= $(BUILD_DIR)/coverage COVERAGE_PROFILE := $(BUILD_COVERAGE_DIR)/coverage.out COVERAGE_REPORT_HTML := $(BUILD_COVERAGE_DIR)/coverage.html -# exports below are required for K8S unit tests -export TEST_ASSET_KUBE_APISERVER=$(KUBE_APISERVER_PATH) -export TEST_ASSET_ETCD=$(ETCD_PATH) -export TEST_ASSET_KUBECTL=$(KUBECTL_PATH) +# This environment variable sets where the kubebuilder envtest framework looks +# for etcd and other tools that is consumes. The `dev/install/kubebuilder` make +# target guaranteed to link these tools into $CI_TOOLS_DIR. +export KUBEBUILDER_ASSETS=$(CI_TOOLS_DIR) .PHONY: test test: ${COVERAGE_PROFILE} ## Dev: Run tests for all modules diff --git a/pkg/plugins/resources/k8s/native/Makefile b/pkg/plugins/resources/k8s/native/Makefile index b5f277324c61..27f284b09c40 100644 --- a/pkg/plugins/resources/k8s/native/Makefile +++ b/pkg/plugins/resources/k8s/native/Makefile @@ -10,13 +10,10 @@ GOPATH_DIR := $(shell go env GOPATH | awk -F: '{print $$1}') GOPATH_BIN_DIR := $(GOPATH_DIR)/bin export PATH := $(CI_TOOLS_DIR):$(GOPATH_BIN_DIR):$(PATH) -KUBE_APISERVER_PATH := $(CI_TOOLS_DIR)/kube-apiserver -ETCD_PATH := $(CI_TOOLS_DIR)/etcd -KUBECTL_PATH := $(CI_TOOLS_DIR)/kubectl - -export TEST_ASSET_KUBE_APISERVER=$(KUBE_APISERVER_PATH) -export TEST_ASSET_ETCD=$(ETCD_PATH) -export TEST_ASSET_KUBECTL=$(KUBECTL_PATH) +# This environment variable sets where the kubebuilder envtest framework looks +# for etcd and other tools that is consumes. The `dev/install/kubebuilder` make +# target guaranteed to link these tools into $CI_TOOLS_DIR. +export KUBEBUILDER_ASSETS=$(CI_TOOLS_DIR) CONTROLLER_GEN := go run -mod=mod sigs.k8s.io/controller-tools/cmd/controller-gen