Skip to content

Commit c588d97

Browse files
authored
Automatically download correct operator-sdk version to bin dir, if not found (#1396)
* Automatically download correct operator-sdk version to bin dir, if not found Signed-off-by: Jonathan West <[email protected]> * Automatically download correct operator-sdk version to bin dir, if not found Signed-off-by: Jonathan West <[email protected]> --------- Signed-off-by: Jonathan West <[email protected]>
1 parent 0c1786b commit c588d97

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

.github/workflows/codegen.yaml

+2-24
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ on:
66
pull_request:
77
branches:
88
- 'master'
9-
env:
10-
# Golang version to use
11-
GOLANG_VERSION: '1.21'
12-
# Version of operator-sdk binary
13-
SDK_VERSION: 1.11.0
14-
# Checksum of operator-sdk binary
15-
SDK_CHECKSUM: 'b1f6fb02c619cfcdb46edf41cbeb4d66f627fd8bba122edaeeb06718965299eb'
169

1710
jobs:
1811
check-go-modules:
@@ -24,7 +17,7 @@ jobs:
2417
- name: Setup Golang
2518
uses: actions/setup-go@v5
2619
with:
27-
go-version: ${{ env.GOLANG_VERSION }}
20+
go-version-file: 'go.mod'
2821
- name: Download all Go modules
2922
run: |
3023
go mod download
@@ -42,22 +35,7 @@ jobs:
4235
- name: Setup Golang
4336
uses: actions/setup-go@v5
4437
with:
45-
go-version: ${{ env.GOLANG_VERSION }}
46-
- name: Download and install Operator SDK
47-
run: |
48-
set -ue
49-
set -o pipefail
50-
curl -sLf --retry 3 \
51-
-o /tmp/operator-sdk_linux_amd64 \
52-
https://github.com/operator-framework/operator-sdk/releases/download/v1.11.0/operator-sdk_linux_amd64
53-
calculated=$(sha256sum /tmp/operator-sdk_linux_amd64 | awk '{print $1}')
54-
if test "${calculated}" != "${SDK_CHECKSUM}"; then
55-
echo "FAILED TO VALIDATE CHECKSUM" >&2
56-
echo "Download is: ${calculated}"
57-
echo "Should: ${SDK_CHECKSUM}"
58-
exit 1
59-
fi
60-
sudo install -m 0755 /tmp/operator-sdk_linux_amd64 /usr/local/bin/operator-sdk
38+
go-version-file: 'go.mod'
6139
- name: Run make bundle
6240
run: |
6341
make bundle

Makefile

+31-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
3232
endif
3333
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
3434

35+
# Set the Operator SDK version to use.
36+
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
37+
OPERATOR_SDK_VERSION ?= v1.11.0
38+
39+
3540
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
3641
# This variable is used to construct full image tags for bundle and catalog images.
3742
#
@@ -112,6 +117,28 @@ docker-build: test ## Build docker image with the manager.
112117
docker-push: ## Push docker image with the manager.
113118
$(CONTAINER_RUNTIME) push ${IMG}
114119

120+
##@ Build Dependencies
121+
122+
## Location to install dependencies to
123+
LOCALBIN ?= $(shell pwd)/bin
124+
$(LOCALBIN):
125+
mkdir -p $(LOCALBIN)
126+
127+
128+
.PHONY: operator-sdk
129+
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
130+
operator-sdk: ## Download operator-sdk locally if necessary.
131+
ifeq (,$(wildcard $(OPERATOR_SDK)))
132+
@{ \
133+
set -e ;\
134+
mkdir -p $(dir $(OPERATOR_SDK)) ;\
135+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
136+
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
137+
chmod +x $(OPERATOR_SDK) ;\
138+
}
139+
endif
140+
141+
115142
##@ Deployment
116143

117144
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
@@ -165,11 +192,11 @@ rm -rf $$TMP_DIR ;\
165192
endef
166193

167194
.PHONY: bundle
168-
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
169-
operator-sdk generate kustomize manifests -q
195+
bundle: operator-sdk manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
196+
$(OPERATOR_SDK) generate kustomize manifests -q
170197
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
171-
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
172-
operator-sdk bundle validate ./bundle
198+
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
199+
$(OPERATOR_SDK) bundle validate ./bundle
173200
rm -fr deploy/olm-catalog/argocd-operator/$(VERSION)
174201
mkdir -p deploy/olm-catalog/argocd-operator/$(VERSION)
175202
cp -r bundle/manifests/* deploy/olm-catalog/argocd-operator/$(VERSION)/

0 commit comments

Comments
 (0)