Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to operator-sdk v1.24.1. Resolves #1908 #1909

Merged
merged 8 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/image_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Login to Quay
uses: docker/login-action@v2
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/upgrade_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
repository: ${{ inputs.repository }}

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
repository: ${{ inputs.repository }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- if: ${{ inputs.operandArtifact != '' }}
name: Download operand artifact
Expand All @@ -63,21 +63,21 @@ jobs:

# Cache go build cache, used to speedup go test
- name: Go Build Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

# Cache go mod cache, used to speedup builds
- name: Go Mod Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}

# Cache local bin dependencies
- name: Local Dependencies Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: bin
key: ${{ runner.os }}-bin-${{ hashFiles('Makefile') }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.access.redhat.com/ubi9/go-toolset:1.19 AS build
FROM registry.access.redhat.com/ubi9/go-toolset:1.20 AS build
ARG OPERATOR_VERSION
ARG SKAFFOLD_GO_GCFLAGS
WORKDIR /workspace
Expand Down
144 changes: 84 additions & 60 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Current Operator version
VERSION ?= $(shell git describe --tags --always --dirty)
# Default bundle image tag
BUNDLE_IMG ?= infinispan-operator-bundle:v$(VERSION)
IMAGE_TAG_BASE ?= infinispan-operator
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
export KUBECONFIG ?= ${HOME}/.kube/config
export WATCH_NAMESPACE ?= namespace-for-testing

Expand All @@ -14,17 +15,25 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= --version $(VERSION) $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)

# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
# You can enable this value if you would like to use SHA Based Digests
# To enable set flag to true
USE_IMAGE_DIGESTS ?= false
ifeq ($(USE_IMAGE_DIGESTS), true)
BUNDLE_GEN_FLAGS += --use-image-digests
endif

# The namespace to deploy the infinispan-operator
DEPLOYMENT_NAMESPACE ?= infinispan-operator-system

# Image URL to use all building/pushing image targets
IMG ?= operator:latest

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.19
ENVTEST_K8S_VERSION = 1.24

export CONTAINER_TOOL ?= docker

Expand All @@ -35,7 +44,30 @@ else
GOBIN=$(shell go env GOBIN)
endif

PATH ?= $(PATH):./bin
##@ Build Dependencies

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

## Tool Binaries
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
export GO_JUNIT_REPORT ?= $(LOCALBIN)/go-junit-report
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
KUSTOMIZE ?= $(LOCALBIN)/kustomize
MOCKGEN ?= $(LOCALBIN)/mockgen
RICE ?= $(LOCALBIN)/rice

## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.9.2
GO_JUNIT_REPORT_VERSION ?= latest
GOLANGCI_LINT_VERSION ?= v1.53.3
KUSTOMIZE_VERSION ?= v3.8.7
RICE_VERSION ?= v1.0.2
JQ_VERSION ?= 1.7
YQ_VERSION ?= v4.31.1

.DEFAULT_GOAL := help

Expand Down Expand Up @@ -140,7 +172,7 @@ undeploy:
.PHONY: manifests
## Generate manifests locally e.g. CRD, RBAC etc.
manifests: controller-gen operator-sdk
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(OPERATOR_SDK) generate kustomize manifests -q

.PHONY: fmt
Expand Down Expand Up @@ -176,71 +208,54 @@ operator-build: manager
operator-push:
$(CONTAINER_TOOL) push $(IMG)

RICE = $(shell pwd)/bin/rice
.PHONY: rice
## Download Rice locally if necessary
rice:
$(call go-get-tool,$(RICE),github.com/GeertJohan/go.rice/[email protected])
rice: $(RICE) ## Download Rice locally if necessary.
$(RICE): $(LOCALBIN)
test -s $(RICE) || GOBIN=$(LOCALBIN) go install github.com/GeertJohan/go.rice/rice@$(RICE_VERSION)

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
test -s $(KUSTOMIZE) || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
.PHONY: controller-gen
## Download controller-gen locally if necessary
controller-gen:
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(CONTROLLER_GEN) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
test -s $(GOLANGCI_LINT) || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

.PHONY: go-junit-report
go-junit-report: $(GO_JUNIT_REPORT) ## Download go-junit-report locally if necessary.
$(GO_JUNIT_REPORT): $(LOCALBIN)
test -s $(GO_JUNIT_REPORT) || GOBIN=$(LOCALBIN) go install github.com/jstemmer/go-junit-report@$(GO_JUNIT_REPORT_VERSION)

KUSTOMIZE = $(shell pwd)/bin/kustomize
.PHONY: kustomize
## Download kustomize locally if necessary
kustomize:
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
.PHONY: golanci-lint
## Download golanci-lint locally if necessary
golangci-lint:
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/[email protected])

