Skip to content

Commit bfbe0d2

Browse files
committed
Use bin-dir override on setup_envtest
Rather than change XDG_DATA_HOME, since many distributions do not explicitly define XDG_DATA_HOME but rather fallback to the default, check if XDG_DATA_HOME is not set and if HOME is either not set or set to the root filesystem. If so, override the setup_envtest binary directory. This helps prevent errors on some CI/CD environments. Signed-off-by: Tayler Geiger <[email protected]>
1 parent 265d60d commit bfbe0d2

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ export WAIT_TIMEOUT ?= 60s
1212
IMG?=$(IMAGE_REPO):$(IMAGE_TAG)
1313
TESTDATA_DIR := testdata
1414

15-
# setup-envtest on *nix uses XDG_DATA_HOME, falling back to HOME, as the default storage directory. Some CI setups
16-
# don't have XDG_DATA_HOME set; in those cases, we set it here so setup-envtest functions correctly. This shouldn't
17-
# affect developers.
18-
export XDG_DATA_HOME ?= /tmp/.local/share
15+
# By default setup-envtest will write to $XDG_DATA_HOME, or $HOME/.local/share if that is not defined.
16+
# If $HOME is not set, we need to specify a binary directory to prevent an error in setup-envtest.
17+
# Useful for some CI/CD environments that set neither $XDG_DATA_HOME nor $HOME.
18+
setup_envtest_bin_dir_override=
19+
ifeq ($(shell [[ $$HOME == "" || $$HOME == "/" ]] && [[ $$XDG_DATA_HOME == "" ]] && echo true ), true)
20+
setup_envtest_bin_dir_override += --bin-dir /tmp/envtest-binaries
21+
endif
1922

2023
# bingo manages consistent tooling versions for things like kind, kustomize, etc.
2124
include .bingo/Variables.mk
@@ -125,7 +128,7 @@ test-ext-dev-e2e: $(SETUP_ENVTEST) $(OPERATOR_SDK) $(KUSTOMIZE) $(KIND) #HELP Ru
125128
ENVTEST_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
126129
UNIT_TEST_DIRS=$(shell go list ./... | grep -v /test/)
127130
test-unit: $(SETUP_ENVTEST) #HELP Run the unit tests
128-
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION)) && go test -tags $(GO_BUILD_TAGS) -count=1 -short $(UNIT_TEST_DIRS) -coverprofile cover.out
131+
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION)) $(setup_envtest_bin_dir_override) && go test -tags $(GO_BUILD_TAGS) -count=1 -short $(UNIT_TEST_DIRS) -coverprofile cover.out
129132

130133
E2E_REGISTRY_NAME=docker-registry
131134
E2E_REGISTRY_NAMESPACE=operator-controller-e2e

0 commit comments

Comments
 (0)