|
| 1 | +# Building Operator Updates for OLM |
| 2 | + |
| 3 | +This guide explains how to build operator versions that support OLM (Operator Lifecycle Manager) upgrades. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- An existing operator version is deployed via OLM |
| 8 | +- The previous version's bundle exists in a container registry |
| 9 | +- You have push access to your container registry |
| 10 | + |
| 11 | +## Simple Update (Single Version Upgrade) |
| 12 | + |
| 13 | +When creating your first update from an upstream version to your custom version: |
| 14 | + |
| 15 | +**Example: Upgrading from upstream v0.6.0 to custom v0.6.1** |
| 16 | + |
| 17 | +```bash |
| 18 | +IMAGENAMESPACE=userx \ |
| 19 | +IMAGE_TAG_BASE=quay.io/userx/openstack-operator \ |
| 20 | +REPLACES=openstack-operator.v0.6.0 \ |
| 21 | +VERSION=0.6.1 \ |
| 22 | +IMG=quay.io/userx/openstack-operator:v0.6.1 \ |
| 23 | +make manifests generate bindata build docker-build docker-push bundle bundle-build bundle-push catalog-build catalog-push |
| 24 | +``` |
| 25 | + |
| 26 | +**What this does:** |
| 27 | +- Creates v0.6.1 bundle with `replaces: openstack-operator.v0.6.0` in the CSV |
| 28 | +- `PREV_BUNDLE_IMG` defaults to `quay.io/openstack-k8s-operators/openstack-operator-bundle:latest` (upstream) |
| 29 | +- Builds catalog containing both v0.6.0 (upstream) and v0.6.1 (yours) |
| 30 | +- OLM will detect the upgrade path: v0.6.0 → v0.6.1 |
| 31 | + |
| 32 | +## Multi-Version Updates (Incremental Upgrades) |
| 33 | + |
| 34 | +When creating subsequent versions on top of your own versions: |
| 35 | + |
| 36 | +**Example: Upgrading from custom v0.6.1 to custom v0.6.2** |
| 37 | + |
| 38 | +```bash |
| 39 | +IMAGENAMESPACE=userx \ |
| 40 | +IMAGE_TAG_BASE=quay.io/userx/openstack-operator \ |
| 41 | +REPLACES=openstack-operator.v0.6.1 \ |
| 42 | +VERSION=0.6.2 \ |
| 43 | +IMG=quay.io/userx/openstack-operator:v0.6.2 \ |
| 44 | +PREV_BUNDLE_IMG=quay.io/userx/openstack-operator-bundle:v0.6.1 \ |
| 45 | +CATALOG_BASE_IMG=quay.io/userx/openstack-operator-index:v0.6.1 \ |
| 46 | +make manifests generate bindata build docker-build docker-push bundle bundle-build bundle-push catalog-build catalog-push |
| 47 | +``` |
| 48 | + |
| 49 | +**What this does:** |
| 50 | +- Creates v0.6.2 bundle with `replaces: openstack-operator.v0.6.1` in the CSV |
| 51 | +- `PREV_BUNDLE_IMG` points to your v0.6.1 bundle (not upstream) |
| 52 | +- `CATALOG_BASE_IMG` uses your existing v0.6.1 catalog as a base |
| 53 | +- Builds catalog containing v0.6.0 → v0.6.1 → v0.6.2 |
| 54 | +- OLM will detect the upgrade path from v0.6.1 to v0.6.2 |
| 55 | + |
| 56 | +## Key Variables Explained |
| 57 | + |
| 58 | +| Variable | Purpose | Example | |
| 59 | +|----------|---------|---------| |
| 60 | +| `REPLACES` | Previous CSV name that this version replaces | `openstack-operator.v0.6.1` | |
| 61 | +| `VERSION` | New version being built | `0.6.2` | |
| 62 | +| `IMG` | New operator image | `quay.io/userx/openstack-operator:v0.6.2` | |
| 63 | +| `PREV_BUNDLE_IMG` | Bundle image of the version being replaced (used with `REPLACES`) | `quay.io/userx/openstack-operator-bundle:v0.6.1` | |
| 64 | +| `CATALOG_BASE_IMG` | Existing catalog to build upon (for incremental builds) | `quay.io/userx/openstack-operator-index:v0.6.1` | |
| 65 | +| `CATALOG_BUNDLE_IMGS` | Comma-separated list of all bundles to include (for building complete upgrade path from scratch) | `"bundle1:latest,bundle2:v0.6.1,bundle3:v0.6.2"` | |
| 66 | + |
| 67 | +## Variable Defaults |
| 68 | + |
| 69 | +If not specified: |
| 70 | +- `PREV_BUNDLE_IMG` defaults to `quay.io/openstack-k8s-operators/openstack-operator-bundle:latest` (upstream) |
| 71 | +- `CATALOG_BASE_IMG` - if not set, builds a fresh catalog from scratch |
| 72 | +- `CATALOG_BUNDLE_IMGS` - auto-computed based on other variables (see strategies below) |
| 73 | + |
| 74 | +## Catalog Building Strategies |
| 75 | + |
| 76 | +There are three approaches to building catalogs: |
| 77 | + |
| 78 | +### 1. Incremental Build (Recommended for iterative development) |
| 79 | + |
| 80 | +Use `CATALOG_BASE_IMG` to add the new bundle to an existing catalog: |
| 81 | + |
| 82 | +```bash |
| 83 | +IMAGENAMESPACE=userx \ |
| 84 | +IMAGE_TAG_BASE=quay.io/userx/openstack-operator \ |
| 85 | +REPLACES=openstack-operator.v0.6.2 \ |
| 86 | +VERSION=0.6.3 \ |
| 87 | +IMG=quay.io/userx/openstack-operator:v0.6.3 \ |
| 88 | +PREV_BUNDLE_IMG=quay.io/userx/openstack-operator-bundle:v0.6.2 \ |
| 89 | +CATALOG_BASE_IMG=quay.io/userx/openstack-operator-index:v0.6.2 \ |
| 90 | +make catalog-build catalog-push |
| 91 | +``` |
| 92 | + |
| 93 | +**Pros:** Fast, builds on existing catalog |
| 94 | +**Cons:** Requires previous catalog to be available |
| 95 | + |
| 96 | +### 2. Auto From Scratch (Single Previous Version) |
| 97 | + |
| 98 | +Use `REPLACES` without `CATALOG_BASE_IMG` to include one previous version: |
| 99 | + |
| 100 | +```bash |
| 101 | +IMAGENAMESPACE=userx \ |
| 102 | +IMAGE_TAG_BASE=quay.io/userx/openstack-operator \ |
| 103 | +REPLACES=openstack-operator.v0.6.2 \ |
| 104 | +VERSION=0.6.3 \ |
| 105 | +IMG=quay.io/userx/openstack-operator:v0.6.3 \ |
| 106 | +PREV_BUNDLE_IMG=quay.io/userx/openstack-operator-bundle:v0.6.2 \ |
| 107 | +make catalog-build catalog-push |
| 108 | +``` |
| 109 | + |
| 110 | +**Pros:** Builds from scratch, no base image needed |
| 111 | +**Cons:** Only includes one upgrade step (v0.6.2 → v0.6.3), not the full upgrade path |
| 112 | + |
| 113 | +### 3. Full From Scratch (Complete Upgrade Path) |
| 114 | + |
| 115 | +Specify all bundles explicitly with `CATALOG_BUNDLE_IMGS`: |
| 116 | + |
| 117 | +```bash |
| 118 | +IMAGENAMESPACE=userx \ |
| 119 | +IMAGE_TAG_BASE=quay.io/userx/openstack-operator \ |
| 120 | +VERSION=0.6.3 \ |
| 121 | +IMG=quay.io/userx/openstack-operator:v0.6.3 \ |
| 122 | +CATALOG_BUNDLE_IMGS="quay.io/openstack-k8s-operators/openstack-operator-bundle:latest,quay.io/userx/openstack-operator-bundle:v0.6.1,quay.io/userx/openstack-operator-bundle:v0.6.2,quay.io/userx/openstack-operator-bundle:v0.6.3" \ |
| 123 | +make catalog-build catalog-push |
| 124 | +``` |
| 125 | + |
| 126 | +**Pros:** Complete control, builds full upgrade path from scratch, reproducible |
| 127 | +**Cons:** Must list all bundles manually |
| 128 | + |
| 129 | +**Recommendation:** Use strategy #3 for production releases and strategy #1 for iterative development. |
| 130 | + |
| 131 | +## Deploying the Update |
| 132 | + |
| 133 | +After building and pushing: |
| 134 | + |
| 135 | +1. Update the CatalogSource to use the new catalog image: |
| 136 | + ```bash |
| 137 | + oc patch catalogsource openstack-operator-index \ |
| 138 | + -n openstack-operators \ |
| 139 | + --type merge \ |
| 140 | + -p '{"spec":{"image":"quay.io/userx/openstack-operator-index:v0.6.2"}}' |
| 141 | + ``` |
| 142 | + |
| 143 | +2. Delete the catalog pod to force refresh: |
| 144 | + ```bash |
| 145 | + oc delete pod -n openstack-operators -l olm.catalogSource=openstack-operator-index |
| 146 | + ``` |
| 147 | + |
| 148 | +3. Check for upgrade: |
| 149 | + ```bash |
| 150 | + oc get subscription openstack -n openstack-operators |
| 151 | + ``` |
| 152 | + |
| 153 | +4. Approve the InstallPlan (if using Manual approval): |
| 154 | + ```bash |
| 155 | + oc patch installplan <installplan-name> \ |
| 156 | + -n openstack-operators \ |
| 157 | + --type merge \ |
| 158 | + -p '{"spec":{"approved":true}}' |
| 159 | + ``` |
| 160 | + |
| 161 | +## Troubleshooting |
| 162 | + |
| 163 | +### Upgrade not detected |
| 164 | + |
| 165 | +Check that both versions are in the catalog: |
| 166 | +```bash |
| 167 | +oc get packagemanifest openstack-operator -n openstack-operators -o json | \ |
| 168 | + jq -r '.status.channels[] | select(.name=="alpha") | .entries[] | .name' |
| 169 | +``` |
| 170 | + |
| 171 | +Both the current and new version should appear. |
| 172 | + |
| 173 | +### Bundle image not found |
| 174 | + |
| 175 | +Ensure the previous bundle was pushed: |
| 176 | +```bash |
| 177 | +skopeo inspect docker://quay.io/userx/openstack-operator-bundle:v0.6.1 |
| 178 | +``` |
| 179 | + |
| 180 | +## Complete Example Workflows |
| 181 | + |
| 182 | +### Approach A: Incremental Builds (Using CATALOG_BASE_IMG) |
| 183 | + |
| 184 | +Building v0.6.1, v0.6.2, and v0.6.3 incrementally: |
| 185 | + |
| 186 | +```bash |
| 187 | +# First custom version (from upstream v0.6.0) |
| 188 | +IMAGENAMESPACE=userx IMAGE_TAG_BASE=quay.io/userx/openstack-operator \ |
| 189 | +REPLACES=openstack-operator.v0.6.0 VERSION=0.6.1 \ |
| 190 | +IMG=quay.io/userx/openstack-operator:v0.6.1 \ |
| 191 | +make manifests generate bindata build docker-build docker-push bundle bundle-build bundle-push catalog-build catalog-push |
| 192 | + |
| 193 | +# Second version (builds on v0.6.1 catalog) |
| 194 | +IMAGENAMESPACE=userx IMAGE_TAG_BASE=quay.io/userx/openstack-operator \ |
| 195 | +REPLACES=openstack-operator.v0.6.1 VERSION=0.6.2 \ |
| 196 | +IMG=quay.io/userx/openstack-operator:v0.6.2 \ |
| 197 | +PREV_BUNDLE_IMG=quay.io/userx/openstack-operator-bundle:v0.6.1 \ |
| 198 | +CATALOG_BASE_IMG=quay.io/userx/openstack-operator-index:v0.6.1 \ |
| 199 | +make manifests generate bindata build docker-build docker-push bundle bundle-build bundle-push catalog-build catalog-push |
| 200 | + |
| 201 | +# Third version (builds on v0.6.2 catalog) |
| 202 | +IMAGENAMESPACE=userx IMAGE_TAG_BASE=quay.io/userx/openstack-operator \ |
| 203 | +REPLACES=openstack-operator.v0.6.2 VERSION=0.6.3 \ |
| 204 | +IMG=quay.io/userx/openstack-operator:v0.6.3 \ |
| 205 | +PREV_BUNDLE_IMG=quay.io/userx/openstack-operator-bundle:v0.6.2 \ |
| 206 | +CATALOG_BASE_IMG=quay.io/userx/openstack-operator-index:v0.6.2 \ |
| 207 | +make manifests generate bindata build docker-build docker-push bundle bundle-build bundle-push catalog-build catalog-push |
| 208 | +``` |
| 209 | + |
| 210 | +Each catalog contains the full upgrade path from v0.6.0. |
| 211 | + |
| 212 | +### Approach B: Full From Scratch (Using CATALOG_BUNDLE_IMGS) |
| 213 | + |
| 214 | +Building v0.6.3 with complete upgrade path in one step: |
| 215 | + |
| 216 | +```bash |
| 217 | +# Build all versions |
| 218 | +IMAGENAMESPACE=userx IMAGE_TAG_BASE=quay.io/userx/openstack-operator \ |
| 219 | +REPLACES=openstack-operator.v0.6.0 VERSION=0.6.1 \ |
| 220 | +IMG=quay.io/userx/openstack-operator:v0.6.1 \ |
| 221 | +make manifests generate bindata build docker-build docker-push bundle bundle-build bundle-push |
| 222 | + |
| 223 | +IMAGENAMESPACE=userx IMAGE_TAG_BASE=quay.io/userx/openstack-operator \ |
| 224 | +REPLACES=openstack-operator.v0.6.1 VERSION=0.6.2 \ |
| 225 | +IMG=quay.io/userx/openstack-operator:v0.6.2 \ |
| 226 | +make manifests generate bindata build docker-build docker-push bundle bundle-build bundle-push |
| 227 | + |
| 228 | +IMAGENAMESPACE=userx IMAGE_TAG_BASE=quay.io/userx/openstack-operator \ |
| 229 | +REPLACES=openstack-operator.v0.6.2 VERSION=0.6.3 \ |
| 230 | +IMG=quay.io/userx/openstack-operator:v0.6.3 \ |
| 231 | +make manifests generate bindata build docker-build docker-push bundle bundle-build bundle-push |
| 232 | + |
| 233 | +# Build complete catalog with all bundles |
| 234 | +IMAGENAMESPACE=userx IMAGE_TAG_BASE=quay.io/userx/openstack-operator \ |
| 235 | +VERSION=0.6.3 IMG=quay.io/userx/openstack-operator:v0.6.3 \ |
| 236 | +CATALOG_BUNDLE_IMGS="quay.io/openstack-k8s-operators/openstack-operator-bundle:latest,quay.io/userx/openstack-operator-bundle:v0.6.1,quay.io/userx/openstack-operator-bundle:v0.6.2,quay.io/userx/openstack-operator-bundle:v0.6.3" \ |
| 237 | +make catalog-build catalog-push |
| 238 | +``` |
| 239 | + |
| 240 | +This approach is reproducible and doesn't depend on previous catalog images. |
0 commit comments