Skip to content

Commit e90d0ad

Browse files
committed
Add CRC startup and deployment automation
Signed-off-by: perdasilva <[email protected]>
1 parent 55503f8 commit e90d0ad

File tree

9 files changed

+552
-6
lines changed

9 files changed

+552
-6
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,3 +461,8 @@ staging/*/vendor
461461
# Ignore sqlite
462462
*.db
463463
*.db-journal
464+
465+
# e2e on crc values file and patches
466+
values-crc-e2e.yaml
467+
scripts/**/*.crc.e2e.patch.yaml
468+

Makefile

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ OPM := $(addprefix bin/, opm)
2727
OLM_CMDS := $(shell go list -mod=vendor $(OLM_PKG)/cmd/...)
2828
PSM_CMD := $(addprefix bin/, psm)
2929
REGISTRY_CMDS := $(addprefix bin/, $(shell ls staging/operator-registry/cmd | grep -v opm))
30+
31+
# Default image tag for build/olm-container and build/registry-container
32+
IMG ?= test:test
33+
3034
# Phony prerequisite for targets that rely on the go build cache to determine staleness.
3135
.PHONY: FORCE
3236
FORCE:
@@ -83,11 +87,11 @@ ifeq ($(shell go env GOARCH),amd64)
8387
GOOS=windows CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_ENABLED=1 go build $(GO_BUILD_OPTS) $(GO_BUILD_TAGS) -o "bin/windows-amd64-opm" --ldflags "-extld=x86_64-w64-mingw32-gcc $(version_flags)" -buildmode=exe $(REGISTRY_PKG)/cmd/opm
8488
endif
8589

86-
build/olm-container:
87-
$(CONTAINER_ENGINE) build -f operator-lifecycle-manager.Dockerfile -t test:test .
90+
build/olm-container: clean
91+
$(CONTAINER_ENGINE) build -f operator-lifecycle-manager.Dockerfile -t ${IMG} .
8892

89-
build/registry-container:
90-
$(CONTAINER_ENGINE) build -f operator-registry.Dockerfile -t test:test .
93+
build/registry-container: clean
94+
$(CONTAINER_ENGINE) build -f operator-registry.Dockerfile -t ${IMG} .
9195

9296
bin/kubebuilder:
9397
$(ROOT_DIR)/scripts/install_kubebuilder.sh
@@ -158,6 +162,30 @@ verify:
158162
echo "Checking commit integrity"
159163
$(MAKE) verify-commits
160164

165+
.PHONY: crc-start
166+
crc-start:
167+
echo "Starting CRC"
168+
./scripts/crc-start.sh
169+
170+
.PHONY: crc-build
171+
crc-build:
172+
echo "Building olm image"
173+
IMG="olm:test" $(MAKE) build/olm-container
174+
echo "Building opm image"
175+
IMG="opm:test" $(MAKE) build/registry-container
176+
177+
.PHONY: crc-deploy
178+
crc-deploy:
179+
echo "Deploying OLM"
180+
./scripts/crc-deploy.sh
181+
182+
.PHONY: crc
183+
crc: crc-start crc-build crc-deploy
184+
185+
.PHONY: clean
186+
clean:
187+
rm -rf bin
188+
161189
.PHONY: help
162190
help: ## Display this help.
163191
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

