Skip to content

Commit

Permalink
update README and add make commands
Browse files Browse the repository at this point in the history
  • Loading branch information
maskarb committed Nov 21, 2024
1 parent 14f401c commit dd2b096
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
42 changes: 27 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PREVIOUS_VERSION ?= 3.3.1
VERSION ?= 3.3.2
VERSION ?= 3.3.1
PREVIOUS_VERSION ?= 3.3.0
PULLSPEC ?= registry.redhat.io/costmanagement/costmanagement-metrics-operator-bundle@sha256:01cab18a6af3cc819a936ce434004d5dce4495474e62bc116643eb753c25cd91

PWD=$(shell pwd)
OPERATOR_NAME=costmanagement-metrics-operator
Expand All @@ -15,6 +16,7 @@ CATALOG_DIR=${PWD}/catalog

# A place to store the operator catalog templates
OPERATOR_CATALOG_TEMPLATE_DIR = ${PWD}/catalog-template
CATALOG_TEMPLATE_FILENAME = basic-template.yaml

# Define the paths for both auth files
DOCKER_CONFIG := $(HOME)/.docker/config.json
Expand All @@ -26,9 +28,13 @@ CONTAINERS_AUTH := $(XDG_RUNTIME_DIR)/containers/auth.json
# of the automated catalog promotion
OCP_VERSIONS=$(shell echo "v4.12 v4.13 v4.14 v4.15 v4.16 v4.17" )

OS=$(shell go env GOOS)
ARCH=$(shell go env GOARCH)

OPM_VERSION ?= v1.48.0
OPM_FILENAME ?= opm-$(OPM_VERSION)
YQ_VERSION ?= v4.2.0
YQ_VERSION ?= v4.44.5
YQ_FILENAME ?= yq-$(YQ_VERSION)

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
Expand All @@ -38,7 +44,13 @@ $(LOCALBIN):
.PHONY: basic
basic: clean opm
mkdir -p ${CATALOG_DIR}/${OPERATOR_NAME}/ && \
$(OPM) alpha render-template basic -o yaml ${OPERATOR_CATALOG_TEMPLATE_DIR}/basic-template.yaml > ${CATALOG_DIR}/${OPERATOR_NAME}/catalog.yaml; \
$(OPM) alpha render-template basic -o yaml ${OPERATOR_CATALOG_TEMPLATE_DIR}/${CATALOG_TEMPLATE_FILENAME} > ${CATALOG_DIR}/${OPERATOR_NAME}/catalog.yaml;
$(OPM) validate ${CATALOG_DIR}/${OPERATOR_NAME}

.PHONY: add-new-version
add-new-version: yq
$(YQ) -i eval 'select(.schema == "olm.template.basic").entries[] |= select(.schema == "olm.channel").entries += [{"name" : "$(OPERATOR_NAME).$(VERSION)", "replaces": "$(OPERATOR_NAME).$(PREVIOUS_VERSION)"}]' ${OPERATOR_CATALOG_TEMPLATE_DIR}/${CATALOG_TEMPLATE_FILENAME}
$(YQ) -i '.entries += [{"image": "$(PULLSPEC)", "schema": "olm.bundle"}]' ${OPERATOR_CATALOG_TEMPLATE_DIR}/${CATALOG_TEMPLATE_FILENAME}

.PHONY: create-catalog-dir
create-catalog-dir:
Expand All @@ -48,36 +60,36 @@ create-catalog-dir:
clean: create-catalog-dir
find $(CATALOG_DIR) -type d -name ${OPERATOR_NAME} -exec rm -rf {} +


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


.PHONY: opm
OPM ?= $(LOCALBIN)/$(OPM_FILENAME)
opm: ## Download opm locally if necessary.
ifeq (,$(wildcard $(OPM_FILENAME)))
ifeq (, $(shell which $(OPM_FILENAME) 2>/dev/null))
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/$(OPM_VERSION)/$${OS}-$${ARCH}-opm ;\
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/$(OPM_VERSION)/$(OS)-$(ARCH)-opm ;\
chmod +x $(OPM) ;\
}
else
OPM = $(shell which $(OPM_FILENAME))
OPM = $(shell which $(OPM))
endif
endif
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,34 @@ File-Based Catalog for Cost Management Metrics Operator

## How to update

Updates are made to the [basic-template.yaml](catalog-templates/basic-template.yaml) file.
Updates are made to the [basic-template.yaml](catalog-templates/basic-template.yaml) file and then a catalog is generated from the template. The template can be updated with a Make command.

1. add new name and replaces to the `olm.channel`, e.g.:
1. in the [Makefile](Makefile), update `VERSION`, `PREVIOUS_VERSION`, and `PULLSPEC` to the latest values:
```
- name: costmanagement-metrics-operator.3.3.2
replaces: costmanagement-metrics-operator.3.3.1
VERSION ?= 3.3.1
PREVIOUS_VERSION ?= 3.3.0
PULLSPEC ?= registry.redhat.io/costmanagement/costmanagement-metrics-operator-bundle@sha256:01cab18a6af3cc819a936ce434004d5dce4495474e62bc116643eb753c25cd91
```

2. add a new `olm.bundle` pullspec image, e.g.:
2. run `make add-new-version` which will add the new version and pullspec to the template:
```
$ make add-new-version
```
which results in:
```
...
- name: costmanagement-metrics-operator.3.3.1
replaces: costmanagement-metrics-operator.3.3.0
name: stable
package: costmanagement-metrics-operator
schema: olm.channel
...
- image: registry.redhat.io/costmanagement/costmanagement-metrics-operator-bundle@sha256:01cab18a6af3cc819a936ce434004d5dce4495474e62bc116643eb753c25cd91
schema: olm.bundle
schema: olm.template.basic
```

3. Update the `OCP_VERSIONS` in the [Makefile](Makefile), if necessary.
4. Rebuild the FBCs (this will be very slow, especially the first time running this command):
3. Rebuild the FBC (this will be very slow, especially the first time running this command). This command also validates the outputted FBC:
```
$ make basic
```

0 comments on commit dd2b096

Please sign in to comment.