Skip to content

Instantly share code, notes, and snippets.

@gallettilance
Last active November 8, 2019 15:39
Show Gist options
  • Save gallettilance/5f66026fc4486f71f90e9d841389f19e to your computer and use it in GitHub Desktop.
Save gallettilance/5f66026fc4486f71f90e9d841389f19e to your computer and use it in GitHub Desktop.

Testing operator registry

In the current state of 4.3, creating a catalogsource will create an operator registry pod using the old format. The new format is available through the use of the opm binary / command line utility that is not currently referenced when building an operator registry pod on an OCP cluster. Hence, we cannot test the new fields and formats that were added to the registry database on an OCP cluster. In order to test that the operator registry has been populated with the correct content, we need to do this testing locally.

Operator-Registry communicates usinng grpc. To test that the content is properly set we need to create a new operator registry service by using the opm command line tool locally and query the registry server using grpcurl.

Build Operator-Registry locally

Note: requires golang v1.12 or greater

git clone https://github.com/operator-framework/operator-registry

cd operator-registry

export GO111MODULE=on

go build -mod=vendor  -o bin/opm ./cmd/opm

Create one or more bundle images

This requires a given set of operator manifests for a specific version. For example:

bundles/prometheus.0.14.0/manifests
├── alertmanager.crd.yaml
├── prometheus.crd.yaml
├── prometheusoperator.0.14.0.clusterserviceversion.yaml
├── prometheusrule.crd.yaml
└── servicemonitor.crd.yaml

With the above set of manifests for prometheus version 0.14.0 we can build a bundle image.

./bin/opm alpha bundle build --directory bundles/prometheus.0.14.0/manifests --tag quay.io/${USERNAME}/prometheus-test:0.14.0 --package prometheus --channels preview --default preview

You can repeat this process with version 0.15.0 or other operators. Finally, push these to a container registry.

Adding Bundles to a database

Note: bundles.db can be an existing db file. If there the file cannot be found the command will create one.

./bin/opm registry add -d=bundles.db -b="quay.io/${USERNAME}/etcd-test:0.9.0,quay.io/${USERNAME}/prometheus-test:0.14.0,quay.io/${USERNAME}/prometheus-test:0.15.0,quay.io/${USERNAME}/prometheus-test:0.22.0"

Serving the database

./bin/opm registry serve -t=log.log -d=bundles.db

Querying for content

You can use grpcurl to query the content in the database exposed by the serve command above. For example to query bundle information for a specific operator:

grpcurl -plaintext -d '{"pkgName":"prometheus","channelName":"preview","csvName":"prometheusoperator.0.14.0"}' localhost:50051 api.Registry/GetBundle

This will return the bundle or bundlePath.

Create an Index image

Create a new index image

./bin/opm index add -b "quay.io/${USERNAME}/prometheus-test:0.14.0" -t "quay.io/${USERNAME}/testing-index:0.0.1"

Add to an existing index

./bin/opm index add -b "quay.io/${USERNAME}/prometheus-test:0.15.0,quay.io/${USERNAME}/prometheus-test:0.22.0" --from-index="quay.io/${USERNAME}/testing-index:0.0.1" -t "quay.io/${USERNAME}/testing-index:0.0.2"

The container serves the database so you will be able to repeat the above steps by interacting with the index container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment