Skip to content

Commit aef56d8

Browse files
authored
Merge pull request #404 from darkowlzz/setup-envtest
Add setup-envtest in Makefile
2 parents 273f8b1 + cb3fb3b commit aef56d8

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

.github/actions/run-tests/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ RUN set -eux; \
1717
RUN groupadd -g 116 test && \
1818
useradd -u 1001 --gid test --shell /bin/sh --create-home test
1919

20+
# Set path to envtest binaries.
21+
ENV PATH="/github/workspace/envtest:${PATH}"
22+
2023
# Run as test user
2124
USER test
2225

.github/workflows/e2e.yaml

+4-7
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ jobs:
2626
image: kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
2727
- name: Setup Kustomize
2828
uses: fluxcd/pkg/actions/kustomize@main
29-
- name: Setup Kubebuilder
30-
uses: fluxcd/pkg/actions/kubebuilder@main
29+
- name: Setup envtest
30+
uses: fluxcd/pkg/actions/envtest@main
31+
with:
32+
version: "1.19.2"
3133
- name: Setup Helm
3234
uses: fluxcd/pkg/actions/helm@main
3335
- name: Run tests
3436
uses: ./.github/actions/run-tests
3537
env:
3638
GOPATH: /github/home/go
37-
KUBEBUILDER_ASSETS: ${{ github.workspace }}/kubebuilder/bin
3839
- name: Check if working tree is dirty
3940
run: |
4041
if [[ $(git diff --stat) != '' ]]; then
@@ -44,14 +45,10 @@ jobs:
4445
fi
4546
- name: Build container image
4647
run: make docker-build IMG=test/source-controller:latest
47-
env:
48-
KUBEBUILDER_ASSETS: ${{ github.workspace }}/kubebuilder/bin
4948
- name: Load test image
5049
run: kind load docker-image test/source-controller:latest
5150
- name: Deploy controller
5251
run: make dev-deploy IMG=test/source-controller:latest
53-
env:
54-
KUBEBUILDER_ASSETS: ${{ github.workspace }}/kubebuilder/bin
5552
- name: Run smoke tests
5653
run: |
5754
kubectl -n source-system apply -f ./config/samples

Makefile

+21-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ IMG ?= fluxcd/source-controller:latest
33
# Produce CRDs that work back to Kubernetes 1.16
44
CRD_OPTIONS ?= crd:crdVersions=v1
55

6+
ENVTEST_BIN_VERSION?=1.19.2
7+
KUBEBUILDER_ASSETS?=$(shell $(SETUP_ENVTEST) use -i $(ENVTEST_BIN_VERSION) -p path)
8+
69
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
710
ifeq (,$(shell go env GOBIN))
811
GOBIN=$(shell go env GOPATH)/bin
@@ -13,8 +16,8 @@ endif
1316
all: manager
1417

1518
# Run tests
16-
test: generate fmt vet manifests api-docs
17-
go test ./... -coverprofile cover.out
19+
test: generate fmt vet manifests api-docs setup-envtest
20+
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./... -coverprofile cover.out
1821
cd api; go test ./... -coverprofile cover.out
1922

2023
# Build manager binary
@@ -112,3 +115,19 @@ API_REF_GEN=$(GOBIN)/gen-crd-api-reference-docs
112115
else
113116
API_REF_GEN=$(shell which gen-crd-api-reference-docs)
114117
endif
118+
119+
# Find or download setup-envtest
120+
setup-envtest:
121+
ifeq (, $(shell which setup-envtest))
122+
@{ \
123+
set -e ;\
124+
SETUP_ENVTEST_TMP_DIR=$$(mktemp -d) ;\
125+
cd $$SETUP_ENVTEST_TMP_DIR ;\
126+
go mod init tmp ;\
127+
go get sigs.k8s.io/controller-runtime/tools/setup-envtest@latest ;\
128+
rm -rf $$SETUP_ENVTEST_TMP_DIR ;\
129+
}
130+
SETUP_ENVTEST=$(GOBIN)/setup-envtest
131+
else
132+
SETUP_ENVTEST=$(shell which setup-envtest)
133+
endif

0 commit comments

Comments
 (0)