Skip to content

Commit 1dcaeca

Browse files
committed
Run recent testing tools rather than install them
This makes it slightly easier to clone the project and immediately run tests. One may continue to use pre-installed tools by calling Make targets with the ENVTEST and KUTTL variables.
1 parent 4ab9a93 commit 1dcaeca

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

.github/workflows/test.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ jobs:
1818
- uses: actions/checkout@v4
1919
- uses: actions/setup-go@v5
2020
with: { go-version: stable }
21-
- run: make check
22-
- run: make check-generate
2321

2422
- name: Ensure go.mod is tidy
2523
run: go mod tidy && git diff --exit-code -- go.mod
24+
- name: Ensure generated files are committed
25+
run: make check-generate
26+
- run: make check
2627

2728
kubernetes-api:
2829
runs-on: ubuntu-24.04
@@ -35,6 +36,7 @@ jobs:
3536
- uses: actions/checkout@v4
3637
- uses: actions/setup-go@v5
3738
with: { go-version: stable }
39+
3840
- run: go mod download
3941
- run: ENVTEST_K8S_VERSION="${KUBERNETES#default}" make check-envtest
4042
env:
@@ -163,7 +165,8 @@ jobs:
163165
echo '::group::PGO logs'; docker logs 'postgres-operator'; echo '::endgroup::'
164166
exit $failed
165167
env:
166-
KUTTL_TEST: kubectl-kuttl test
168+
KUTTL: kubectl-kuttl
169+
167170
- name: Stop PGO
168171
run: docker stop 'postgres-operator' || true
169172

Makefile

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ GO_TEST ?= $(GO) test
2020
# by managing them together in the main module.
2121
CONTROLLER ?= $(GO) tool sigs.k8s.io/controller-tools/cmd/controller-gen
2222

23-
KUTTL ?= kubectl-kuttl
23+
# Run tests using the latest tools.
24+
ENVTEST ?= $(GO) run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
25+
KUTTL ?= $(GO) run github.com/kudobuilder/kuttl/pkg/kuttlctl/cmd/kubectl-kuttl@latest
2426
KUTTL_TEST ?= $(KUTTL) test
2527

28+
2629
##@ General
2730

2831
# The help target prints out all targets with their descriptions organized
@@ -67,7 +70,6 @@ clean: clean-deprecated
6770
rm -f bin/postgres-operator
6871
rm -rf licenses/*/
6972
[ ! -d testing/kuttl/e2e-generated ] || rm -r testing/kuttl/e2e-generated
70-
[ ! -f hack/tools/setup-envtest ] || rm hack/tools/setup-envtest
7173
[ ! -d hack/tools/envtest ] || { chmod -R u+w hack/tools/envtest && rm -r hack/tools/envtest; }
7274
[ ! -d hack/tools/pgmonitor ] || rm -rf hack/tools/pgmonitor
7375
[ ! -d hack/tools/external-snapshotter ] || rm -rf hack/tools/external-snapshotter
@@ -97,6 +99,7 @@ clean-deprecated: ## Clean deprecated resources
9799
[ ! -d testing/kuttl/e2e-generated-other ] || rm -r testing/kuttl/e2e-generated-other
98100
@# Tools used to be downloaded directly
99101
[ ! -f hack/tools/controller-gen ] || rm hack/tools/controller-gen
102+
[ ! -f hack/tools/setup-envtest ] || rm hack/tools/setup-envtest
100103

101104

102105
##@ Deployment
@@ -206,7 +209,7 @@ check: get-pgmonitor
206209
check-envtest: ## Run check using envtest and a mock kube api
207210
check-envtest: ENVTEST_USE = $(ENVTEST) --bin-dir=$(CURDIR)/hack/tools/envtest use $(ENVTEST_K8S_VERSION)
208211
check-envtest: SHELL = bash
209-
check-envtest: get-pgmonitor tools/setup-envtest
212+
check-envtest: get-pgmonitor
210213
@$(ENVTEST_USE) --print=overview && echo
211214
source <($(ENVTEST_USE) --print=env) && PGO_NAMESPACE="postgres-operator" QUERIES_CONFIG_DIR="$(CURDIR)/${QUERIES_CONFIG_DIR}" \
212215
$(GO_TEST) -count=1 -cover ./...
@@ -299,20 +302,6 @@ generate-rbac: ## Generate RBAC
299302
paths='./cmd/...' paths='./internal/...' \
300303
output:dir='config/rbac' # {directory}/role.yaml
301304

302-
##@ Tools
303-
304-
.PHONY: tools
305-
tools: ## Download tools like controller-gen and kustomize if necessary.
306-
307-
# go-get-tool will 'go install' any package $2 and install it to $1.
308-
define go-get-tool
309-
@[ -f '$(1)' ] || { echo Downloading '$(2)'; GOBIN='$(abspath $(dir $(1)))' $(GO) install '$(2)'; }
310-
endef
311-
312-
ENVTEST ?= hack/tools/setup-envtest
313-
tools: tools/setup-envtest
314-
tools/setup-envtest:
315-
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
316305

317306
##@ Release
318307

0 commit comments

Comments
 (0)