mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-19 22:21:46 +00:00
Merge pull request #2288 from aryan9600/aryan9600/setup-testenv
Fix makefile envtest setup and usage
This commit is contained in:
commit
7f580e89d0
3 changed files with 28 additions and 24 deletions
4
.github/workflows/e2e.yaml
vendored
4
.github/workflows/e2e.yaml
vendored
|
|
@ -29,10 +29,6 @@ jobs:
|
||||||
version: v0.11.1
|
version: v0.11.1
|
||||||
image: kindest/node:v1.19.11@sha256:07db187ae84b4b7de440a73886f008cf903fcf5764ba8106a9fd5243d6f32729
|
image: kindest/node:v1.19.11@sha256:07db187ae84b4b7de440a73886f008cf903fcf5764ba8106a9fd5243d6f32729
|
||||||
config: .github/kind/config.yaml # disable KIND-net
|
config: .github/kind/config.yaml # disable KIND-net
|
||||||
- name: Setup envtest
|
|
||||||
uses: fluxcd/pkg/actions/envtest@main
|
|
||||||
with:
|
|
||||||
version: "1.21.x"
|
|
||||||
- name: Setup Calico for network policy
|
- name: Setup Calico for network policy
|
||||||
run: |
|
run: |
|
||||||
kubectl apply -f https://docs.projectcalico.org/v3.20/manifests/calico.yaml
|
kubectl apply -f https://docs.projectcalico.org/v3.20/manifests/calico.yaml
|
||||||
|
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -20,6 +20,7 @@ bin/
|
||||||
output/
|
output/
|
||||||
cmd/flux/manifests/
|
cmd/flux/manifests/
|
||||||
cmd/flux/.manifests.done
|
cmd/flux/.manifests.done
|
||||||
|
testbin/
|
||||||
|
|
||||||
# Docs
|
# Docs
|
||||||
site/
|
site/
|
||||||
|
|
|
||||||
47
Makefile
47
Makefile
|
|
@ -1,8 +1,8 @@
|
||||||
VERSION?=$(shell grep 'VERSION' cmd/flux/main.go | awk '{ print $$4 }' | head -n 1 | tr -d '"')
|
VERSION?=$(shell grep 'VERSION' cmd/flux/main.go | awk '{ print $$4 }' | head -n 1 | tr -d '"')
|
||||||
EMBEDDED_MANIFESTS_TARGET=cmd/flux/.manifests.done
|
EMBEDDED_MANIFESTS_TARGET=cmd/flux/.manifests.done
|
||||||
TEST_KUBECONFIG?=/tmp/flux-e2e-test-kubeconfig
|
TEST_KUBECONFIG?=/tmp/flux-e2e-test-kubeconfig
|
||||||
ENVTEST_BIN_VERSION?=latest
|
# Architecture to use envtest with
|
||||||
KUBEBUILDER_ASSETS?=$(shell $(SETUP_ENVTEST) use -i $(ENVTEST_BIN_VERSION) -p path)
|
ENVTEST_ARCH ?= amd64
|
||||||
|
|
||||||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
||||||
ifeq (,$(shell go env GOBIN))
|
ifeq (,$(shell go env GOBIN))
|
||||||
|
|
@ -34,6 +34,7 @@ cleanup-kind:
|
||||||
kind delete cluster --name=flux-e2e-test
|
kind delete cluster --name=flux-e2e-test
|
||||||
rm $(TEST_KUBECONFIG)
|
rm $(TEST_KUBECONFIG)
|
||||||
|
|
||||||
|
KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)"
|
||||||
test: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet install-envtest
|
test: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet install-envtest
|
||||||
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... -coverprofile cover.out --tags=unit
|
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... -coverprofile cover.out --tags=unit
|
||||||
|
|
||||||
|
|
@ -59,27 +60,33 @@ install:
|
||||||
install-dev:
|
install-dev:
|
||||||
CGO_ENABLED=0 go build -o /usr/local/bin ./cmd/flux
|
CGO_ENABLED=0 go build -o /usr/local/bin ./cmd/flux
|
||||||
|
|
||||||
install-envtest: setup-envtest
|
|
||||||
$(SETUP_ENVTEST) use $(ENVTEST_BIN_VERSION)
|
|
||||||
|
|
||||||
setup-bootstrap-patch:
|
setup-bootstrap-patch:
|
||||||
go run ./tests/bootstrap/main.go
|
go run ./tests/bootstrap/main.go
|
||||||
|
|
||||||
setup-image-automation:
|
setup-image-automation:
|
||||||
cd tests/image-automation && go run main.go
|
cd tests/image-automation && go run main.go
|
||||||
|
|
||||||
# Find or download setup-envtest
|
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
|
||||||
setup-envtest:
|
ENVTEST_KUBERNETES_VERSION?=latest
|
||||||
ifeq (, $(shell which setup-envtest))
|
install-envtest: setup-envtest
|
||||||
@{ \
|
mkdir -p ${ENVTEST_ASSETS_DIR}
|
||||||
set -e ;\
|
$(ENVTEST) use $(ENVTEST_KUBERNETES_VERSION) --arch=$(ENVTEST_ARCH) --bin-dir=$(ENVTEST_ASSETS_DIR)
|
||||||
SETUP_ENVTEST_TMP_DIR=$$(mktemp -d) ;\
|
|
||||||
cd $$SETUP_ENVTEST_TMP_DIR ;\
|
ENVTEST = $(shell pwd)/bin/setup-envtest
|
||||||
go mod init tmp ;\
|
.PHONY: envtest
|
||||||
go get sigs.k8s.io/controller-runtime/tools/setup-envtest@latest ;\
|
setup-envtest: ## Download envtest-setup locally if necessary.
|
||||||
rm -rf $$SETUP_ENVTEST_TMP_DIR ;\
|
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
|
||||||
}
|
|
||||||
SETUP_ENVTEST=$(GOBIN)/setup-envtest
|
# go-install-tool will 'go install' any package $2 and install it to $1.
|
||||||
else
|
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
|
||||||
SETUP_ENVTEST=$(shell which setup-envtest)
|
define go-install-tool
|
||||||
endif
|
@[ -f $(1) ] || { \
|
||||||
|
set -e ;\
|
||||||
|
TMP_DIR=$$(mktemp -d) ;\
|
||||||
|
cd $$TMP_DIR ;\
|
||||||
|
go mod init tmp ;\
|
||||||
|
echo "Downloading $(2)" ;\
|
||||||
|
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
|
||||||
|
rm -rf $$TMP_DIR ;\
|
||||||
|
}
|
||||||
|
endef
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue