From f50226cebf377dd6ddd9dc08910231e26e10bd7a Mon Sep 17 00:00:00 2001 From: Michael Nairn Date: Tue, 13 Feb 2024 12:26:16 +0000 Subject: [PATCH] feat: Add prepare-release and manifests-gen-base-csv make targets Adds a make target(manifests-gen-base-csv) that updates the default values in the base CSV manifest to match the current VERSION/IMG/CHANNELS etc.. variables. Executed as part of bundle target. Adds a make target(prepare-release) that generates a makefile with env vars pinned to a particular release values: ``` make prepare-release IMG=quay.io/kuadrant/dns-operator:v0.1.0 VERSION=0.1.0 CHANNELS=stable REPLACES_VERSION=0.1.0 ``` Subsequent calls to make targets (`make bundle` etc..) will always use these values unless explicitly set. --- Makefile | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d8cfb3ad..1b5da9fa 100644 --- a/Makefile +++ b/Makefile @@ -100,6 +100,18 @@ help: ## Display this help. manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases +.PHONY: manifests-gen-base-csv +REPLACES_VERSION ?= "" +manifests-gen-base-csv: yq ## Generate base CSV for the current configuration (VERSION, IMG, CHANNELS etc..) + $(YQ) -i '.metadata.annotations.containerImage = "$(IMG)"' config/manifests/bases/dns-operator.clusterserviceversion.yaml + $(YQ) -i '.metadata.name = "dns-operator.v$(VERSION)"' config/manifests/bases/dns-operator.clusterserviceversion.yaml + $(YQ) -i '.spec.version = "$(VERSION)"' config/manifests/bases/dns-operator.clusterserviceversion.yaml + @if [ "$(REPLACES_VERSION)" != "" ]; then\ + $(YQ) -i '.spec.replaces = "dns-operator.v$(REPLACES_VERSION)"' config/manifests/bases/dns-operator.clusterserviceversion.yaml; \ + else \ + $(YQ) -i 'del(.spec.replaces)' config/manifests/bases/dns-operator.clusterserviceversion.yaml; \ + fi + .PHONY: generate generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." @@ -215,6 +227,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest OPENSHIFT_GOIMPORTS ?= $(LOCALBIN)/openshift-goimports KIND = $(LOCALBIN)/kind ACT = $(LOCALBIN)/act +YQ = $(LOCALBIN)/yq ## Tool Versions KUSTOMIZE_VERSION ?= v5.0.1 @@ -222,6 +235,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.12.0 OPENSHIFT_GOIMPORTS_VERSION ?= c70783e636f2213cac683f6865d88c5edace3157 KIND_VERSION = v0.20.0 ACT_VERSION = latest +YQ_VERSION := v4.34.2 .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading. @@ -271,12 +285,17 @@ $(KIND): $(LOCALBIN) GOBIN=$(LOCALBIN) go install sigs.k8s.io/kind@$(KIND_VERSION) .PHONY: act -act: $(ACT) -$(ACT): $(LOCALBIN) ## Download act locally if necessary. +act: $(ACT) ## Download act locally if necessary. +$(ACT): $(LOCALBIN) GOBIN=$(LOCALBIN) go install github.com/nektos/act@$(ACT_VERSION) +.PHONY: yq +yq: $(YQ) ## Download yq locally if necessary. +$(YQ): $(LOCALBIN) + GOBIN=$(LOCALBIN) go install github.com/mikefarah/yq/v4@$(YQ_VERSION) + .PHONY: bundle -bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files. +bundle: manifests manifests-gen-base-csv kustomize operator-sdk ## 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 $(BUNDLE_GEN_FLAGS) @@ -345,5 +364,13 @@ catalog-build: opm ## Build a catalog image. catalog-push: ## Push a catalog image. $(MAKE) docker-push IMG=$(CATALOG_IMG) +##@ Release + +.PHONY: prepare-release +RELEASE_FILE = $(shell pwd)/make/release.mk +prepare-release: ## Generates a makefile that will override environment variables for a specific release and runs bundle. + echo -e "#Release default values\\nIMG=$(IMG)\nCHANNELS=$(CHANNELS)\nVERSION=$(VERSION)\nREPLACES_VERSION=$(REPLACES_VERSION)" > $(RELEASE_FILE) + $(MAKE) bundle + # Include last to avoid changing MAKEFILE_LIST used above include ./make/*.mk