Skip to content

Commit 48cd062

Browse files
committed
Make targets to download the KUTTL executable
1 parent b40ab5a commit 48cd062

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

Makefile

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,17 @@ ifeq ("$(PGO_BASEOS)", "ubi8")
4747
PACKAGER=microdnf
4848
endif
4949

50+
# Setting SHELL to bash allows bash commands to be executed by recipes.
51+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
52+
SHELL = /usr/bin/env bash -O globstar -o pipefail
53+
.SHELLFLAGS = -ec
54+
5055
DEBUG_BUILD ?= false
5156
GO ?= go
5257
GO_BUILD = $(GO_CMD) build -trimpath
5358
GO_CMD = $(GO_ENV) $(GO)
5459
GO_TEST ?= $(GO) test
55-
KUTTL_TEST ?= kuttl test
60+
KUTTL_TEST ?= $(KUTTL) test
5661

5762
# Disable optimizations if creating a debug build
5863
ifeq ("$(DEBUG_BUILD)", "true")
@@ -210,7 +215,7 @@ check-envtest-existing: createnamespaces
210215
# Expects operator to be running
211216
.PHONY: check-kuttl
212217
check-kuttl:
213-
${PGO_KUBE_CLIENT} ${KUTTL_TEST} \
218+
${KUTTL_TEST} \
214219
--config testing/kuttl/kuttl-test.yaml
215220

216221
.PHONY: generate-kuttl
@@ -234,14 +239,12 @@ check-generate: generate-crd generate-deepcopy generate-rbac
234239
git diff --exit-code -- config/rbac
235240
git diff --exit-code -- pkg/apis
236241

237-
clean: clean-deprecated
242+
clean: clean-deprecated clean-tools
238243
rm -f bin/postgres-operator
239244
rm -f config/rbac/role.yaml
240245
[ ! -d testing/kuttl/e2e-generated ] || rm -r testing/kuttl/e2e-generated
241246
[ ! -d testing/kuttl/e2e-generated-other ] || rm -r testing/kuttl/e2e-generated-other
242247
[ ! -d build/crd/generated ] || rm -r build/crd/generated
243-
[ ! -d hack/tools/envtest ] || rm -r hack/tools/envtest
244-
[ ! -n "$$(ls hack/tools)" ] || rm hack/tools/*
245248
[ ! -d hack/.kube ] || rm -r hack/.kube
246249

247250
clean-deprecated:
@@ -306,3 +309,32 @@ hack/tools/envtest:
306309
license: licenses
307310
licenses:
308311
./bin/license_aggregator.sh ./cmd/...
312+
313+
## Tools
314+
315+
.PHONY: clean-tools tools
316+
clean-tools:
317+
rm -rf hack/krew hack/tools/envtest
318+
[ ! -n "$$(ls hack/tools)" ] || rm hack/tools/*
319+
320+
KREW ?= hack/tools/krew
321+
tools: tools/krew
322+
tools/krew:
323+
$(call go-get-tool,$(KREW),sigs.k8s.io/krew/cmd/[email protected])
324+
325+
KUTTL ?= hack/tools/kuttl
326+
tools: tools/kuttl
327+
tools/kuttl: tools/krew
328+
$(call krew-get-tool,$(KUTTL),kuttl)
329+
330+
# go-get-tool will 'go install' any package $2 and install it to $1.
331+
define go-get-tool
332+
@[ -f '$(1)' ] || { echo Downloading '$(2)'; GOBIN='$(abspath $(dir $(1)))' $(GO) install '$(2)'; }
333+
endef
334+
335+
# krew-get-tool will 'krew install' any plugin $2 and link it to $1.
336+
define krew-get-tool
337+
@[ -f '$(1)' ] || { KREW_ROOT='hack/krew' $(KREW) install '$(2)'; }
338+
@[ -f '$(1)' ] || { T="$$(readlink 'hack/krew/bin/kubectl-$(notdir $(1))')" && \
339+
[[ '$(1)' == hack/* ]] && ln -fs "..$${T#$(realpath hack)}" '$(1)'; }
340+
endef

0 commit comments

Comments
 (0)