For OKD clusters installed on restricted networks, also known as disconnected clusters, Operator Lifecycle Manager (OLM) by default cannot access the Red Hat-provided OperatorHub sources hosted on Quay.io because they require full Internet connectivity. However, cluster administrators can disable those remote sources, create local mirrors of that same content, and configure OLM to install and manage Operators from the local sources instead.

While OLM can manage Operators from local sources, the ability for a given Operator to run successfully in a restricted network still depends on the Operator itself. The Operator must:

  • List any related images, or other container images that the Operator might require to perform their functions, in the relatedImages parameter of its ClusterServiceVersion (CSV) object.

  • Reference all specified images by a digest (SHA) and not by a tag.

See the following Red Hat Knowledgebase Article for a list of Red Hat Operators that support running in disconnected mode:

Understanding Operator catalogs

An Operator catalog is a repository of metadata that Operator Lifecycle Manager (OLM) can query to discover and install Operators and their dependencies on a cluster. OLM always installs Operators from the latest version of a catalog. As of OKD 4.6, Red Hat-provided catalogs are distributed using index images.

An index image, based on the Operator Bundle Format, is a containerized snapshot of a catalog. It is an immutable artifact that contains the database of pointers to a set of Operator manifest content. A catalog can reference an index image to source its content for OLM on the cluster.

Starting in OKD 4.6, index images provided by Red Hat replace the App Registry catalog images, based on the deprecated Package Manifest Format, that are distributed for previous versions of OKD 4. While App Registry catalog images are not distributed by Red Hat for OKD 4.6 and later, custom catalog images based on the Package Manifest Format are still supported.

As catalogs are updated, the latest versions of Operators change, and older versions may be removed or altered. In addition, when OLM runs on an OKD cluster in a restricted network environment, it is unable to access the catalogs directly from the Internet to pull the latest content.

As a cluster administrator, you can create your own custom index image, either based on a Red Hat-provided catalog or from scratch, which can be used to source the catalog content on the cluster. Creating and updating your own index image provides a method for customizing the set of Operators available on the cluster, while also avoiding the aforementioned restricted network environment issues.

When creating custom catalog images, previous versions of OKD 4 required using the oc adm catalog build command, which has been deprecated for several releases. With the availability of Red Hat-provided index images starting in OKD 4.6, catalog builders should start switching to using the opm index command to manage index images before the oc adm catalog build command is removed in a future release.

Prerequisites

  • If you want to prune the default catalog and selectively mirror only a subset of Operators, install the opm CLI.

Disabling the default OperatorHub sources

Operator catalogs that source content provided by Red Hat and community projects are configured for OperatorHub by default during an OKD installation. Before configuring OperatorHub to instead use local catalog sources in a restricted network environment, you must disable the default catalogs.

Procedure
  • Disable the sources for the default catalogs by adding disableAllDefaultSources: true to the OperatorHub spec:

    $ oc patch OperatorHub cluster --type json \
        -p '[{"op": "add", "path": "/spec/disableAllDefaultSources", "value": true}]'

Pruning an index image

An index image, based on the Operator Bundle Format, is a containerized snapshot of an Operator catalog. You can prune an index of all but a specified list of packages, creating a copy of the source index containing only the Operators that you want.

When configuring Operator Lifecycle Manager (OLM) to use mirrored content on restricted network OKD clusters, use this pruning method if you want to only mirror a subset of Operators from the default catalogs.

For the steps in this procedure, the target registry is an existing mirror registry that is accessible by both your cluster and a workstation with unrestricted network access. This example also shows pruning the index image for the default upstream-community-operators catalog, but the process is the same for all index images.

Prerequisites
  • Workstation with unrestricted network access

  • podman version 1.4.4+

  • grpcurl

  • opm version 1.12.3+

  • Access to a registry that supports Docker v2-2

