Skip to content

Commit 30bfe95

Browse files
authored
revamped artifacts to give good UX to the flow (#1)
Signed-off-by: Jordan Keister <[email protected]>
1 parent 6cf17b3 commit 30bfe95

File tree

9 files changed

+238
-100
lines changed

9 files changed

+238
-100
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ name: CI
22

33
on:
44
push:
5-
branches:
6-
- '**'
5+
branches: [ main ]
76
pull_request:
87
branches: [ main ]
98

@@ -16,7 +15,7 @@ jobs:
1615
- name: Check out code into the Go module directory
1716
uses: actions/checkout@v2
1817

19-
- name: Build
18+
- name: Build Catalog
2019
run: make catalog
2120

2221
- name: Validate
@@ -25,11 +24,6 @@ jobs:
2524
catalog: catalog
2625

2726
- name: Release
28-
# if: github.event_name == 'push'
29-
#uses: catalog-release-bot/catalog-release-bot@main
30-
#with:
31-
# catalogDir: catalog
32-
# packageName: example-operator
3327
if: github.event_name == 'push'
3428
uses: grokspawn/[email protected]
3529
env:

Makefile

Lines changed: 81 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,95 @@
11

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+
3476

3577
.PHONY: clean
3678
clean:
37-
rm -r catalog
79+
rm -rf catalog
80+
3881

3982
OS=$(shell uname -s | tr '[:upper:]' '[:lower:]')
4083
ARCH=$(shell uname -m | sed 's/x86_64/amd64/')
41-
OPM_VERSION=v1.19.5
84+
OPM_VERSION ?= v1.26.1
4285
bin/opm:
4386
mkdir -p bin
4487
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
4588

89+
4690
YQ_VERSION=v4.22.1
4791
YQ_BINARY=yq_$(OS)_$(ARCH)
48-
bin/yq:
92+
$(YQ):
4993
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+

README.md

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,97 @@
11
# example-operator-index
2+
Welcome! This repository provides a starting point for those interested in maintaining the catalog information for their operator and illustrates how that information contributes to an overall catalog ecosystem.
23

4+
5+
## Quickstart
6+
1. fork this repository
7+
2. adjust destination fields in .github/workflows/ci.yaml as necessary, commit and push changes
8+
3. adjust Makefile `$OPERATOR_NAME` for your operator's name
9+
2. decide on an approach: basic veneer, semver veneer, custom veneers, raw FBC, etc. and adjust the 'catalog' target in Makefile to generate your desired FBC
10+
4. run local tests (`make catalog`, `make validate`, etc.) until happy with the generated FBC
11+
6. add, commit, and push the changes
12+
7. verify that CI passes and opens a PR in the catalog repository
13+
14+
15+
16+
## Detailed HOWTO
17+
### Actors and Terms
18+
- [`File-Based Catalog`](https://olm.operatorframework.io/docs/reference/file-based-catalogs/) (FBC) is the declarative expression of operators and their relationships with other operators, other versions of themselves.
19+
- [`Veneers`](https://olm.operatorframework.io/docs/reference/veneers/) are a general class of objects which can provide a simplified interaction with FBC.
20+
- `Operator Author` is the role related to expressing an individual operator versions, channels, properties, etc. in a destination catalog.
21+
- `Catalog` is the destination FBC-based catalog composed of the FBC contributions of one or more operators.
22+
- `Catalog Owner` is the role related to integrating Operator Authors' catalog contributions.
23+
- `Catalog Contribution` is the FBC that an Operator Author needs to convey to the Catalog Owner. The format needs to be negotiated with the Catalog Owner.
24+
For this example, the Catalog Owner receives contributions of a single, unversioned directory named after the operator which contain all FBC files, e.g.:
25+
26+
```tree
27+
catalog
28+
└── testoperator
29+
├── .indexignore
30+
├── OWNERS
31+
└── catalog.yaml
32+
```
33+
34+
35+
### Lifecycle
36+
This repository models a single operator author contributing their FBC to a catalog. This repository has pre-configured GitHub actions to deliver the FBC to an example [catalog GitHub repository](https://github.com/grokspawn/cool-catalog/). The actions will generate the FBC from this repository and open a pull request on the catalog repository to merge them. (See that repository for more information about the lifecycle steps after creating the pull request.)
37+
38+
39+
```mermaid
40+
%%{init: {'securityLevel': 'strict', 'theme':'forest'}}%%
41+
42+
sequenceDiagram
43+
autonumber
44+
participant User
45+
participant LocalRepo
46+
participant RemoteRepo
47+
participant GHAction
48+
participant CatalogRepo
49+
activate User
50+
activate RemoteRepo
51+
User-->RemoteRepo: fork and clone repository
52+
activate LocalRepo
53+
User->>LocalRepo: update CI destination
54+
LocalRepo->>RemoteRepo: push CI changes to remote
55+
activate RemoteRepo
56+
User->>LocalRepo: update 'catalog' target
57+
LocalRepo->>RemoteRepo: push changes to remote
58+
deactivate LocalRepo
59+
deactivate User
60+
RemoteRepo--xGHAction: <<push trigger>
61+
deactivate RemoteRepo
62+
activate GHAction
63+
GHAction->>GHAction: Generate FBC from 'catalog' target
64+
GHAction->>GHAction: validate FBC
65+
activate CatalogRepo
66+
GHAction->>CatalogRepo: Open PR in catalog destination
67+
deactivate GHAction
68+
deactivate CatalogRepo
69+
70+
```
71+
72+
1. Fork and Clone Remote Repository
73+
IMPORTANT! Any operator-specific changes contributions to the parent repository will be discarded.
74+
75+
2. Update CI Destination
76+
Customize `.github/workflows/ci.yaml` to your needs, including setting the `destination_repo` to the URI of your catalog repository.
77+
78+
3. Push Changes to Remote
79+
Push the CI changes to the remote branch so they will trigger later when you push catalog contributions.
80+
81+
4. Update 'catalog' target
82+
Locally, update the catalog target in the Makefile to generate your FBC. Example targets are provided in the Makefile (with supporting artifacts) to support to the following scenarios:
83+
1. Basic veneer generates FBC.
84+
2. Semver veneer generates FBC.
85+
3. Compound veneer generates and post-processes FBC.
86+
87+
5. Push Changes to Remote
88+
Once the `catalog` make target and the resulting FBC are ready, push the changes to the remote repository. This will trigger the remote actions to generate a pull request against the destination catalog repository as specified in #2.
89+
90+
91+
92+
<!--
393
## Demo
4-
Recorded demo of modifying veneer.yaml, building, and pushing veneer to collection repository.
94+
Recorded demo of modifying a `basic veneer` file "basic-veneer.yaml", generating an FBC from it, and pushing that FBC as a PR to a catalog repository.
595
696
![asciicast](demo/fbc-veneer-demo-console.gif)
97+
-->

basic-veneer.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
schema: olm.package
3+
name: testoperator
4+
defaultChannel: stable
5+
---
6+
schema: olm.channel
7+
package: testoperator
8+
name: stable
9+
entries:
10+
- name: testoperator.v0.1.0
11+
- name: testoperator.v0.2.0
12+
replaces: testoperator.v0.1.0
13+
---
14+
schema: olm.bundle
15+
image: quay.io/ankitathomas/olm:testoperator.v0.1.0
16+
---
17+
schema: olm.bundle
18+
image: quay.io/ankitathomas/olm:testoperator.v0.2.0
19+

build.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

convert.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

sanity.sh

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /bin/bash
1+
#!/usr/bin/env bash
22
# PNAME=$$(bin/yq "select(.schema == \"olm.package\") | .name" catalog/$(OPERATOR_NAME)/catalog.yaml)
33
# @echo `bin/yq "select(.schema == \"olm.package\") | .name" catalog/$(OPERATOR_NAME)/catalog.yaml`
44
# @export PNAME=$(shell bin/yq "select(.schema == \"olm.package\") | .name" catalog/$(OPERATOR_NAME)/catalog.yaml)
@@ -13,13 +13,21 @@ function usage () {
1313
exit 1
1414
}
1515

16+
function logit() {
17+
if [ $QUIET_MODE -eq 0 ]; then
18+
echo $1
19+
fi
20+
}
21+
1622
YQ=bin/yq
23+
QUIET_MODE=0
1724

18-
while getopts 'n:f:' arg;
25+
while getopts 'n:f:q' arg;
1926
do
2027
case "$arg" in
2128
f) FILENAME=$OPTARG ;;
2229
n) PKGNAME=$OPTARG ;;
30+
q) QUIET_MODE=1 ;;
2331
h) usage ;;
2432
esac
2533
done
@@ -30,37 +38,37 @@ shift `expr $OPTIND - 1`
3038

