|
1 | 1 |
|
2 |
| -OPERATOR_NAME = example-operator |
3 |
| -VERSION ?= "latest" |
4 |
| -INDEX_IMAGE = "quay.io/joelanford/example-operator-index:$(VERSION)" |
5 |
| - |
6 |
| -catalog: bin/opm bin/yq veneer.yaml convert.sh |
7 |
| - rm -rf catalog && \ |
8 |
| - mkdir -p catalog/$(OPERATOR_NAME) && \ |
9 |
| - ./convert.sh veneer.yaml > catalog/$(OPERATOR_NAME)/catalog.yaml && \ |
10 |
| - cp CATALOG_OWNERS catalog/$(OPERATOR_NAME)/OWNERS && \ |
11 |
| - echo "OWNERS" > catalog/$(OPERATOR_NAME)/.indexignore |
12 |
| - |
13 |
| -.PHONY: sanity |
14 |
| -sanity: catalog bin/opm pretest |
15 |
| - bin/opm validate catalog |
16 |
| - |
17 |
| -.PHONY: pretest |
18 |
| -pretest: bin/yq catalog |
19 |
| - @./sanity.sh -n $(OPERATOR_NAME) -f catalog/$(OPERATOR_NAME)/catalog.yaml; |
20 |
| - @if [ $$? -ne 0 ] ; then \ |
21 |
| - echo "operator name in veneer and Makefile do not agree"; \ |
22 |
| - false; \ |
23 |
| - fi |
24 |
| - |
25 |
| -.PHONY: build |
26 |
| -build: catalog sanity bin/opm bin/yq |
27 |
| - bin/opm alpha generate dockerfile catalog |
28 |
| - docker build -t $(INDEX_IMAGE) -f catalog.Dockerfile . |
29 |
| - rm catalog.Dockerfile |
30 |
| - |
31 |
| -.PHONY: push |
32 |
| -push: build |
33 |
| - docker push $(INDEX_IMAGE) |
| 2 | +OPERATOR_NAME = testoperator |
| 3 | +OPERATOR_CATALOG_DIR = catalog/$(OPERATOR_NAME) |
| 4 | +OPERATOR_CATALOG_CONTRIBUTION = $(OPERATOR_CATALOG_DIR)/catalog.yaml |
| 5 | +YQ = bin/yq |
| 6 | + |
| 7 | + |
| 8 | +# the catalog contribution target will enforce that the user selected an FBC build approach and generated the catalog |
| 9 | +$(OPERATOR_CATALOG_CONTRIBUTION): |
| 10 | + @echo "$(OPERATOR_CATALOG_CONTRIBUTION) does not exist"; \ |
| 11 | + echo ">>> you must first customize and execute 'make catalog' to generate the catalog contribution"; \ |
| 12 | + false; |
| 13 | + |
| 14 | +.PHONY: catalog |
| 15 | +# replace this stub with one customized to serve your needs ... some examples below |
| 16 | +catalog: $(OPERATOR_CATALOG_CONTRIBUTION) |
| 17 | + |
| 18 | +# in order to have a deliverable target, the CI workflow executes the target "catalog" and wraps the resulting catalog contribution in |
| 19 | +# a PR to the modeled catalog repo |
| 20 | +# |
| 21 | +# here are a few examples of different approaches to fulfilling this target |
| 22 | +# comment out / customize the one that makes the most sense, or use them as examples in defining your own |
| 23 | +# |
| 24 | +# --- BASIC VENEER --- |
| 25 | +#catalog: basic framework |
| 26 | +# |
| 27 | +# --- SEMVER VENEER --- |
| 28 | +#catalog: semver framework |
| 29 | +# |
| 30 | +# --- COMPOUND VENEER --- |
| 31 | +# this case is for when a single veneer cannot support the use-case, and automated changes to the generated FBC need to be made before it is complete |
| 32 | +# this example models the need to set the v0.2.1 of the operator with the `olm.deprecated` property, to prevent installation |
| 33 | +# |
| 34 | +#catalog: $(YQ) semver framework |
| 35 | +# $(YQ) eval 'select(.name == "testoperator.v0.2.1" and .schema == "olm.bundle").properties += [{"type" : "olm.deprecated", "value" : "true"}]' -i $(OPERATOR_CATALOG_CONTRIBUTION) |
| 36 | + |
| 37 | +# framework target provides two pieces that are helpful for any veneer approach: |
| 38 | +# - an OWNERS file to provide default contribution control |
| 39 | +# - an .indexignore file to illustrate how to add content to the FBC contribution which should be |
| 40 | +# excluded from validation via `opm validate` |
| 41 | +.PHONY: framework |
| 42 | +framework: CATALOG_OWNERS |
| 43 | + cp CATALOG_OWNERS $(OPERATOR_CATALOG_DIR)/OWNERS && \ |
| 44 | + echo "OWNERS" > $(OPERATOR_CATALOG_DIR)/.indexignore |
| 45 | + |
| 46 | + |
| 47 | +# basic target provides an example FBC generation from a `basic` veneer type. |
| 48 | +# this example takes a single file as input and generates a well-formed FBC operator contribution as an output |
| 49 | +# the 'validate' target should be used next to validate the output |
| 50 | +.PHONY: basic |
| 51 | +basic: bin/opm basic-veneer.yaml clean |
| 52 | + mkdir -p $(OPERATOR_CATALOG_DIR) && bin/opm alpha render-veneer basic -o yaml basic-veneer.yaml > $(OPERATOR_CATALOG_CONTRIBUTION) |
| 53 | + |
| 54 | + |
| 55 | +# semver target provides an example FBC generation from a `semver` veneer type. |
| 56 | +# this example takes a single file as input and generates a well-formed FBC operator contribution as an output |
| 57 | +# the 'validate' target should be used next to validate the output |
| 58 | +.PHONY: semver |
| 59 | +semver: bin/opm semver-veneer.yaml clean |
| 60 | + mkdir -p $(OPERATOR_CATALOG_DIR) && bin/opm alpha render-veneer semver -o yaml semver-veneer.yaml > $(OPERATOR_CATALOG_CONTRIBUTION) |
| 61 | + |
| 62 | + |
| 63 | +# validate target illustrates FBC validation |
| 64 | +# all FBC must pass opm validation in order to be able to be used in a catalog |
| 65 | +.PHONY: validate |
| 66 | +validate: bin/opm $(OPERATOR_CATALOG_CONTRIBUTION) preverify |
| 67 | + bin/opm validate catalog && echo "catalog validation passed" || echo "catalog validation failed" |
| 68 | + |
| 69 | + |
| 70 | +# preverify target ensures that the operator name is consistent between the destination directory and the generated catalog |
| 71 | +# since the veneer will be modified outside the build process but needs to be consistent with the directory name |
| 72 | +.PHONY: preverify |
| 73 | +preverify: $(YQ) $(OPERATOR_CATALOG_CONTRIBUTION) |
| 74 | + ./validate.sh -n $(OPERATOR_NAME) -f $(OPERATOR_CATALOG_CONTRIBUTION) |
| 75 | + |
34 | 76 |
|
35 | 77 | .PHONY: clean
|
36 | 78 | clean:
|
37 |
| - rm -r catalog |
| 79 | + rm -rf catalog |
| 80 | + |
38 | 81 |
|
39 | 82 | OS=$(shell uname -s | tr '[:upper:]' '[:lower:]')
|
40 | 83 | ARCH=$(shell uname -m | sed 's/x86_64/amd64/')
|
41 |
| -OPM_VERSION=v1.19.5 |
| 84 | +OPM_VERSION ?= v1.26.1 |
42 | 85 | bin/opm:
|
43 | 86 | mkdir -p bin
|
44 | 87 | curl -sLO https://github.com/operator-framework/operator-registry/releases/download/$(OPM_VERSION)/$(OS)-$(ARCH)-opm && chmod +x $(OS)-$(ARCH)-opm && mv $(OS)-$(ARCH)-opm bin/opm
|
45 | 88 |
|
| 89 | + |
46 | 90 | YQ_VERSION=v4.22.1
|
47 | 91 | YQ_BINARY=yq_$(OS)_$(ARCH)
|
48 |
| -bin/yq: |
| 92 | +$(YQ): |
49 | 93 | if [ ! -e bin ] ; then mkdir -p bin; fi
|
50 |
| - wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/${YQ_BINARY} -O bin/${YQ_BINARY} && mv -f bin/${YQ_BINARY} bin/yq && chmod +x bin/yq |
| 94 | + wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/${YQ_BINARY} -O bin/${YQ_BINARY} && mv -f bin/${YQ_BINARY} $(YQ) && chmod +x $(YQ) |
| 95 | + |
0 commit comments