Where is your change? | You changed | To test your changes |
---|---|---|
./roles |
Playbook content | Build and push a new mig-operator image |
./deploy/non-olm |
OpenShift 3 manifests | Apply updated manifests directly |
./deploy/olm-catalog |
OpenShift 4 metadata | Build and push a new OperatorHub metadata, update OperatorSource |
Note: if you build a new mig-operator image, you must reference it in ./deploy/non-olm/[...]
and ./deploy/olm-catalog/[...]
.
- Pull the latest
operator-sdk
base image before building.
docker pull quay.io/operator-framework/ansible-operator:latest
- Set quay org and tag
export ORG=your-quay-org
export TAG=latest
- Run the build from the root of the mig-operator repo:
docker build -f build/Dockerfile -t quay.io/$ORG/mig-operator-container:$TAG .
docker push quay.io/$ORG/mig-operator-container:$TAG
-
Update the deploy manifest in
./deploy/non-olm
# from ./deploy/non-olm/latest/operator.yml [...] containers: - name: operator image: quay.io/$ORG/mig-operator-container:$TAG
-
Apply the updated manifest to your cluster
oc apply -f ./deploy/non-olm/latest/operator.yml
-
Update the ClusterServiceVersion in
./deploy/olm-catalog
# from ./deploy/olm-catalog/[...]/crane-operator.v99.0.0.clusterserviceversion.yaml [...] containers: - name: operator image: quay.io/$ORG/mig-operator-container:$TAG
-
Follow steps to push operator metadata
-
Follow steps to install mig-operator after pushing metadata
The tooling and steps for pushing metadata depend on the OpenShift version.
OpenShift Versions | Operator Metadata Tooling |
---|---|
4.5+ | opm |
4.1 - 4.5 | operator-courier |
3.x | n/a |
- Install
opm
from operator-registry
-
Set quay org and image tag
export ORG=your-quay-org export TAG=latest
-
Build and push the bundle image
docker build -f build/Dockerfile.bundle -t quay.io/$ORG/mig-operator-bundle:$TAG . docker push quay.io/$ORG/mig-operator-bundle:$TAG
Note: visit quay.io and make
mig-operator-bundle
public before continuing -
Build and push the index image
opm index add --container-tool docker --bundles quay.io/$ORG/mig-operator-bundle:$TAG --tag quay.io/$ORG/mig-operator-index:$TAG docker push quay.io/$ORG/mig-operator-index:$TAG
Note: visit quay.io and make
mig-operator-index
public before continuing -
Create a new CatalogSource referencing the index image
cat << EOF > catalogsource.yml apiVersion: operators.coreos.com/v1alpha1 kind: CatalogSource metadata: name: migration-operator namespace: openshift-marketplace spec: sourceType: grpc image: quay.io/$ORG/mig-operator-index:$TAG EOF oc create -f catalogsource.yml
Note: CatalogSources will not pull updated images. operator-framework/operator-lifecycle-manager#903
As a workaround, use the commands below to modify your CatalogSource with the latest index image SHA
export BUNDLEDIGEST=$(docker pull quay.io/$ORG/mig-operator-index:latest | grep Digest | awk '{ print $2 }') sed "s/:latest/@$BUNDLEDIGEST/" catalogsource.yml | oc create -f -
-
Install
opm
from operator-registry -
Install
operator-courier
dnf -y install python3-operator-courier
-
Set the
QUAY_TOKEN
basic auth token- To interact with the quay API using operator courier you will need to obtain a basic auth token. The example script below can be used to retrieve a token and then to more easily follow examples here it is suggested you export it in your .bashrc or somewhere else that makes sense for you,
export QUAY_TOKEN="basic ..."
.
export QUAY_USERNAME export QUAY_PASSWORD echo $(curl -sH "Content-Type: application/json" -XPOST https://quay.io/cnr/api/v1/users/login -d ' { "user": { "username": "'"${QUAY_USERNAME}"'", "password": "'"${QUAY_PASSWORD}"'" } }')
- To interact with the quay API using operator courier you will need to obtain a basic auth token. The example script below can be used to retrieve a token and then to more easily follow examples here it is suggested you export it in your .bashrc or somewhere else that makes sense for you,
-
Set quay org and tag
export ORG=your-quay-org export TAG=latest
-
Follow steps 1-3 from build bundle and index images to build an index image.
-
Use
opm
to export metadata from your index image in appregistry formatopm index export --container-tool docker -i quay.io/$ORG/mig-operator-index:$TAG mtc-operator
Note: This will produce a directory called
downloaded
with appregistry format metadata. -
Use
operator-courier
to push updated metadata, making sure to increment the versionoperator-courier --verbose push downloaded/mtc-operator $ORG mtc-operator 2.0.0 "$QUAY_TOKEN"
Note: visit quay.io and make the app
$ORG/mtc-operator
public before continuing -
Create a new OperatorSource referencing the pushed metadata
cat << EOF > mig-operator-source.yaml apiVersion: operators.coreos.com/v1 kind: OperatorSource metadata: name: migration-operator namespace: openshift-marketplace spec: type: appregistry endpoint: https://quay.io/cnr registryNamespace: $ORG displayName: "Migration Operator" publisher: "[email protected]" EOF oc create -f mig-operator-source.yaml
If you are working on an operator such as crane, that exists in community-operators or elsewhere you may see duplicate operators in the UI. It can be difficult to discern which copy comes from which source. To alleviate this problem you may disable the default operator sources.
oc patch OperatorHub cluster --type json -p '[{"op": "add", "path": "/spec/disableAllDefaultSources", "value": true}]'
To reverse this change simply update the value again.
oc patch OperatorHub cluster --type json -p '[{"op": "add", "path": "/spec/disableAllDefaultSources", "value": false}]'
Before creating a subscription from the CLI, you must create an OperatorGroup.
cat << EOF > operatorgroup.yml
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
namespace: openshift-migration
generateName: openshift-migration-
spec:
targetNamespaces:
- openshift-migration
EOF
oc create -f operatorgroup.yml
You may Subscribe to an Operator via OperatorHub or from the CLI.
To Subscribe to an Operator from the CLI:
- Ensure the namespace exists,
- Select an update channel
- Write a subscription.yml, and create the resource.
oc create namespace openshift-migration ||:
export CHANNEL=latest
cat << EOF > subscription.yml
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: crane-operator
namespace: openshift-migration
spec:
channel: $CHANNEL
installPlanApproval: Automatic
name: crane-operator
source: migration-operator
sourceNamespace: openshift-marketplace
EOF
oc create -f subscription.yml
If you have made a change, deployed the operator, spotted an error and need to test another update:
-
Update operator playbook and metadata
- Make changes to playbook contents
- Build and push updated mig-operator image
- Make changes to operator metadata
- Build and push updated operator metadata
-
Clean up
- Delete the Operator Subscription
oc delete -f subscription.yml
- Delete the OperatorSource
oc delete -f mig-operator-source.yaml
- Delete the Operator Subscription
-
Re-deploy
- Recreate the OperatorSource
oc create -f mig-operator-source.yaml
- Recreate the Operator Subscription
oc create -f subscription.yml
- Recreate the OperatorSource