export GO_JUNIT_REPORT = $(shell pwd)/bin/go-junit-report
.PHONY: GO_JUNIT_REPORT
## Download go-junit-report locally if necessary
go-junit-report:
$(call go-get-tool,$(GO_JUNIT_REPORT),github.com/jstemmer/go-junit-report@latest)

export MOCKGEN = $(shell pwd)/bin/mockgen
.PHONY: mockgen
## Download mockgen locally if necessary
mockgen:
$(call go-get-tool,$(MOCKGEN),github.com/golang/mock/[email protected])
mockgen: $(MOCKGEN) ## Download mockgen locally if necessary
$(MOCKGEN): $(LOCALBIN)
test -s $(MOCKGEN) || GOBIN=$(LOCALBIN) go install github.com/golang/mock/[email protected]

ENVTEST = $(shell pwd)/bin/setup-envtest
.PHONY: envtest
## Download envtest-setup locally if necessary.
envtest:
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
}
endef
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(ENVTEST) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: bundle
## Generate bundle manifests and metadata, then validate generated files.
bundle: manifests kustomize yq
# Remove old bundle as old files aren't always cleaned up by operator-sdk
rm -rf bundle
cd config/manager && $(KUSTOMIZE) edit set image operator=$(IMG)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite $(BUNDLE_METADATA_OPTS)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
# TODO is there a better way todo this with operator-sdk and/or kustomize. `commonAnnotations` adds annotations to all resources, not just CSV.
sed -i -e "s,<IMAGE>,$(IMG)," bundle/manifests/infinispan-operator.clusterserviceversion.yaml
# Hack to set the metadata package name to "infinispan". `operator-sdk --package infinispan` can't be used as it
# changes the csv name from infinispan-operator.v0.0.0 -> infinispan.v0.0.0
sed -i -e 's/infinispan-operator/infinispan/' bundle/metadata/annotations.yaml bundle.Dockerfile
rm bundle/manifests/infinispan-operator-controller-manager_v1_serviceaccount.yaml
rm bundle/manifests/infinispan-operator-webhook-service_v1_service.yaml
# Minimum Openshift version must correspond to `minKubeVersion` set in CSV
$(YQ) -i '.annotations += {"com.redhat.openshift.versions": "v4.11"}' bundle/metadata/annotations.yaml
Expand All @@ -259,51 +274,56 @@ bundle-push:
.PHONY: opm
export OPM = ./bin/opm
opm: ## Download opm locally if necessary.
ifeq (,$(wildcard $(OPM)))
ifeq (,$(shell which opm 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPM)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.21.0/$${OS}-$${ARCH}-opm ;\
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
chmod +x $(OPM) ;\
}
else
OPM = $(shell which opm)
endif

endif

.PHONY: jq
export JQ = ./bin/jq
jq: ## Download opm locally if necessary.
ifeq (,$(wildcard $(JQ)))
ifeq (,$(shell which jq 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(JQ)) ;\
curl -sSLo $(JQ) https://github.com/stedolan/jq/releases/download/jq-1.7/jq-linux64 ;\
curl -sSLo $(JQ) https://github.com/stedolan/jq/releases/download/jq-$(JQ_VERSION)/jq-linux64 ;\
chmod +x $(JQ) ;\
}
else
JQ = $(shell which jq)
endif
endif

.PHONY: yq
export YQ = ./bin/yq
## Download yq locally if necessary.
yq: jq
yq: ## Download yq locally if necessary.
ifeq (,$(wildcard $(YQ)))
ifeq (,$(shell which yq 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(YQ)) ;\
curl -sSLo $(YQ) https://github.com/mikefarah/yq/releases/download/v4.40.2/yq_linux_amd64 ;\
curl -sSLo $(YQ) https://github.com/mikefarah/yq/releases/download/$(YQ_VERSION)/yq_linux_amd64 ;\
chmod +x $(YQ) ;\
}
else
YQ = $(shell which yq)
endif
endif

.PHONY: oc
export OC = ./bin/oc
oc: ## Download oc locally if necessary.
ifeq (,$(wildcard $(OC)))
ifeq (,$(shell which oc 2>/dev/null))
@{ \
set -e ;\
Expand All @@ -314,10 +334,13 @@ ifeq (,$(shell which oc 2>/dev/null))
else
OC = $(shell which oc)
endif
endif

.PHONY: operator-sdk
## Download operator-sdk locally if necessary.
export OPERATOR_SDK = ./bin/operator-sdk
operator-sdk: ## Download operator-sdk locally if necessary.
operator-sdk:
ifeq (,$(wildcard $(OPERATOR_SDK)))
ifeq (,$(shell which operator-sdk 2>/dev/null))
@{ \
set -e ;\
Expand All @@ -328,6 +351,7 @@ ifeq (,$(shell which operator-sdk 2>/dev/null))
else
OPERATOR_SDK = $(shell which operator-sdk)
endif
endif

# 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).
# These images MUST exist in a registry and be pull-able.
Expand Down
Loading