--- description: Execute opm (Operator Package Manager) commands for building and managing operator catalogs argument-hint: [arguments...] --- ## Name olm:opm ## Synopsis ```bash /olm:opm build-index-image [--cacheless] [--arch=] [--base-image=] [--builder-image=] /olm:opm build-semver-index-image [--cacheless] [--arch=] [--base-image=] [--builder-image=] /olm:opm generate-semver-template [--output=] [--major=true|false] [--minor=true|false] /olm:opm list packages /olm:opm list channels [package-name] /olm:opm list bundles [package-name] ``` ## Description The `olm:opm` command provides a unified interface to `opm` (Operator Package Manager) operations for building and managing operator catalog indexes. It supports building catalog indexes, generating semver templates, and querying catalog contents. ## Arguments - `$1`: **action** - The action to perform: - `build-index-image`: Build an index from an existing catalog directory - `build-semver-index-image`: Build an index from a semver template - `generate-semver-template`: Generate a semver template file - `list`: List catalog contents (requires second argument: `packages`, `channels`, or `bundles`) - `$2+`: Additional arguments specific to each action (see Actions section below) ## Actions ### build-index-image Build an operator catalog index image from an existing catalog directory. **Synopsis:** ```bash /olm:opm build-index-image [--cacheless] [--arch=] [--base-image=] [--builder-image=] ``` **Arguments:** - `$2`: **catalog-path** - Path to the catalog directory containing the index configuration - `$3`: **index-image-tag** - Full image tag for the resulting index image (e.g., `quay.io/myorg/mycatalog:v1.0.0`) - `--cacheless`: Optional flag to build a cacheless image (uses `scratch` as base image; `--base-image` and `--builder-image` are ignored when this is set) - `--arch=`: Optional architecture specification (default: `multi` for multi-arch build; can specify single arch like `amd64`, `arm64`, `ppc64le`, `s390x`) - `--base-image=`: Optional base image for the index (default: `quay.io/operator-framework/opm:latest`; ignored if `--cacheless` is set) - `--builder-image=`: Optional builder image (default: `quay.io/operator-framework/opm:latest`; ignored if `--cacheless` is set) **Examples:** ```bash /olm:opm build-index-image catalog quay.io/myorg/mycatalog:v1.0.0 /olm:opm build-index-image catalog quay.io/myorg/mycatalog:v1.0.0 --cacheless /olm:opm build-index-image catalog quay.io/myorg/mycatalog:v1.0.0 --arch=amd64 ``` ### build-semver-index-image Build a multi-architecture operator catalog index image using the semver template format. **Synopsis:** ```bash /olm:opm build-semver-index-image [--cacheless] [--arch=] [--base-image=] [--builder-image=] ``` **Arguments:** - `$2`: **semver-template-file** - Path to the semver template configuration file (e.g., `catalog-config.yaml`) - `$3`: **index-image-tag** - Full image tag for the resulting index image (e.g., `quay.io/myorg/mycatalog:v1.0.0`) - `--cacheless`: Optional flag to build a cacheless image (uses `scratch` as base image; `--base-image` and `--builder-image` are ignored when this is set) - `--arch=`: Optional architecture specification (default: `multi` for multi-arch build; can specify single arch like `amd64`, `arm64`, `ppc64le`, `s390x`) - `--base-image=`: Optional base image for the index (default: `quay.io/operator-framework/opm:latest`; ignored if `--cacheless` is set) - `--builder-image=`: Optional builder image (default: `quay.io/operator-framework/opm:latest`; ignored if `--cacheless` is set) **Examples:** ```bash /olm:opm build-semver-index-image catalog-config.yaml quay.io/myorg/mycatalog:v1.0.0 /olm:opm build-semver-index-image catalog-config.yaml quay.io/myorg/mycatalog:v1.0.0 --cacheless /olm:opm build-semver-index-image catalog-config.yaml quay.io/myorg/mycatalog:v1.0.0 --arch=amd64 /olm:opm build-semver-index-image catalog-config.yaml quay.io/myorg/mycatalog:v1.0.0 --arch=multi ``` ### generate-semver-template Generate a semver template configuration file for building operator catalogs. **Synopsis:** ```bash /olm:opm generate-semver-template [--output=] [--major=true|false] [--minor=true|false] ``` **Arguments:** - `$2`: **bundle-list** - Comma-separated list of bundle image references (e.g., `quay.io/org/bundle:v1.0.0,quay.io/org/bundle:v1.0.1`) - `--output=`: Optional output file path (default: `catalog-semver-config.yaml` in current directory) - `--major=true|false`: Optional flag to generate major version channels (default: `true`) - `--minor=true|false`: Optional flag to generate minor version channels (default: `false`) **Examples:** ```bash /olm:opm generate-semver-template quay.io/org/bundle:v1.0.0,quay.io/org/bundle:v1.0.1 /olm:opm generate-semver-template quay.io/org/bundle:v1.0.0,quay.io/org/bundle:v1.0.1 --output=my-catalog.yaml /olm:opm generate-semver-template quay.io/org/bundle:v1.0.0,quay.io/org/bundle:v1.1.0 --minor=true ``` ### list packages List all operator packages available in a catalog index. **Synopsis:** ```bash /olm:opm list packages ``` **Arguments:** - `$2`: **list** - Must be "list" - `$3`: **packages** - Must be "packages" - `$4`: **index-ref** - Catalog index reference, either: - Image tag: `quay.io/myorg/mycatalog:v1.0.0` - Directory path: `./catalog` or `/path/to/catalog` **Examples:** ```bash /olm:opm list packages quay.io/olmqe/nginx8518-index-test:v1 /olm:opm list packages ./catalog ``` ### list channels List channels for operator packages in a catalog index. **Synopsis:** ```bash /olm:opm list channels [package-name] ``` **Arguments:** - `$2`: **list** - Must be "list" - `$3`: **channels** - Must be "channels" - `$4`: **index-ref** - Catalog index reference (image tag or directory path) - `$5`: **package-name** (Optional) - Name of a specific package to list channels for **Examples:** ```bash /olm:opm list channels quay.io/olmqe/nginx8518-index-test:v1 /olm:opm list channels quay.io/olmqe/nginx8518-index-test:v1 nginx85187 /olm:opm list channels ./catalog ``` ### list bundles List bundles for operator packages in a catalog index. **Synopsis:** ```bash /olm:opm list bundles [package-name] ``` **Arguments:** - `$2`: **list** - Must be "list" - `$3`: **bundles** - Must be "bundles" - `$4`: **index-ref** - Catalog index reference (image tag or directory path) - `$5`: **package-name** (Optional) - Name of a specific package to list bundles for **Examples:** ```bash /olm:opm list bundles quay.io/olmqe/nginx8518-index-test:v1 /olm:opm list bundles quay.io/olmqe/nginx8518-index-test:v1 nginx85187 /olm:opm list bundles ./catalog ``` ## Implementation ### Step 1: Parse Action - Extract the action from `$1` - Validate the action is one of: `build-index-image`, `build-semver-index-image`, `generate-semver-template`, `list` - If invalid action, display error with available actions ### Step 2: Check Prerequisites Verify required tools are installed: - Check for `opm`: `which opm` - If not found, provide installation instructions: - For build actions, also check for `podman`: `which podman` - If not found, provide installation instructions based on user's platform ### Step 3: Route to Action Handler Based on the action, call the appropriate implementation: #### For `build-index-image`: 1. **Parse Arguments and Set Defaults** - Extract catalog path from `$2` - Extract index image tag from `$3` - Parse optional flags: `--cacheless`, `--arch`, `--base-image`, `--builder-image` - Set defaults: arch=`multi`, base-image=`quay.io/operator-framework/opm:latest`, builder-image=`quay.io/operator-framework/opm:latest` 2. **Verify Catalog Directory** - Check catalog directory exists: `test -d ` 3. **Validate Catalog** ```bash opm validate ``` 4. **Generate Dockerfile** - If cacheless: `opm generate dockerfile --base-image=scratch` - If normal: `opm generate dockerfile -b -i ` 5. **Determine Build Platform** - If arch=`multi`: `linux/amd64,linux/arm64,linux/ppc64le,linux/s390x` - Otherwise: `linux/` 6. **Create Podman Manifest** ```bash podman manifest rm 2>/dev/null || true podman manifest create ``` 7. **Build Image** ```bash podman build --platform --manifest . -f catalog.Dockerfile ``` 8. **Push Manifest** ```bash podman manifest push ``` 9. **List Bundles in Index** ```bash opm alpha list bundles ``` 10. **Display Success Message** #### For `build-semver-index-image`: 1. **Parse Arguments and Set Defaults** - Extract semver template file from `$2` - Extract index image tag from `$3` - Parse optional flags: `--cacheless`, `--arch`, `--base-image`, `--builder-image` - Set defaults: arch=`multi`, base-image=`quay.io/operator-framework/opm:latest`, builder-image=`quay.io/operator-framework/opm:latest` 2. **Verify Template File** - Check file exists: `test -f ` 3. **Create Catalog and Render Template** ```bash mkdir -p catalog opm alpha render-template semver -o yaml > catalog/index.yaml ``` 4. **Validate Catalog** ```bash opm validate catalog ``` 5. **Generate Dockerfile** - If cacheless: `opm generate dockerfile catalog --base-image=scratch` - If normal: `opm generate dockerfile catalog -b -i ` 6. **Determine Build Platform** - If arch=`multi`: `linux/amd64,linux/arm64,linux/ppc64le,linux/s390x` - Otherwise: `linux/` 7. **Create Podman Manifest** ```bash podman manifest rm 2>/dev/null || true podman manifest create ``` 8. **Build Image** ```bash podman build --platform --manifest . -f catalog.Dockerfile ``` 9. **Push Manifest** ```bash podman manifest push ``` 10. **List Bundles in Index** ```bash opm alpha list bundles ``` 11. **Display Success Message** #### For `generate-semver-template`: 1. **Parse Arguments and Set Defaults** - Extract bundle list from `$2` - Parse optional flags: `--output`, `--major`, `--minor` - Set defaults: output=`catalog-semver-config.yaml`, major=`true`, minor=`false` 2. **Validate Bundle List** - Split by commas - Validate each bundle is a valid image reference 3. **Generate YAML Content** ```yaml Schema: olm.semver GenerateMajorChannels: GenerateMinorChannels: Candidate: Bundles: - Image: - Image: ``` 4. **Write Template File** - Check if file exists and confirm overwrite if needed - Write YAML content 5. **Validate Generated File** - Read back and verify YAML is well-formed 6. **Display Success Message** - Show file path, bundles included, settings - Suggest next step: `/olm:opm build-semver-index-image ` #### For `list`: 1. **Parse List Type** - Extract list type from `$2` (must be `packages`, `channels`, or `bundles`) - If invalid, display error with available types 2. **Parse Index Reference and Optional Package** - Extract index-ref from `$3` - Extract optional package-name from `$4` (for channels and bundles) 3. **Determine Reference Type** - Check if directory: `test -d ` 4. **Execute List Command** - For packages: `opm alpha list packages ` - For channels: `opm alpha list channels [package-name]` - For bundles: `opm alpha list bundles [package-name]` 5. **Display Results** - Show the output with appropriate formatting - Display count of items found ## Return Value **Format**: Varies by action - **build-index-image / build-semver-index-image**: Success message with image tag, architectures, and bundle list - **generate-semver-template**: Success message with file path and configuration details - **list**: Table or list of catalog contents On failure, displays: - Clear error message indicating which step/action failed - Relevant tool output for debugging - Suggestions for resolution ## Notes - Ensure you are authenticated to container registries before building/pushing images (use `podman login`) - For build operations, the `catalog.Dockerfile` is created in the current working directory - Multi-architecture builds can be time-consuming - Cacheless builds result in smaller images and use `scratch` as the base image - When using `--cacheless`, the `--base-image` and `--builder-image` options are ignored (scratch is always used as base) - Index references can be either image tags or local directory paths - Bundle images must be accessible from where you build the catalog - Image tags should include the full registry hostname (e.g., `quay.io/org/image:tag` not `quay/org/image:tag`) ## Related Commands - `/olm:install` - Install an operator using OLM - `/olm:catalog` - Manage catalog sources - `/olm:debug` - Debug OLM issues