|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * operators/operator_sdk/osdk-working-bundle-images.adoc |
| 4 | + |
| 5 | +[id="osdk-publish-catalog_{context}"] |
| 6 | += Publishing a catalog containing a bundled Operator |
| 7 | + |
| 8 | +To install and manage Operators, Operator Lifecycle Manager (OLM) requires that Operator bundles are listed in an index image, which is referenced by a catalog on the cluster. As an Operator author, you can use the Operator SDK to create an index containing the bundle for your Operator and all of its dependencies. This is useful for testing on remote clusters and publishing to container registries. |
| 9 | + |
| 10 | +[NOTE] |
| 11 | +==== |
| 12 | +The Operator SDK uses the `opm` CLI to facilitate index image creation. Experience with the `opm` command is not required. For advanced use cases, the `opm` command can be used directly instead of the Operator SDK. |
| 13 | +==== |
| 14 | + |
| 15 | +.Prerequisites |
| 16 | + |
| 17 | +- Operator SDK CLI installed on a development workstation |
| 18 | +- Operator bundle image built and pushed to a registry |
| 19 | +- OLM installed on a Kubernetes-based cluster (v1.16.0 or later if you use `apiextensions.k8s.io/v1` CRDs, for example {product-title} {product-version}) |
| 20 | +- Logged in to the cluster with `oc` using an account with `cluster-admin` permissions |
| 21 | + |
| 22 | +.Procedure |
| 23 | + |
| 24 | +. Run the following `make` command in your Operator project directory to build an index image containing your Operator bundle: |
| 25 | ++ |
| 26 | +[source,terminal] |
| 27 | +---- |
| 28 | +$ make catalog-build CATALOG_IMG=<registry>/<user>/<index_image_name>:<tag> |
| 29 | +---- |
| 30 | ++ |
| 31 | +where the `CATALOG_IMG` argument references a repository that you have access to. You can obtain an account for storing containers at repository sites such as Quay.io. |
| 32 | + |
| 33 | +. Push the built index image to a repository: |
| 34 | ++ |
| 35 | +[source,terminal] |
| 36 | +---- |
| 37 | +$ make catalog-push CATALOG_IMG=<registry>/<user>/<index_image_name>:<tag> |
| 38 | +---- |
| 39 | ++ |
| 40 | +[TIP] |
| 41 | +==== |
| 42 | +You can use Operator SDK `make` commands together if you would rather perform multiple actions in sequence at once. For example, if you had not yet built a bundle image for your Operator project, you can build and push both a bundle image and an index image with the following syntax: |
| 43 | +
|
| 44 | +[source,terminal] |
| 45 | +---- |
| 46 | +$ make bundle-build bundle-push catalog-build catalog-push \ |
| 47 | + BUNDLE_IMG=<bundle_image_pull_spec> \ |
| 48 | + CATALOG_IMG=<index_image_pull_spec> |
| 49 | +---- |
| 50 | +
|
| 51 | +Alternatively, you can set the `IMAGE_TAG_BASE` field in your `Makefile` to an existing repository: |
| 52 | +
|
| 53 | +[source,terminal] |
| 54 | +---- |
| 55 | +IMAGE_TAG_BASE=quay.io/example/my-operator |
| 56 | +---- |
| 57 | +
|
| 58 | +You can then use the following syntax to build and push images with automatically-generated names, such as `quay.io/example/my-operator-bundle:v0.0.1` for the bundle image and `quay.io/example/my-operator-catalog:v0.0.1` for the index image: |
| 59 | +
|
| 60 | +[source,terminal] |
| 61 | +---- |
| 62 | +$ make bundle-build bundle-push catalog-build catalog-push |
| 63 | +---- |
| 64 | +==== |
| 65 | + |
| 66 | +. Define a `CatalogSource` object that references the index image you just generated, and then create the object by using the `oc apply` command or web console: |
| 67 | ++ |
| 68 | +.Example `CatalogSource` YAML |
| 69 | +[source,yaml] |
| 70 | +---- |
| 71 | +apiVersion: operators.coreos.com/v1alpha1 |
| 72 | +kind: CatalogSource |
| 73 | +metadata: |
| 74 | + name: cs-memcached |
| 75 | + namespace: default |
| 76 | +spec: |
| 77 | + displayName: My Test |
| 78 | + publisher: Company |
| 79 | + sourceType: grpc |
| 80 | + image: quay.io/example/memcached-catalog:v0.0.1 <1> |
| 81 | + updateStrategy: |
| 82 | + registryPoll: |
| 83 | + interval: 10m |
| 84 | +---- |
| 85 | +<1> Set `image` to the image pull spec you used previously with the `CATALOG_IMG` argument. |
| 86 | + |
| 87 | +. Check the catalog source: |
| 88 | ++ |
| 89 | +[source,terminal] |
| 90 | +---- |
| 91 | +$ oc get catalogsource |
| 92 | +---- |
| 93 | ++ |
| 94 | +.Example output |
| 95 | +[source,terminal] |
| 96 | +---- |
| 97 | +NAME DISPLAY TYPE PUBLISHER AGE |
| 98 | +cs-memcached My Test grpc Company 4h31m |
| 99 | +---- |
| 100 | + |
| 101 | +.Verification |
| 102 | + |
| 103 | +. Install the Operator using your catalog: |
| 104 | + |
| 105 | +.. Define an `OperatorGroup` object and create it by using the `oc apply` command or web console: |
| 106 | ++ |
| 107 | +.Example `OperatorGroup` YAML |
| 108 | +[source,yaml] |
| 109 | +---- |
| 110 | +apiVersion: operators.coreos.com/v1 |
| 111 | +kind: OperatorGroup |
| 112 | +metadata: |
| 113 | + name: my-test |
| 114 | + namespace: default |
| 115 | +spec: |
| 116 | + targetNamespaces: |
| 117 | + - default |
| 118 | +---- |
| 119 | + |
| 120 | +.. Define a `Subscription` object and create it by using the `oc apply` command or web console: |
| 121 | ++ |
| 122 | +.Example `Subscription` YAML |
| 123 | +[source,yaml] |
| 124 | +---- |
| 125 | +apiVersion: operators.coreos.com/v1alpha1 |
| 126 | +kind: Subscription |
| 127 | +metadata: |
| 128 | + name: catalogtest |
| 129 | + namespace: default |
| 130 | +spec: |
| 131 | + channel: "alpha" |
| 132 | + installPlanApproval: Manual |
| 133 | + name: catalog |
| 134 | + source: cs-memcached |
| 135 | + sourceNamespace: default |
| 136 | + startingCSV: memcached-operator.v0.0.1 |
| 137 | +---- |
| 138 | + |
| 139 | +. Verify the installed Operator is running: |
| 140 | + |
| 141 | +.. Check the Operator group: |
| 142 | ++ |
| 143 | +[source,terminal] |
| 144 | +---- |
| 145 | +$ oc get og |
| 146 | +---- |
| 147 | ++ |
| 148 | +.Example output |
| 149 | +[source,terminal] |
| 150 | +---- |
| 151 | +NAME AGE |
| 152 | +my-test 4h40m |
| 153 | +---- |
| 154 | + |
| 155 | +.. Check the cluster service version (CSV): |
| 156 | ++ |
| 157 | +[source,terminal] |
| 158 | +---- |
| 159 | +$ oc get csv |
| 160 | +---- |
| 161 | ++ |
| 162 | +.Example output |
| 163 | +[source,terminal] |
| 164 | +---- |
| 165 | +NAME DISPLAY VERSION REPLACES PHASE |
| 166 | +memcached-operator.v0.0.1 Test 0.0.1 Succeeded |
| 167 | +---- |
| 168 | + |
| 169 | +.. Check the pods for the Operator: |
| 170 | ++ |
| 171 | +[source,terminal] |
| 172 | +---- |
| 173 | +$ oc get pods |
| 174 | +---- |
| 175 | ++ |
| 176 | +.Example output |
| 177 | +[source,terminal] |
| 178 | +---- |
| 179 | +NAME READY STATUS RESTARTS AGE |
| 180 | +9098d908802769fbde8bd45255e69710a9f8420a8f3d814abe88b68f8ervdj6 0/1 Completed 0 4h33m |
| 181 | +catalog-controller-manager-7fd5b7b987-69s4n 2/2 Running 0 4h32m |
| 182 | +cs-memcached-7622r 1/1 Running 0 4h33m |
| 183 | +---- |
0 commit comments