Create a file-based catalog image

You can use the opm CLI to create a catalog image that uses the plain text file-based catalog format (JSON or YAML), which replaces the deprecated SQLite database format.

Prerequisites
  • You have installed the opm CLI.

  • You have podman version 1.9.3+.

  • A bundle image is built and pushed to a registry that supports Docker v2-2.

Procedure
  1. Initialize the catalog:

    1. Create a directory for the catalog by running the following command:

      $ mkdir <catalog_dir>
    2. Generate a Dockerfile that can build a catalog image by running the opm generate dockerfile command:

      $ opm generate dockerfile <catalog_dir> \
          -i registry.redhat.io/openshift4/ose-operator-registry-rhel9:v{product-version}

      + Specify the official Red Hat base image by using the -i flag, otherwise the Dockerfile uses the default upstream image.

      The Dockerfile must be in the same parent directory as the catalog directory that you created in the previous step:

      Example directory structure
      .
      ├── <catalog_dir>
      └── <catalog_dir>.Dockerfile

      where:

      .

      Specifies the parent directory.

      <catalog_dir>

      Specifies the catalog directory.

      <catalog_dir>.Dockerfile

      Specifies the Dockerfile generated by the opm generate dockerfile command.

    3. Populate the catalog with the package definition for your Operator by running the opm init command:

      $ opm init <operator_name> \
          --default-channel=preview \
          --description=./README.md \
          --icon=./operator-icon.svg \
          --output yaml \
          > <catalog_dir>/index.yaml
      • Replace the <operator_name> variable with the Operator or package, name.

      • The --default-channel flag specifies the channel that subscriptions default to if unspecified.

      • The --description flag specifies the path to the Operator’s README.md or other documentation.

      • The --icon flag specifies the path to the Operator’s icon.

      • The --output flag specifies the output format. JSON or YAML are valid values.

      • Replace the <catalog_dir> variable with the path for creating the catalog configuration file.

        This command generates an olm.package declarative config blob in the specified catalog configuration file.

  2. Add a bundle to the catalog by running the opm render command:

    $ opm render <registry>/<namespace>/<bundle_image_name>:<tag> \
        --output=yaml \
        >> <catalog_dir>/index.yaml

    where:

    <registry>/<namespace>/<bundle_image_name>:<tag>

    Specifies the pull spec for the bundle image.

    <catalog_dir>/index.yaml

    Specifies the path to the catalog configuration file.

    Note

    Channels must contain at least one bundle.

  3. Add a channel entry for the bundle. For example, modify the following example to your specifications, and add it to your <catalog_dir>/index.yaml file:

    Example channel entry
    ---
    schema: olm.channel
    package: <operator_name>
    name: preview
    entries:
      - name: <operator_name>.v0.1.0

    Ensure that you include the period (.) after the <operator_name>`variable but before the `v in the version. Otherwise, the entry fails to pass the opm validate command.

  4. Validate the file-based catalog:

    1. Run the opm validate command against the catalog directory:

      $ opm validate <catalog_dir>
    2. Check that the error code is 0:

      $ echo $?
      Example output
      0
  5. Build the catalog image by running the podman build command:

    $ podman build . \
        -f <catalog_dir>.Dockerfile \
        -t <registry>/<namespace>/<catalog_image_name>:<tag>
  6. Push the catalog image to a registry:

    1. If required, authenticate with your target registry by running the podman login command:

      $ podman login <registry>
    2. Push the catalog image by running the podman push command:

      $ podman push <registry>/<namespace>/<catalog_image_name>:<tag>