docs/downstream-ci.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Downstream CI
2+
3+
The CI configuration for each release branch can be found [here](https://github.com/openshift/release/tree/master/ci-operator/config/openshift/operator-framework-olm).
4+
From `4.11` (`master` as of this writing) we've updated the configuration to able to influence CI on a PR basis. An overview of the `ci-operator` (the system used for ci)
5+
can be found [here](https://docs.ci.openshift.org/docs/architecture/ci-operator/).
6+
7+
### Structure
8+
9+
* `.ci-operator.yaml` defines the `build_root_image`. To be ART compliant, the image should come from the [ocp-build-data](https://github.com/openshift/ocp-build-data/) repo
10+
* [openshift-operator-framework-olm-master.yaml](https://github.com/openshift/release/blob/master/ci-operator/config/openshift/operator-framework-olm/openshift-operator-framework-olm-master.yaml) defines the images that are used by ci, produced by ci, and the ci jobs the get executed.
11+
* `base.Dockerfile` defines the image used by ci to execute the ci jobs
12+
13+
From [openshift-operator-framework-olm-master.yaml](https://github.com/openshift/release/blob/master/ci-operator/config/openshift/operator-framework-olm/openshift-operator-framework-olm-master.yaml), we see under the `images` stanza the `ci-image` definition.
14+
It goes from `src` (the `build_root_image`) to `ci-image` by building `base.Dockerfile` with `src` as the base image.
15+
16+
```
17+
- dockerfile_path: base.Dockerfile
18+
from: src
19+
to: ci-image
20+
```
21+
22+
The image is excluded from promotion, to never be posted up anywhere:
23+
24+
```
25+
promotion:
26+
excluded_images:
27+
- ci-image
28+
```
29+
30+
and each `test` references `ci-image` as the image to be used to the test, e.g.:
31+
32+
```
33+
tests:
34+
- as: verify
35+
commands: make verify
36+
container:
37+
from: ci-image
38+
```
39+
40+
### Updating go versions
41+
42+
All we need to do is update the `build_root_image` referenced in `.ci-operator.yaml` and we may also need to update the `base_images` in [openshift-operator-framework-olm-master.yaml](https://github.com/openshift/release/blob/master/ci-operator/config/openshift/operator-framework-olm/openshift-operator-framework-olm-master.yaml).
43+
44+
**NOTE**: I believe there is some automation that updates the base images, though I don't know. I'll leave this as a questions to the reviewer, and if no one knows, I'll go after it.
45+
46+
### Downstream sync
47+
48+
The complete information about the downstreaming process can be found [here](https://docs.google.com/document/d/139yXeOqAJbV1ndC7Q4NbaOtzbSdNpcuJan0iemORd3g/edit).
49+
50+
TL;DR;
51+
52+
We sync three upstream repositories ([api](https://github.com/operator-framework/api), [registry](https://github.com/operator-framework/operator-registry), [olm](https://github.com/operator-framework/operator-lifecycle-manager)) to the downstream [olm mono-repo](https://github.com/openshift/operator-framework-olm). Commits from the upstream repositories are cherry-picked to the appropriate `staging` directory in the downstream repository. Because this is a monorepo in the `Openshift` GitHub organization, two things need to be remembered:
53+
- we don't pull in upstream `vendor` folder changes
54+
- we don't pull in changes to `OWNERS` files
55+
- after each cherry-pick we execute: `make vendor` and `make manifest` to ensure a) the downstream dependencies are updated b) to ensure any manifest changes are picked up downstream
56+
57+
While manual changes to the `staging` directory should be avoided, there could be instances where there drift between the downstream `staging` directory and the corresponding upstream repository. This can happen due to applying commits out-of-order, e.g. due to feature freeze, etc.
58+
59+
Therefore, after a sync, it is important to manually verify the diff of `staging` and the upstream. Please note, though, that some downstream changes are downstream only. These are, however, few and far between and there are comments to indicate that a block of code is downstream only.
60+
61+
The downstream sync process is facilitated by two scripts: `scripts/sync_get_candidates.sh` and `scripts/sync_pop_candidate.sh`, which compare the upstream remote with the appropriate `staging` directory and gets a stack of commits to sync, and cherry-pick those commits in reverse order. What does this look like in practice:
62+
63+
```bash
64+
# Clone downstream
65+
git clone [email protected]:openshift/operator-framework-olm.git && cd operator-framework-olm
66+
67+
# Add and fetch upstream remotes
68+
git remote add api [email protected]:operator-framework/api.git && git fetch api
69+
git remote add operator-registry [email protected]:operator-framework/operator-registry.git && git fetch operator-registry
70+
git remote add operator-lifecycle-manager [email protected]:operator-framework/operator-lifecycle-manager.git && git fetch operator-lifecycle-manager
71+
72+
# Get upstream commit candidates: ./scripts/sync_get_candidates.sh <api|operator-registry|operator-lifecycle-manager> <branch>
73+
# The shas will be found in ./<api|operator-registry|operator-lifecycle-manager>.cherrypick
74+
./scripts/sync_get_candidates.sh api master
75+
./scripts/sync_get_candidates.sh operator-registry master
76+
./scripts/sync_get_candidates.sh operator-lifecycle-manager master
77+
78+
# Sync upstream commits: ./scripts/sync_pop_candidate.sh <api|operator-registry|operator-lifecycle-manager> [-a]
79+
# Without -a, you'll proceed one commit at a time. With -a the process will conclude once there are no more commits.
80+
# When a cherry pick encounters a conflict the script will stop so you can manually fix it.
81+
sync_pop_candidate.sh operator-lifecycle-manager -a
82+
83+
# When finished
84+
sync_pop_candidate.sh api -a
85+
86+
# When finished
87+
sync_pop_candidate.sh operator-registry -a
88+
89+
# Depending on the changes being pulled in, the order of repos you sync _could_ matter and _could_ leave a commit in an unbuildable state
90+
```
91+
92+
Example:
93+
94+
```bash
95+
$ sync_pop_candidate.sh operator-lifecycle-manager -a
96+
97+
.github/workflows: Enable workflow_dispatch event triggers (#2464)
98+
Author: Tim Flannagan <[email protected]>
99+
Date: Mon Dec 20 15:13:33 2021 -0500
100+
9 files changed, 9 insertions(+), 1 deletion(-)
101+
66 picks remaining (pop_all=true)
102+
popping: 4daeb114ccd56cee7132883325da68c80ba70bed
103+
Auto-merging staging/operator-lifecycle-manager/go.mod
104+
CONFLICT (content): Merge conflict in staging/operator-lifecycle-manager/go.mod
105+
Auto-merging staging/operator-lifecycle-manager/go.sum
106+
CONFLICT (content): Merge conflict in staging/operator-lifecycle-manager/go.sum
107+
CONFLICT (modify/delete): staging/operator-lifecycle-manager/vendor/github.com/operator-framework/api/pkg/validation/doc.go deleted in HEAD and modified in 4daeb114c (chore(api): Vendor the new version of api repo (#2525)). Version 4daeb114c (chore(api): Vendor the new version of api repo (#2525)) of staging/operator-lifecycle-manager/vendor/github.com/operator-framework/api/pkg/validation/doc.go left in tree.
108+
CONFLICT (modify/delete): staging/operator-lifecycle-manager/vendor/modules.txt deleted in HEAD and modified in 4daeb114c (chore(api): Vendor the new version of api repo (#2525)). Version 4daeb114c (chore(api): Vendor the new version of api repo (#2525)) of staging/operator-lifecycle-manager/vendor/modules.txt left in tree.
109+
error: could not apply 4daeb114c... chore(api): Vendor the new version of api repo (#2525)
110+
hint: After resolving the conflicts, mark them with
111+
hint: "git add/rm <pathspec>", then run
112+
hint: "git cherry-pick --continue".
113+
hint: You can instead skip this commit with "git cherry-pick --skip".
114+
hint: To abort and get back to the state before "git cherry-pick",
115+
hint: run "git cherry-pick --abort".
116+
117+
$ rm -rf staging/operator-lifecycle-manager/vendor
118+
119+
# make sure there are no conflics in
120+
# staging/operator-lifecycle-manager/go.mod and go.sum
121+
$ cd staging/operator-lifecycle-manager
122+
$ go mod tidy
123+
$ cd ../../
124+
125+
# now that the conflict is fixed, advance again
126+
$ sync_pop_candidate.sh operator-lifecycle-manager -a
127+
```
128+
129+
### Troubleshooting
130+
131+
#### Running console test locally
132+
133+
The [console](https://github.com/openshift/console) repository contains all instructions you need to execute the console tests locally. The olm console tests can be found [here](https://github.com/openshift/console/tree/master/frontend/packages/operator-lifecycle-manager)

docs/local-testing-with-crc.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Local testing with CRC
2+
3+
We can use CRC as an Openshift-like environment within which to test downstream OLM. [CRC](https://developers.redhat.com/products/codeready-containers/overview)
4+
is a tool for deploying a local Openshift cluster on your laptop.
5+
6+
TL;DR
7+
8+
1. Install [CRC](https://developers.redhat.com/products/codeready-containers/overview)
9+
2. `make crc` to provision a CRC cluster, build OLM, and deploy it on the cluster
10+
3. `export KUBECONFIG=~/.crc/machines/crc/kubeconfig`
11+
4. Execute e2e tests as you normally would, e.g., `make e2e/olm`
12+
13+
#### Gosh darn it, how does it work?
14+
15+
`./scripts/crc-start.sh` is used to provision a crc cluster. `./scripts/crc-deploy.sh` pushes the `olm:test` and `opm:test` to
16+
`image-registry.openshift-image-registry.svc:5000/openshift/olm:test` and `image-registry.openshift-image-registry.svc:5000/openshift/opm:test`
17+
images to the crc image registry under the global project `openshift` (to be independent from the olm namespace). It also generates an image stream
18+
from these images. Finally, using the istag for the image. It also generates the olm manifests by applying generated helm values file (`values-crc-e2e.yaml`)
19+
and other generated yaml patches (`scripts/*.crc.e2e.patch.yaml`) to make sure the manifests point to the newly pushed images. The generated manifests are
20+
then applied to the cluster using `kubectl replace` in priority order (lexical sort).
21+
22+
#### Make targets
23+
24+
1. `make crc-start`: provision a crc cluster, if necessary
25+
1. `FORCE_CLEAN=1 make crc-start`: nuke any current installation including cache and current cluster instance
26+
2. `make crc-build`: build olm images with the right tags
27+
3. `make crc-deploy`: generate manifests, upload olm images, deploy olm
28+
1. `SKIP_MANIFESTS=1 make crc-deploy`: skip manifest generation and deployment (only update images)
29+
2. `SKIP_WAIT_READY=1 make crc-deploy`: skip waiting for olm deployments to be available at the end
30+
4. `make crc`: the same as `make crc-start crc-build crc-deploy`
31+
32+
#### Manipulating Resources
33+
34+
If new resources are introduced that require being updated for local deployment (e.g. updating the pod spec image) follow
35+
the pattern used in `scripts/crc-deploy.sh:make_manifest_patches`

0 commit comments

Comments
 (0)