Skip to content

Commit 5cb740f

Browse files
authored
Merge pull request #340 from dmvolod/download-cluser-api-crd-for-each-test
🌱 Download Cluster API CRDs for every integration test
2 parents 00030ec + 7967a26 commit 5cb740f

File tree

4 files changed

+8
-1390
lines changed

4 files changed

+8
-1390
lines changed

Makefile

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ SHELL:=/usr/bin/env bash
2323
#
2424
# Go.
2525
#
26-
GO_VERSION ?= 1.22.9
26+
GO_VERSION ?= $(shell go mod edit --print | grep -oP '(?<=toolchain go).*' || go mod edit --print | grep "go " | head -1 | awk '{print $$2}')
2727
GO_BASE_CONTAINER ?= docker.io/library/golang
2828
GO_CONTAINER_IMAGE ?= $(GO_BASE_CONTAINER):$(GO_VERSION)
2929

@@ -121,7 +121,7 @@ KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER))
121121
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v5
122122

123123
CLUSTER_API_VERSION := $(call get_go_version,sigs.k8s.io/cluster-api)
124-
CLUSTER_API_CRD_LOCATION = test/controllers/data/crd
124+
CLUSTER_API_CRD_LOCATION = tmp/cluster-api/crd
125125

126126
MOCKGEN_VER := v0.4.0
127127
MOCKGEN_BIN := mockgen
@@ -300,6 +300,8 @@ generate-modules: ## Run go mod tidy to ensure modules are up to date
300300

301301
.PHONY: download-cluster-api-crd
302302
download-cluster-api-crd: generate-modules ## Run to download Cluster API CRDs for tests
303+
mkdir -p $(CLUSTER_API_CRD_LOCATION)
304+
rm -f $(CLUSTER_API_CRD_LOCATION)/*
303305
cp -r $(shell go env GOPATH)/pkg/mod/sigs.k8s.io/cluster-api@$(CLUSTER_API_VERSION)/config/crd/bases/cluster.x-k8s.io_clusters.yaml $(CLUSTER_API_CRD_LOCATION)
304306
chmod 644 $(CLUSTER_API_CRD_LOCATION)/*
305307

@@ -425,7 +427,7 @@ KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILD
425427
install-tools: $(ENVSUBST) $(KUSTOMIZE) $(HELM) $(GINKGO) # Should kubectl be added here?
426428

427429
.PHONY: test
428-
test: $(SETUP_ENVTEST) ## Run unit and integration tests
430+
test: $(SETUP_ENVTEST) download-cluster-api-crd ## Run unit and integration tests
429431
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... $(TEST_ARGS)
430432

431433
.PHONY: test-verbose

config/manager/manager.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ spec:
4646
value: /tmp/xdg/.cache
4747
- name: XDG_CONFIG_DIRS
4848
value: /tmp/xdg
49+
- name: KUBECACHEDIR
50+
value: /tmp/.kube/cache
4951
image: controller:latest
5052
imagePullPolicy: Always
5153
name: manager

controllers/suite_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ var _ = BeforeSuite(func() {
9595
testEnv = &envtest.Environment{
9696
CRDDirectoryPaths: []string{
9797
filepath.Join("..", "config", "crd", "bases"),
98-
filepath.Join("..", "test", "controllers", "data", "crd"),
98+
filepath.Join("..", "tmp", "cluster-api", "crd"),
9999
},
100100
ErrorIfCRDPathMissing: true,
101101
}

0 commit comments

Comments
 (0)