Procedure
  1. Authenticate with your target registry:

    $ podman login <target_registry>
  2. Determine the list of packages you want to include in your pruned index.

    1. Run the source index image that you want to prune in a container. For example:

      $ podman run -p50051:50051 \
          -it quay.io/operator-framework/upstream-community-operators:latest
      Example output
      Trying to pull quay.io/operator-framework/upstream-community-operators:latest...
      Getting image source signatures
      Copying blob ae8a0c23f5b1 done
      ...
      INFO[0000] serving registry                              database=/database/index.db port=50051
    2. In a separate terminal session, use the grpcurl command to get a list of the packages provided by the index:

      $ grpcurl -plaintext localhost:50051 api.Registry/ListPackages > packages.out
    3. Inspect the packages.out file and identify which package names from this list you want to keep in your pruned index. For example:

      Example snippets of packages list
      ...
      {
        "name": "couchdb-operator"
      }
      ...
      {
        "name": "eclipse-che"
      }
      ...
      {
      {
        "name": "etcd"
      }
      ...
    4. In the terminal session where you executed the podman run command, press Ctrl and C to stop the container process.

  3. Run the following command to prune the source index of all but the specified packages:

    $ opm index prune \
        -f quay.io/operator-framework/upstream-community-operators:latest \(1)
        -p couchdb-operator,eclipse-che,etcd \(2)
        -t <target_registry>:<port>/<namespace>/upstream-community-operators:latest (3)
    1 Index to prune.
    2 Comma-separated list of packages to keep.
    3 Custom tag for new index image being built.
  4. Run the following command to push the new index image to your target registry:

    $ podman push <target_registry>:<port>/<namespace>/upstream-community-operators:latest

    where <namespace> is any existing namespace on the registry. For example, you might create an olm-mirror namespace to push all mirrored content to.

Mirroring an Operator catalog

You can mirror the Operator content of a Red Hat-provided catalog, or a custom catalog, into a container image registry using the oc adm catalog mirror command. The target registry must support Docker v2-2. For a cluster on a restricted network, this registry can be a registry that the cluster has network access to, such as a mirror registry created during a restricted network cluster installation.

You must also mirror the Red Hat-provided index image, or push your own custom-built index image, to the target registry by using the oc image mirror command. You can then use the mirrored index image to create a CatalogSource that allows Operator Lifecycle Manager (OLM) to load the mirrored catalog onto your OKD cluster.

For the steps in this procedure, the target registry is an existing mirror registry that is accessible by both your cluster and a workstation with unrestricted network access. This example also shows mirroring the default upstream-community-operators catalog, but the process is the same for all catalogs.

Prerequisites
  • Workstation with unrestricted network access

  • podman version 1.4.4+

  • Access to mirror registry that supports Docker v2-2

  • If you are working with private registries, set the REG_CREDS environment variable to the file path of your registry credentials for use in later steps. For example, for the podman CLI:

    $ REG_CREDS=${XDG_RUNTIME_DIR}/containers/auth.json
Procedure
  1. On your workstation with unrestricted network access, use the podman login command to authenticate with the your target mirror registry:

    $ podman login <mirror_registry>
  2. The oc adm catalog mirror command extracts the contents of an index image to generate the manifests required for mirroring. You can choose either of the following:

    • Allow the default behavior of the command to automatically mirror all of the image content from the index image to your mirror registry after generating manifests.

    • Add the --manifests-only flag to only generate the manifests required for mirroring, but do not actually mirror the image content to the registry yet. This can be useful for reviewing what will be mirrored, and it allows you to make any changes to the mapping list if you only require a subset of packages. You can then use that file with the oc image mirror command to mirror the modified list of images in a later step.

      The --manifests-only flag is intended for advanced selective mirroring of content from the catalog. The opm index prune command, if you used it previously to prune the index image, is suitable for most use cases.

    On your workstation with unrestricted network access, run the following command:

    $ oc adm catalog mirror \
        <index_image> \(1)
        <mirror_registry>:<port> \(2)
        [-a ${REG_CREDS}] \(3)
        [--insecure] \(4)
        [--filter-by-os="<os>/<arch>"] \(5)
        [--manifests-only] (6)
    1 Specify the index image for the catalog you want to mirror. For example, this might be a pruned index image that you created previously, or one of the source index images for the default catalogs, such as quay.io/operator-framework/upstream-community-operators:latest.
    2 Specify the target registry to mirror the Operator content to.
    3 Optional: If required, specify the location of your registry credentials file.
    4 Optional: If you do not want to configure trust for the target registry, add the --insecure flag.
    5 Optional: Because the catalog might reference images that support multiple architectures and operating systems, you can filter by architecture and operating system to mirror only the images that match. Valid values are linux/amd64, linux/ppc64le, and linux/s390x.
    6 Optional: Only generate the manifests required for mirroring and do not actually mirror the image content to a registry.
    Example output
    src image has index label for database path: /database/index.db
    using database path mapping: /database/index.db:/tmp/153048078
    wrote database to /tmp/153048078 (1)
    ...
    wrote mirroring manifests to upstream-community-operators-manifests
    1 Directory for the temporary index.db database generated by the command.

    After running the command, a <image_name>-manifests/ directory is created in the current directory and generates the following files:

    • The imageContentSourcePolicy.yaml file defines an ImageContentSourcePolicy object that can configure nodes to translate between the image references stored in Operator manifests and the mirrored registry.

    • The mapping.txt file contains all of the source images and where to map them in the target registry. This file is compatible with the oc image mirror command and can be used to further customize the mirroring configuration.

  3. If you used the --manifests-only flag in the previous step and want to further trim the subset of packages to be mirrored:

    1. Modify the list of images in your mapping.txt file to your specifications. If you are unsure of the exact names and versions of the subset of images you want to mirror, use the following steps to find them:

      1. Run the sqlite3 tool against the temporary database that was generated by the oc adm catalog mirror command to retrieve a list of images matching a general search query. The output helps inform how you will later edit your mapping.txt file.

        For example, to retrieve a list of images that are similar to the string jaeger:

        $ echo "select * from related_image \
            where operatorbundle_name like '%jaeger%';" \
            | sqlite3 -line /tmp/153048078/index.db (1)
        1 Refer to the previous output of the oc adm catalog mirror command to find the path of the database file.
        Example output
        ...
        image = example.com/distributed-tracing/jaeger-all-in-one-rhel7@sha256:41f769c2c32f3f050aa42d86f084b739914ff9ba2f0aed2d9b0b69357b48459d
        operatorbundle_name = jaeger-operator.v1.17.6
        
        image = example.com/distributed-tracing/jaeger-es-index-cleaner-rhel7@sha256:c64ac461d96523516a199bd132ad4d7148317e503a735028f0d8f7ba063a61cb
        operatorbundle_name = jaeger-operator.v1.17.6
        
        image = example.com/distributed-tracing/jaeger-rhel7-operator:1.13.2
        operatorbundle_name = jaeger-operator.v1.13.2-1
      2. Use the results from the previous step to help you edit the mapping.txt file to only include the subset of images you want to mirror.

        For example, you can use the image values from the previous example output to find that the following matching lines exist in your mapping.txt file:

        Matching image mappings in mapping.txt
        ...
        example.com/distributed-tracing/jaeger-all-in-one-rhel7@sha256:41f769c2c32f3f050aa42d86f084b739914ff9ba2f0aed2d9b0b69357b48459d=quay.io/adellape/distributed-tracing-jaeger-all-in-one-rhel7:5cf7a033
        ...
        example.com/distributed-tracing/jaeger-es-index-cleaner-rhel7@sha256:c64ac461d96523516a199bd132ad4d7148317e503a735028f0d8f7ba063a61cb=quay.io/adellape/distributed-tracing-jaeger-es-index-cleaner-rhel7:ecfd2ca7
        ...
        example.com/distributed-tracing/jaeger-rhel7-operator:1.13.2=quay.io/adellape/distributed-tracing-jaeger-rhel7-operator:1.13.2
        ...

        In this example, if you only want to mirror these images, you would then remove all other entries in the mapping.txt file and leave only the above matching image mapping lines.

    2. Still on your workstation with unrestricted network access, use your modified mapping.txt file to mirror the images to your registry using the oc image mirror command:

      $ oc image mirror \
          [-a ${REG_CREDS}] \
          -f ./upstream-community-operators-manifests/mapping.txt
  4. Apply the ImageContentSourcePolicy:

    $ oc apply -f ./upstream-community-operators-manifests/imageContentSourcePolicy.yaml
  5. If you are not using a custom, pruned version of an index image, push the Red Hat-provided index image to your registry:

    $ oc image mirror \
        [-a ${REG_CREDS}] \
        quay.io/operator-framework/upstream-community-operators:latest \(1)
        <mirror_registry>:<port>/<namespace>/upstream-community-operators:latest (2)
    1 Specify the index image for catalog that you mirrored content for in the previous step.
    2 Specify where to mirror the index image.

You can now create a CatalogSource to reference your mirrored index image and Operator content.

Creating a catalog from an index image

You can create an Operator catalog from an index image and apply it to an OKD cluster for use with Operator Lifecycle Manager (OLM).

Prerequisites
  • An index image built and pushed to a registry.

Procedure
  1. Create a CatalogSource object that references your index image.

    1. Modify the following to your specifications and save it as a catalogsource.yaml file:

      apiVersion: operators.coreos.com/v1alpha1
      kind: CatalogSource
      metadata:
        name: my-operator-catalog
        namespace: openshift-marketplace
      spec:
        sourceType: grpc
        image: <mirror_registry>:<port>/<namespace>/upstream-community-operators:latest (1)
        displayName: My Operator Catalog
        publisher: <publisher_name> (2)
        updateStrategy:
          registryPoll: (3)
            interval: 30m
      1 Specify your index image.
      2 Specify your name or an organization name publishing the catalog.
      3 CatalogSources can automatically check for new versions to keep up to date.
    2. Use the file to create the CatalogSource object:

      $ oc create -f catalogsource.yaml
  2. Verify the following resources are created successfully.

    1. Check the Pods:

      $ oc get pods -n openshift-marketplace
      Example output
      NAME                                    READY   STATUS    RESTARTS  AGE
      my-operator-catalog-6njx6               1/1     Running   0         28s
      marketplace-operator-d9f549946-96sgr    1/1     Running   0         26h
    2. Check the CatalogSource:

      $ oc get catalogsource -n openshift-marketplace
      Example output
      NAME                  DISPLAY               TYPE PUBLISHER  AGE
      my-operator-catalog   My Operator Catalog   grpc            5s
    3. Check the PackageManifest:

      $ oc get packagemanifest -n openshift-marketplace
      Example output
      NAME                          CATALOG               AGE
      jaeger-product                My Operator Catalog   93s

You can now install the Operators from the OperatorHub page on your OKD web console.

Updating an index image

After configuring OperatorHub to use a CatalogSource that references a custom index image, cluster administrators can keep the available Operators on their cluster up to date by adding bundle images to the index image.

You can update an existing index image using the opm index add commad.

Prerequisites
  • opm version 1.12.3+

  • podman version 1.4.4+

  • An index image built and pushed to a registry.

  • An existing CatalogSource referencing the index image.

Procedure
  1. Update the existing index by adding bundle images:

    $ opm index add \
        --bundles <registry>/<namespace>/<new_bundle_image>:<tag> \(1)
        --from-index <registry>/<namespace>/<existing_index_image>:<tag> \(2)
        --tag <registry>/<namespace>/<existing_index_image>:<tag> (3)
    1 A comma-separated list of additional bundle images to add to the index.
    2 The existing index that was previously pushed.
    3 The image tag that you want the updated index image to have.
  2. Push the updated index image:

    $ podman push <registry>/<namespace>/<existing_index_image>:<tag>
  3. After Operator Lifecycle Manager (OLM) automatically polls the index image referenced in the CatalogSource at its regular interval, verify that the new packages are successfully added:

    $ oc get packagemanifests -n openshift-marketplace