Skip to content

Commit

Permalink
Automatically download correct operator-sdk version to bin dir, if no…
Browse files Browse the repository at this point in the history
…t found

Signed-off-by: Jonathan West <[email protected]>
  • Loading branch information
jgwest committed Jun 4, 2024
1 parent cdf3832 commit 9319aa7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
26 changes: 2 additions & 24 deletions .github/workflows/codegen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ on:
pull_request:
branches:
- 'master'
env:
# Golang version to use
GOLANG_VERSION: '1.21'
# Version of operator-sdk binary
SDK_VERSION: 1.11.0
# Checksum of operator-sdk binary
SDK_CHECKSUM: 'b1f6fb02c619cfcdb46edf41cbeb4d66f627fd8bba122edaeeb06718965299eb'

jobs:
check-go-modules:
Expand All @@ -24,7 +17,7 @@ jobs:
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}
go-version-file: 'go.mod'
- name: Download all Go modules
run: |
go mod download
Expand All @@ -42,22 +35,7 @@ jobs:
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: Download and install Operator SDK
run: |
set -ue
set -o pipefail
curl -sLf --retry 3 \
-o /tmp/operator-sdk_linux_amd64 \
https://github.com/operator-framework/operator-sdk/releases/download/v1.11.0/operator-sdk_linux_amd64
calculated=$(sha256sum /tmp/operator-sdk_linux_amd64 | awk '{print $1}')
if test "${calculated}" != "${SDK_CHECKSUM}"; then
echo "FAILED TO VALIDATE CHECKSUM" >&2
echo "Download is: ${calculated}"
echo "Should: ${SDK_CHECKSUM}"
exit 1
fi
sudo install -m 0755 /tmp/operator-sdk_linux_amd64 /usr/local/bin/operator-sdk
go-version-file: 'go.mod'
- name: Run make bundle
run: |
make bundle
Expand Down
39 changes: 35 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# Set the Operator SDK version to use.
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
OPERATOR_SDK_VERSION ?= v1.11.0


# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
# This variable is used to construct full image tags for bundle and catalog images.
#
Expand Down Expand Up @@ -104,6 +109,32 @@ docker-build: test ## Build docker image with the manager.
docker-push: ## Push docker image with the manager.
docker push ${IMG}

##@ Build Dependencies

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)


.PHONY: operator-sdk
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
operator-sdk: ## Download operator-sdk locally if necessary.
ifeq (,$(wildcard $(OPERATOR_SDK)))
ifeq (,$(shell which operator-sdk 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPERATOR_SDK)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
chmod +x $(OPERATOR_SDK) ;\
}
else
OPERATOR_SDK = $(shell which operator-sdk)
endif
endif


##@ Deployment

install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
Expand Down Expand Up @@ -157,11 +188,11 @@ rm -rf $$TMP_DIR ;\
endef

.PHONY: bundle
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q
bundle: operator-sdk manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
$(OPERATOR_SDK) generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
$(OPERATOR_SDK) bundle validate ./bundle
rm -fr deploy/olm-catalog/argocd-operator/$(VERSION)
mkdir -p deploy/olm-catalog/argocd-operator/$(VERSION)
cp -r bundle/manifests/* deploy/olm-catalog/argocd-operator/$(VERSION)/
Expand Down

0 comments on commit 9319aa7

Please sign in to comment.