OpenShift Operator Lifecycle Management Guide: Integrating Operators in OLM Part IV

8 minute read

38202270

Overview

In this article we will provide a hands-on guide to integrating your already built Operator with the Operator Lifecycle Manager (OLM). Using the Operator SDK and OPM tool we will create the application manifests and images so your application Operator can be managed through OLM.

This article is part of a series that will walk you through understanding and building operators in Go or Ansible end-to-end.

In order to add your Operator to OLM you will need two tools: the operator-sdk and opm. Download the binaries for operator-sdk and opm. Install them under /usr/local/bin.

Create Cluster Service Version

The Cluster Service Version (CSV) is the manifest that allows your application operator to be bundled and exposed to the OLM API. The CSV is itself a CRD in kubernetes. Before creating a the CSV manifest you need the deployment scafolding. These are the objects and CRDs that your Operator require. These are created automatically when using the operator-sdk to create a application under the deploy directory.

$ operator-sdk new cars-operator --repo github.com/cars-operator

When generating an CSV you will provide the path to the deploy directory where those objects can be found.

$ operator-sdk generate csv --csv-version 1.0.0 --deploy-dir deploy

The generate csv command will create an olm_catalog/cars-operator/manifests directory. There you will find the 'clusterserviceversion' yaml. You will however want to edit and add a lot. As such I have provided an example csv for an Operator I built.

Note: If you want to add an icon, so it shows up nicely in Operator Hub, the image needs to be a base64 bit stream inside the csv.

$ cat myimage.png | base64

Create Application Operator Catalog Bundle

Now that we have generated and updated our CSV we can create an application bundle.

$ sudo operator-sdk bundle create quay.io/ktenzer/podium-operator-catalog:latest \
--channels beta --package podium-operator-catalog --directory \
deploy/olm-catalog/podium-operator/manifests

This will package the application manifest into a container image. Push the image to a public or private repository.

$ sudo docker push quay.io/ktenzer/podium-operator-catalog:latest

Create Application Operator Catalog Index

Once we have bundled an application operator we can add it to a catalog index. The catalog index provides one or more application bundles to OLM. This is also what the Operator Hub directly interfaces with.

$ sudo opm index add -c docker --bundles \
quay.io/ktenzer/podium-operator-catalog:latest \
--tag quay.io/ktenzer/podium-operator-index:latest

Again an image is created that needs to be pushed to our private or public repository.

$ sudo docker push quay.io/ktenzer/podium-operator-index:latest

Deploy Catalog Source

A catalog source is a CRD that defines an OLM catalog and points to a catalog index image, for example the one we just created.

Create a catalog source yaml file that points to the catalog index image.

$ vi catalog_source.yaml
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
  name: podium-operator-catalog
spec:
  sourceType: grpc
  image: quay.io/ktenzer/podium-operator-index:latest
  displayName: Podium Operator Catalog
  publisher: Podium Community

Deploy the catalog source under the openshift-marketplace namespace or where you have deployed OLM.

$ oc create -f catalog_source.yaml -n openshift-marketplace

Below we can see a list of catalogs. Again each catalog can contain one or more applications. All are default in OpenShift, except the one in bold which I added.

$ oc get catalogsource -n openshift-marketplace
NAME                     DISPLAY                 TYPE PUBLISHER        AGE
certified-operators      Certified Operators     grpc Red Hat          18d
community-operators      Community Operators     grpc Red Hat          18d
podium-operator-catalog  Podium Operator Catalog grpc Podium Community 31m
redhat-operators         Red Hat Operators       grpc Red Hat          18d

Each catalog has it's own operator / pod.

$ oc get pods -n openshift-marketplace
NAME                                    READY   STATUS    RESTARTS   AGE
certified-operators-76d9d8b886-bnsz7    1/1     Running   0          14h
community-operators-74d675f545-g7d2t    1/1     Running   0          18h
podium-operator-catalog-67gsk           1/1     Running   0          31m
marketplace-operator-75f49679d7-n7v2r   1/1     Running   0          17d
redhat-operators-87d549bf4-mxf7w        1/1     Running   0          13h

Once a catalog operator exists, the applications it offers will show up in Operator Hub and can be installed.

podium_install

Operators can be cluster-wide or namespace scoped. The Operator Lifecycle Management also provides a subscription, allowing updates to be pulled from various channels. This is similar to the relationship between an RPM and Repository.

podium_install2

After you deploy application via Operator Hub it will launch the operator. Cluster-wide operators will run in the openshift-operators namespace while namespaced operators will only run in a user defined namespace.

$ oc get pods -n openshift-operators
NAME                               READY   STATUS    RESTARTS   AGE
podium-operator-6855dc9478-q65bt   1/1     Running   0          38m

Summary

In this article we stepped through the process of integrating an already existing operator with the Operator Lifecycle Manager. We saw how to generate an application manifest, build an application catalog bundle, add the bundle to an application index and finally deploy the application catalog, seamlessly integrating with Operator Hub. Using OLM provides not only a way to install applications but manage their lifecycle, releases and updates.

Happy Operatoring!

(c) 2020 Keith Tenzer