Skip to content

Commit 3b4e815

Browse files
committed
Make operator-sdk installation more robust
Signed-off-by: chiragkyal <[email protected]>
1 parent e6cbdab commit 3b4e815

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

Makefile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,8 @@ OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
284284
operator-sdk: ## Download operator-sdk locally if necessary.
285285
ifeq (,$(wildcard $(OPERATOR_SDK)))
286286
ifeq (, $(shell which operator-sdk 2>/dev/null))
287-
@{ \
288-
set -e ;\
289-
mkdir -p $(dir $(OPERATOR_SDK)) ;\
290-
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
291-
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
292-
chmod +x $(OPERATOR_SDK) ;\
293-
}
287+
mkdir -p $(dir $(OPERATOR_SDK))
288+
hack/operator-sdk.sh $(OPERATOR_SDK) $(OPERATOR_SDK_VERSION)
294289
else
295290
OPERATOR_SDK = $(shell which operator-sdk)
296291
endif

hack/operator-sdk.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
OUTPUT_PATH=${1:-./bin/operator-sdk}
6+
VERSION=${2:-"v1.39.0"}
7+
8+
GOOS=$(go env GOOS)
9+
GOARCH=$(go env GOARCH)
10+
BIN="operator-sdk"
11+
BIN_ARCH="${BIN}_${GOOS}_${GOARCH}"
12+
OPERATOR_SDK_DL_URL="https://github.com/operator-framework/operator-sdk/releases/download/${VERSION}"
13+
14+
if [[ "$GOOS" != "linux" && "$GOOS" != "darwin" ]]; then
15+
echo "Unsupported OS $GOOS"
16+
exit 1
17+
fi
18+
19+
if [[ "$GOARCH" != "amd64" && "$GOARCH" != "arm64" && "$GOARCH" != "ppc64le" && "$GOARCH" != "s390x" ]]; then
20+
echo "Unsupported architecture $GOARCH"
21+
exit 1
22+
fi
23+
24+
command -v curl &> /dev/null || { echo "can't find curl command" && exit 1; }
25+
26+
TEMPDIR=$(mktemp -d)
27+
BIN_PATH="${TEMPDIR}/${BIN_ARCH}"
28+
29+
echo "> downloading binary"
30+
curl --location -o "${BIN_PATH}" "${OPERATOR_SDK_DL_URL}/operator-sdk_${GOOS}_${GOARCH}"
31+
32+
echo "> installing binary"
33+
mv "${BIN_PATH}" "${OUTPUT_PATH}"
34+
chmod +x "${OUTPUT_PATH}"
35+
rm -rf "${TEMPDIR}"
36+
37+
echo "> operator-sdk binary available at ${OUTPUT_PATH}"

0 commit comments

Comments
 (0)