Skip to content

Commit

Permalink
feat: Add prepare-release and manifests-gen-base-csv make targets
Browse files Browse the repository at this point in the history
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.

Adds a task that is executed after generate bundle that updates things
not possible with the operator sdk.

Adds openshift annotations to bundle annotations.yaml:

```
com.redhat.openshift.versions = v4.12-v4.14
```
  • Loading branch information
mikenairn committed Feb 13, 2024
1 parent 559cc35 commit 1c839c9
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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="./..."
Expand Down Expand Up @@ -215,13 +227,15 @@ 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
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.
Expand Down Expand Up @@ -271,15 +285,21 @@ $(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)
$(MAKE) bundle-post-generate
$(OPERATOR_SDK) bundle validate ./bundle
$(MAKE) bundle-ignore-createdAt

Expand All @@ -294,6 +314,10 @@ bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metada
bundle-ignore-createdAt:
git diff --quiet -I'^ createdAt: ' ./bundle && git checkout ./bundle || true

.PHONY: bundle-post-generate
bundle-post-generate:
$(YQ) -i '.annotations."com.redhat.openshift.versions" = "v4.12-v4.14"' bundle/metadata/annotations.yaml

.PHONY: bundle-build
bundle-build: ## Build the bundle image.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
Expand Down Expand Up @@ -345,5 +369,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

0 comments on commit 1c839c9

Please sign in to comment.