Skip to content

Commit 34941d1

Browse files
authored
OADP-1.4: ensure tool versions are visible and installed correctly (#1932)
* ensure tool versions are visible and installed correctly same as: #1928 #1929 Note there are some differences between branches: * note the versions * note slightly different functions Signed-off-by: Wesley Hayutin <[email protected]> * fix yq version * fix version check on yq * adding goproxy,gosumdb Seems to help when switching around go versions Signed-off-by: Wesley Hayutin <[email protected]> --------- Signed-off-by: Wesley Hayutin <[email protected]>
1 parent 7f0fd06 commit 34941d1

File tree

1 file changed

+244
-59
lines changed

1 file changed

+244
-59
lines changed

Makefile

Lines changed: 244 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,105 @@ OC_CLI = $(shell which oc)
3232
TEST_VIRT ?= false
3333
TEST_UPGRADE ?= false
3434

35+
# TOOL VERSIONS
36+
# All version-related variables are defined here for easy maintenance
37+
DEFAULT_VERSION := 1.4.0
38+
VERSION ?= $(DEFAULT_VERSION) # the version of the operator
39+
OPERATOR_SDK_VERSION ?= v1.34.2
40+
ENVTEST_K8S_VERSION = 1.29 # Kubernetes version from OpenShift 4.16.x
41+
GOLANGCI_LINT_VERSION ?= v1.54.2
42+
KUSTOMIZE_VERSION ?= v4.5.5
43+
CONTROLLER_TOOLS_VERSION ?= v0.16.5
44+
OPM_VERSION ?= v1.15.1
45+
YQ_VERSION ?= v4.28.1
46+
BRANCH_VERSION = oadp-1.4
47+
PREVIOUS_CHANNEL ?= oadp-1.3
48+
PREVIOUS_CHANNEL_GO_VERSION ?= 1.21
49+
# Extract the toolchain directive from go.mod
50+
GO_TOOLCHAIN_VERSION := $(shell grep -E "^toolchain" go.mod | awk '{print $$2}')
51+
52+
# Set GOPROXY to use the proxy.golang.org mirror to avoid rate limiting issues
53+
export GOPROXY ?= https://proxy.golang.org,direct
54+
# Set GOSUMDB to use the sum.golang.org checksum database to avoid checksum mismatch issues
55+
export GOSUMDB ?= sum.golang.org
56+
57+
58+
# CHANNELS define the bundle channels used in the bundle.
59+
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
60+
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
61+
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
62+
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
63+
CHANNELS = "stable-1.4"
64+
ifneq ($(origin CHANNELS), undefined)
65+
BUNDLE_CHANNELS := --channels=$(CHANNELS)
66+
endif
67+
68+
# DEFAULT_CHANNEL defines the default channel used in the bundle.
69+
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
70+
# To re-generate a bundle for any other default channel without changing the default setup, you can:
71+
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
72+
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
73+
DEFAULT_CHANNEL = "stable-1.4"
74+
ifneq ($(origin DEFAULT_CHANNEL), undefined)
75+
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
76+
endif
77+
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
78+
79+
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
80+
# This variable is used to construct full image tags for bundle and catalog images.
81+
#
82+
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
83+
# openshift.io/oadp-operator-bundle:$VERSION and openshift.io/oadp-operator-catalog:$VERSION.
84+
IMAGE_TAG_BASE ?= openshift.io/oadp-operator
85+
86+
# BUNDLE_IMG defines the image:tag used for the bundle.
87+
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
88+
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
89+
90+
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
91+
BUNDLE_GEN_FLAGS ?= -q --extra-service-accounts "velero,non-admin-controller" --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
92+
93+
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
94+
# You can enable this value if you would like to use SHA Based Digests
95+
# To enable set flag to true
96+
USE_IMAGE_DIGESTS ?= false
97+
ifeq ($(USE_IMAGE_DIGESTS), true)
98+
BUNDLE_GEN_FLAGS += --use-image-digests
99+
endif
100+
101+
# Image URL to use all building/pushing image targets
102+
IMG ?= quay.io/konveyor/oadp-operator:oadp-1.4
103+
104+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
105+
ifeq (,$(shell go env GOBIN))
106+
GOBIN=$(shell go env GOPATH)/bin
107+
else
108+
GOBIN=$(shell go env GOBIN)
109+
endif
110+
111+
# CONTAINER_TOOL defines the container tool to be used for building images.
112+
# Be aware that the target commands are only tested with Docker which is
113+
# scaffolded by default. However, you might want to replace it to use other
114+
# tools. (i.e. podman)
115+
CONTAINER_TOOL ?= docker
116+
117+
# Setting SHELL to bash allows bash commands to be executed by recipes.
118+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
119+
SHELL = /usr/bin/env bash -o pipefail
120+
.SHELLFLAGS = -ec
121+
122+
LOCALBIN ?= $(shell pwd)/bin
123+
$(LOCALBIN):
124+
mkdir -p $(LOCALBIN)
125+
126+
# Tool Definitions
127+
GOLANGCI_LINT = $(LOCALBIN)/$(BRANCH_VERSION)/golangci-lint
128+
KUSTOMIZE ?= $(LOCALBIN)/$(BRANCH_VERSION)/kustomize
129+
CONTROLLER_GEN ?= $(LOCALBIN)/$(BRANCH_VERSION)/controller-gen
130+
OPERATOR_SDK ?= $(LOCALBIN)/$(BRANCH_VERSION)/operator-sdk
131+
OPM ?= $(LOCALBIN)/$(BRANCH_VERSION)/opm
132+
YQ = $(LOCALBIN)/$(BRANCH_VERSION)/yq
133+
35134
ifdef CLI_DIR
36135
OC_CLI = ${CLI_DIR}/oc
37136
endif
@@ -75,27 +174,6 @@ ENVTEST_K8S_VERSION = 1.29
75174
DEFAULT_VERSION := 1.4.0
76175
VERSION ?= $(DEFAULT_VERSION)
77176

78-
# CHANNELS define the bundle channels used in the bundle.
79-
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
80-
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
81-
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
82-
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
83-
CHANNELS = "stable-1.4"
84-
ifneq ($(origin CHANNELS), undefined)
85-
BUNDLE_CHANNELS := --channels=$(CHANNELS)
86-
endif
87-
88-
# DEFAULT_CHANNEL defines the default channel used in the bundle.
89-
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
90-
# To re-generate a bundle for any other default channel without changing the default setup, you can:
91-
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
92-
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
93-
DEFAULT_CHANNEL = "stable-1.4"
94-
ifneq ($(origin DEFAULT_CHANNEL), undefined)
95-
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
96-
endif
97-
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
98-
99177
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
100178
# This variable is used to construct full image tags for bundle and catalog images.
101179
#
@@ -142,6 +220,58 @@ all: build
142220
help: ## Display this help.
143221
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
144222

223+
# Function to check tool version
224+
# Parameters: $(1)=TOOL_NAME $(2)=TOOL_PATH $(3)=VERSION_CMD $(4)=EXPECTED_VERSION $(5)=MAKE_TARGET $(6)=DISPLAY_NAME $(7)=SPECIAL_HANDLING
225+
define CHECK_TOOL_VERSION
226+
@printf "\n\033[1m$(1) Version Check:\033[0m\n"
227+
@if [ -f "$(2)" ]; then \
228+
INSTALLED_VERSION=$$($(3) || echo "unknown"); \
229+
EXPECTED_VERSION="$(4)"; \
230+
if [ "$$INSTALLED_VERSION" = "$$EXPECTED_VERSION" ]; then \
231+
printf "\033[32m%-30s\033[0m %-20s %s\n" "$(6)" "$$INSTALLED_VERSION" "✓ matches Makefile"; \
232+
$(if $(7),$(7)) \
233+
else \
234+
printf "\033[33m%-30s\033[0m %-20s %s\n" "$(6)" "$$INSTALLED_VERSION" "⚠ differs from Makefile ($$EXPECTED_VERSION)"; \
235+
printf "\033[33m✗ Installing the version requested by the Makefile\033[0m\n"; \
236+
$(MAKE) $(5); \
237+
fi; \
238+
else \
239+
printf "\033[31m%-30s\033[0m %-20s %s\n" "$(6)" "not found" "✗ not installed in $(LOCALBIN)"; \
240+
$(MAKE) $(5); \
241+
fi
242+
endef
243+
244+
.PHONY: check-go
245+
check-go: ## Check if go binary is available in PATH
246+
@if ! command -v go >/dev/null 2>&1; then \
247+
printf "\033[31m✗ Error: 'go' binary not found in PATH\033[0m\n"; \
248+
printf "Please install Go from https://golang.org/dl/ and ensure it's in your PATH\n"; \
249+
exit 1; \
250+
fi
251+
@printf "\033[32m✓ Go binary found in PATH\033[0m\n"
252+
253+
.PHONY: versions
254+
versions: check-go ## Display all variables containing 'version' in their name.
255+
@printf "\033[36m%-30s\033[0m %s\n" "GO_VERSION" "$$(go version | awk '{print $$3}')"
256+
@printf "\n\033[1m%-30s %-20s %s\033[0m\n" "Tool and Project Versions:" "Value" "Used by Targets"
257+
@printf "\033[36m%-30s\033[0m %-20s %s\n" "DEFAULT_VERSION" "$(DEFAULT_VERSION)" "bundle-isupdated"
258+
@printf "\033[36m%-30s\033[0m %-20s %s\n" "VERSION" "$(VERSION)" "bundle, catalog-build, deploy-olm, undeploy-olm"
259+
@printf "\033[36m%-30s\033[0m %-20s %s\n" "OPERATOR_SDK_VERSION" "$(OPERATOR_SDK_VERSION)" "operator-sdk"
260+
@printf "\033[36m%-30s\033[0m %-20s %s\n" "ENVTEST_K8S_VERSION" "$(ENVTEST_K8S_VERSION)" "test"
261+
@printf "\033[36m%-30s\033[0m %-20s %s\n" "GOLANGCI_LINT_VERSION" "$(GOLANGCI_LINT_VERSION)" "golangci-lint"
262+
@printf "\033[36m%-30s\033[0m %-20s %s\n" "KUSTOMIZE_VERSION" "$(KUSTOMIZE_VERSION)" "kustomize"
263+
@printf "\033[36m%-30s\033[0m %-20s %s\n" "CONTROLLER_TOOLS_VERSION" "$(CONTROLLER_TOOLS_VERSION)" "controller-gen"
264+
@printf "\033[36m%-30s\033[0m %-20s %s\n" "OPM_VERSION" "$(OPM_VERSION)" "opm"
265+
@printf "\033[36m%-30s\033[0m %-20s %s\n" "YQ_VERSION" "$(YQ_VERSION)" "yq"
266+
@printf "\033[36m%-30s\033[0m %-20s %s\n" "PREVIOUS_CHANNEL" "$(PREVIOUS_CHANNEL)" "catalog-test-upgrade"
267+
@printf "\033[36m%-30s\033[0m %-20s %s\n" "PREVIOUS_CHANNEL_GO_VERSION" "$(PREVIOUS_CHANNEL_GO_VERSION)" "catalog-test-upgrade"
268+
@printf "\033[36m%-30s\033[0m %-20s %s\n" "GO_TOOLCHAIN_VERSION" "$(GO_TOOLCHAIN_VERSION)" "(informational only)"
269+
$(call CHECK_TOOL_VERSION,Operator-SDK,$(OPERATOR_SDK),$(OPERATOR_SDK) version 2>/dev/null | grep 'operator-sdk version' | cut -d'"' -f2,$(OPERATOR_SDK_VERSION),operator-sdk,OPERATOR_SDK_LOCAL)
270+
$(call CHECK_TOOL_VERSION,Controller-Gen,$(CONTROLLER_GEN),$(CONTROLLER_GEN) --version 2>/dev/null | grep 'Version:' | cut -d' ' -f2,$(CONTROLLER_TOOLS_VERSION),controller-gen,CONTROLLER_GEN_LOCAL)
271+
$(call CHECK_TOOL_VERSION,OPM,$(OPM),$(OPM) version 2>/dev/null | cut -d'"' -f2,$(OPM_VERSION),opm,OPM_LOCAL)
272+
$(call CHECK_TOOL_VERSION,Kustomize,$(KUSTOMIZE),$(KUSTOMIZE) version 2>/dev/null | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' || echo "unknown",$(KUSTOMIZE_VERSION),kustomize,KUSTOMIZE_LOCAL,elif [ "$$INSTALLED_VERSION" = "unknown" ]; then printf "\033[36m%-30s\033[0m %-20s %s\n" "KUSTOMIZE_LOCAL" "$$INSTALLED_VERSION" "ⓘ kustomize v4 build (expected $(KUSTOMIZE_VERSION))";)
273+
$(call CHECK_TOOL_VERSION,YQ,$(YQ),$(YQ) --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1,$(YQ_VERSION:v%=%),yq,YQ_LOCAL)
274+
145275
##@ Development
146276

147277
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
@@ -155,10 +285,10 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
155285
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
156286
GOFLAGS="-mod=mod" $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
157287

158-
fmt: ## Run go fmt against code.
288+
fmt: check-go ## Run go fmt against code.
159289
go fmt -mod=mod ./...
160290

161-
vet: ## Run go vet against code.
291+
vet: check-go ## Run go vet against code.
162292
go vet -mod=mod ./...
163293

164294
ENVTEST := $(shell pwd)/bin/setup-envtest
@@ -179,7 +309,7 @@ envtest: $(ENVTEST)
179309
# to login to registry cluster follow https://docs.ci.openshift.org/docs/how-tos/use-registries-in-build-farm/#how-do-i-log-in-to-pull-images-that-require-authentication
180310
# If bin/ contains binaries of different arch, you may remove them so the container can install their arch.
181311
.PHONY: test
182-
test: vet envtest ## Run Go linter and unit tests and check Go code format and if api and bundle folders are up to date.
312+
test: check-go vet envtest ## Run Go linter and unit tests and check Go code format and if api and bundle folders are up to date.
183313
KUBEBUILDER_ASSETS="$(ENVTESTPATH)" go test -mod=mod $(shell go list -mod=mod ./... | grep -v /tests/e2e) -coverprofile cover.out
184314
@make fmt-isupdated
185315
@make api-isupdated
@@ -261,9 +391,7 @@ CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
261391
controller-gen: ## Download controller-gen locally if necessary.
262392
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
263393

264-
KUSTOMIZE = $(shell pwd)/bin/kustomize
265-
kustomize: ## Download kustomize locally if necessary.
266-
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
394+
267395

268396
# Codecov OS String for use in download url
269397
ifeq ($(OS),Windows_NT)
@@ -304,19 +432,9 @@ rm -rf $$TMP_DIR ;\
304432
}
305433
endef
306434

307-
YQ = $(shell pwd)/bin/yq
308-
yq: ## Download yq locally if necessary.
309-
# 4.28.1 is latest with go 1.17 go.mod
310-
$(call go-install-tool,$(YQ),github.com/mikefarah/yq/[email protected])
311-
312-
OPERATOR_SDK = $(shell pwd)/bin/operator-sdk
313-
operator-sdk:
314-
# Download operator-sdk locally if does not exist
315-
if [ ! -f $(OPERATOR_SDK) ]; then \
316-
mkdir -p bin ;\
317-
curl -Lo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/v1.34.2/operator-sdk_$(shell go env GOOS)_$(shell go env GOARCH) ; \
318-
chmod +x $(OPERATOR_SDK); \
319-
fi
435+
436+
437+
320438

321439
.PHONY: bundle
322440
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
@@ -399,23 +517,6 @@ undeploy-olm: login-required ## Uninstall current branch operator via OLM
399517
$(OC_CLI) create namespace $(OADP_TEST_NAMESPACE) || true
400518
$(OPERATOR_SDK) cleanup oadp-operator --namespace $(OADP_TEST_NAMESPACE)
401519

402-
.PHONY: opm
403-
OPM = ./bin/opm
404-
opm: ## Download opm locally if necessary.
405-
ifeq (,$(wildcard $(OPM)))
406-
ifeq (,$(shell which opm 2>/dev/null))
407-
@{ \
408-
set -e ;\
409-
mkdir -p $(dir $(OPM)) ;\
410-
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
411-
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
412-
chmod +x $(OPM) ;\
413-
}
414-
else
415-
OPM = $(shell which opm)
416-
endif
417-
endif
418-
419520
# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
420521
# These images MUST exist in a registry and be pull-able.
421522
BUNDLE_IMGS ?= $(BUNDLE_IMG)
@@ -483,7 +584,7 @@ else
483584
endif
484585

485586
.PHONY: install-ginkgo
486-
install-ginkgo: # Make sure ginkgo is in $GOPATH/bin
587+
install-ginkgo: check-go ## Make sure ginkgo is in $GOPATH/bin
487588
go install -v -mod=mod github.com/onsi/ginkgo/v2/ginkgo
488589

489590
OADP_BUCKET ?= $(shell cat $(OADP_BUCKET_FILE))
@@ -548,6 +649,90 @@ test-e2e-cleanup: login-required
548649
for restore_name in $(shell $(OC_CLI) get restore -n $(OADP_TEST_NAMESPACE) -o name);do $(OC_CLI) patch "$$restore_name" -n $(OADP_TEST_NAMESPACE) -p '{"metadata":{"finalizers":null}}' --type=merge;done
549650
rm -rf $(SETTINGS_TMP)
550651

652+
# go-install-tool-branch will 'go install' any package $2 and install it to branch-specific directory $1.
653+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
654+
define go-install-tool-branch
655+
@[ -f $(1) ] || { \
656+
set -e ;\
657+
TMP_DIR=$$(mktemp -d) ;\
658+
cd $$TMP_DIR ;\
659+
go mod init tmp ;\
660+
echo "Downloading $(2) to branch directory" ;\
661+
GOBIN=$(dir $(1)) go install -mod=mod $(2) ;\
662+
rm -rf $$TMP_DIR ;\
663+
}
664+
endef
665+
666+
.PHONY: golangci-lint
667+
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
668+
$(GOLANGCI_LINT): $(LOCALBIN)
669+
$(call go-install-tool-branch,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION))
670+
@if [ -L "$(LOCALBIN)/golangci-lint" ]; then \
671+
unlink "$(LOCALBIN)/golangci-lint"; \
672+
fi
673+
@ln -sf "$(LOCALBIN)/$(BRANCH_VERSION)/golangci-lint" "$(LOCALBIN)/golangci-lint"
674+
675+
.PHONY: kustomize
676+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
677+
$(KUSTOMIZE): $(LOCALBIN)
678+
$(call go-install-tool-branch,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@$(KUSTOMIZE_VERSION))
679+
@if [ -L "$(LOCALBIN)/kustomize" ]; then \
680+
unlink "$(LOCALBIN)/kustomize"; \
681+
fi
682+
@ln -sf "$(LOCALBIN)/$(BRANCH_VERSION)/kustomize" "$(LOCALBIN)/kustomize"
683+
684+
.PHONY: controller-gen
685+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
686+
$(CONTROLLER_GEN): $(LOCALBIN)
687+
$(call go-install-tool-branch,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION))
688+
@if [ -L "$(LOCALBIN)/controller-gen" ]; then \
689+
unlink "$(LOCALBIN)/controller-gen"; \
690+
fi
691+
@ln -sf "$(LOCALBIN)/$(BRANCH_VERSION)/controller-gen" "$(LOCALBIN)/controller-gen"
692+
693+
.PHONY: operator-sdk
694+
operator-sdk: $(OPERATOR_SDK) ## Download operator-sdk locally if necessary.
695+
$(OPERATOR_SDK): $(LOCALBIN)
696+
@if [ -f "$(OPERATOR_SDK)" ] && $(OPERATOR_SDK) version | grep -q $(OPERATOR_SDK_VERSION); then \
697+
echo "operator-sdk $(OPERATOR_SDK_VERSION) is already installed"; \
698+
else \
699+
set -e ;\
700+
mkdir -p $(dir $(OPERATOR_SDK)) ;\
701+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
702+
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
703+
chmod +x $(OPERATOR_SDK) ;\
704+
fi
705+
@if [ -L "$(LOCALBIN)/operator-sdk" ]; then \
706+
unlink "$(LOCALBIN)/operator-sdk"; \
707+
fi
708+
@ln -sf "$(LOCALBIN)/$(BRANCH_VERSION)/operator-sdk" "$(LOCALBIN)/operator-sdk"
709+
710+
.PHONY: opm
711+
opm: $(OPM) ## Download opm locally if necessary.
712+
$(OPM): $(LOCALBIN)
713+
@if [ -f "$(OPM)" ] && $(OPM) version | grep -q $(OPM_VERSION); then \
714+
echo "opm $(OPM_VERSION) is already installed"; \
715+
else \
716+
set -e ;\
717+
mkdir -p $(dir $(OPM)) ;\
718+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
719+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/$(OPM_VERSION)/$${OS}-$${ARCH}-opm ;\
720+
chmod +x $(OPM) ;\
721+
fi
722+
@if [ -L "$(LOCALBIN)/opm" ]; then \
723+
unlink "$(LOCALBIN)/opm"; \
724+
fi
725+
@ln -sf "$(LOCALBIN)/$(BRANCH_VERSION)/opm" "$(LOCALBIN)/opm"
726+
727+
.PHONY: yq
728+
yq: $(YQ) ## Download yq locally if necessary.
729+
$(YQ): $(LOCALBIN)
730+
$(call go-install-tool-branch,$(YQ),github.com/mikefarah/yq/v4@$(YQ_VERSION))
731+
@if [ -L "$(LOCALBIN)/yq" ]; then \
732+
unlink "$(LOCALBIN)/yq"; \
733+
fi
734+
@ln -sf "$(LOCALBIN)/$(BRANCH_VERSION)/yq" "$(LOCALBIN)/yq"
735+
551736
.PHONY: build-must-gather
552-
build-must-gather: ## Build OADP Must-gather binary must-gather/oadp-must-gather
737+
build-must-gather: check-go ## Build OADP Must-gather binary must-gather/oadp-must-gather
553738
cd must-gather && go build -mod=mod -a -o oadp-must-gather cmd/main.go

0 commit comments

Comments
 (0)