3139
if [ -z $FILENAME ]
3240
then
33-
echo "veneer-file-name is empty"
41+
logit "veneer-file-name is empty"
3442
usage
3543
fi
3644

3745
if [ ! -e $FILENAME ]
3846
then
39-
echo "$FILENAME does not exist"
47+
logit "$FILENAME does not exist"
4048
exit 253
4149
fi
4250

4351
if [ -z $PKGNAME ]
4452
then
45-
echo "package-name is empty"
53+
logit "package-name is empty"
4654
usage
4755
fi
4856

4957
if [ ! -e $YQ ]
5058
then
51-
echo "unable to find yq binary: $YQ"
59+
logit "unable to find yq binary: $YQ"
5260
exit 255
5361
fi
5462

5563
SCHEMA_PNAME=$($YQ "select(.schema == \"olm.package\") | .name" ${FILENAME})
5664
if [ $SCHEMA_PNAME != $PKGNAME ]
5765
then
58-
echo "operator name in veneer and Makefile do not agree:"
59-
echo " Makefile(${SCHEMA_PNAME})"
60-
echo " veneer( ${PKGNAME})"
66+
logit "operator name in catalog and Makefile do not agree:"
67+
logit " Makefile(${SCHEMA_PNAME})"
68+
logit " catalog (${PKGNAME})"
6169
exit 254
6270
else
63-
echo "operator name match between veneer and Makefile"
71+
logit "operator name match between catalog and Makefile"
6472
fi
6573

6674

0 commit comments

Comments
 (0)