Deploying onto OpenShift
This section is to help you verify that the operator deploys successfully from the metadata bundle onto OpenShift using the Operator Lifecycle Manager (OLM).

Before getting started

Creating an index image

You can create an index image using the opm CLI.
  1. 1.
    Start a new index:
    1
    $ opm index add \
    2
    --bundles quay.io/<namespace>/wordpress-operator:v0.0.1 \
    3
    --tag quay.io/<namespace>/wordpress-operator-index:latest
    Copied!
  2. 2.
    Push the index image to a registry:
    1
    $ podman push quay.io/<namespace>/wordpress-operator-index:latest
    Copied!
Be sure to make your quay.io repositories for the bundle image and the index image public. You can can change this in the settings in quay.io

Create the CatalogSource

  1. 1.
    In your OpenShift environment create a catalog source in the openshift-marketplace namespace.
test-operator-catalogsource.yaml
1
apiVersion: operators.coreos.com/v1alpha1
2
kind: CatalogSource
3
metadata:
4
name: my-test-operators
5
namespace: openshift-marketplace
6
spec:
7
sourceType: grpc
8
image: quay.io/<namespace>/wordpress-operator-index:latest
9
displayName: Test Operators
10
publisher: Red Hat Partner
11
updateStrategy:
12
registryPoll:
13
interval: 5m
Copied!
1
$ oc create -f test-operator-catalogsource.yaml
Copied!
2. You can verify the catalogsource has been created by running the following command:
1
$ oc -n openshift-marketplace get catalogsource
Copied!
You should see the following output:
1
NAME DISPLAY TYPE PUBLISHER AGE
2
certified-operators Certified Operators grpc Red Hat 12d
3
community-operators Community Operators grpc Red Hat 12d
4
my-test-operators Test Operators grpc Red Hat 30s
5
redhat-marketplace Red Hat Marketplace grpc Red Hat 12d
6
redhat-operators Red Hat Operators grpc Red Hat 12d
Copied!
3. Once you have confirmed the catalogsource exists, run the following command to verify it's associated pod is successfully running. This verifies that the index image has been successfully pulled down from the repository.
1
$ oc -n openshift-marketplace get pods
Copied!
You should see the following output:
1
NAME READY STATUS RESTARTS AGE
2
certified-operators-59b6bc7fbc-rzzwq 1/1 Running 0 12d
3
community-operators-5f89b4787d-ljvfb 1/1 Running 0 12d
4
marketplace-operator-5c84994668-927b6 1/1 Running 0 12d
5
my-test-operators-##########-##### 1/1 Running 0 12d
6
redhat-marketplace-86cc645bb6-8crdl 1/1 Running 0 12d
7
redhat-operators-5877478c4f-4ffs2 1/1 Running 0 12d
Copied!
4. Verify that the operator package has been successfully added:
1
$ oc get packagemanifests | grep “Test Operators”
Copied!

Create OperatorGroup

  1. 1.
    Create a namespace for your project
1
$ oc new-project test-operator
Copied!
2. Create the OperatorGroup
test-operatorgroup.yaml
1
apiVersion: operators.coreos.com/v1alpha2
2
kind: OperatorGroup
3
metadata:
4
name: my-group
5
namespace: test-operator
6
spec:
7
targetNamespaces:
8
- test-operator
Copied!
1
$ oc create -f test-operatorgroup.yaml
Copied!
3. Verify you have a working operatorgroup within the namespace you created:
1
$ oc get og
Copied!
You should see the following output:
1
NAMESPACE NAME AGE
2
test-operator my-group 30s
Copied!

Create a Subscription

test-subscription.yaml
1
apiVersion: operators.coreos.com/v1alpha1
2
kind: Subscription
3
metadata:
4
name: test-subscription
5
spec:
6
channel: alpha
7
installPlanApproval: Automatic
8
name: wordpress-operator
9
source: my-test-operators
10
sourceNamespace: openshift-marketplace
Copied!
1
$ oc create -f test-subscription.yaml
Copied!
Verify the subscription is created within your namespace:
1
$ oc get sub -n test-operator
Copied!
You should see the following output:
1
NAMESPACE NAME PACKAGE SOURCE CHANNEL
2
test-operator test-subscription wordpress-operator test-operators stable
Copied!
The creation of the subscription should trigger the creation of the InstallPlan and CSV.
1
$ oc get installplan -n test-operator
Copied!
1
$ oc get csv -n test-operator
Copied!
You should see something similar to this output:
1
NAMESPACE NAME DISPLAY VERSION REPLACES PHASE
2
test-operator wordpress-operator.v0.0.1 Wordpress Operator 0.0.1 Succeeded
Copied!
Verify your operator is running in the namespace:
1
$ oc get pods -n test-operator
Copied!

Updating an existing index image

You can update an existing index image with a new operator bundle version using the opm CLI.
  1. 1.
    Update the existing index:
    1
    $ opm index add \
    2
    --bundles quay.io/<namespace>/wordpress-operator:v0.0.2 \
    3
    --from-index quay.io/<namespace>/wordpress-operator-index:latest \
    4
    --tag quay.io/<namespace>/wordpress-operator-index:latest
    Copied!
  2. 2.
    Push the updated index image:
    1
    $ podman push quay.io/<namespace>/wordpress-operator-index:latest
    Copied!
  3. 3.
    After OLM polls the index image at its specified interval, we should eventually see a new installplan for our new operator bundle version
    1
    $ oc get installplan -n test-operator
    Copied!

Run the Scorecard test

The Operator Scorecard is a testing utility included in the operator-sdk binary that guides users towards operator best practices by checking the correctness of their operators and CSVs. With your operator deployed via OLM, you can run the operator-sdk scorecard utility to create a CR which will trigger the operator and monitor what occurs. In order to certify you must pass the first two Basic Tests: Spec Block Exists, and Status Block Exists. Passing the third basic test (Writing into CRs has an effect) requires adding the scorecard-proxy container to the operator deployment, which is not desired in a production operator and is therefore not required for certification.
In order to run scorecard locally against your operator deployed via OLM please refer to this section of the upstream documentation
Last modified 3mo ago