|
| 1 | +# Packaging for Operator Hub / Red Hat |
| 2 | + |
| 3 | +## Tools |
| 4 | +* `opm` |
| 5 | + 1. Checkout a copy of [operator-framework/operator-registry](https://github.com/operator-framework/operator-registry) |
| 6 | + 2. Build with `make build` |
| 7 | + 3. Binary resides at `bin/opm` |
| 8 | +* `k3d` |
| 9 | + |
| 10 | +### Setup Test Cluster |
| 11 | + |
| 12 | +Spin up local cluster for testing and install OLM |
| 13 | + |
| 14 | +```console |
| 15 | +k3d cluster create |
| 16 | +kubectl create namespace test-operator |
| 17 | +operator-sdk olm install |
| 18 | + |
| 19 | +# Optional |
| 20 | +kubectl delete catalogsource operatorhubio-catalog -n olm |
| 21 | +``` |
| 22 | + |
| 23 | +### Unsupported Resource Types |
| 24 | +The following types may not be included in the operator bundle |
| 25 | + |
| 26 | +1. Namespace |
| 27 | +2. Secret |
| 28 | +3. ValidatingWebhookConfiguration |
| 29 | +4. Service |
| 30 | + |
| 31 | +## Common Issues |
| 32 | +* `runAsUser` set to `999` in the deployment - OpenShift prefers to set a randomly assigned user at container start time. If this field is not left empty the user field must be set extremely high. 999 is too low. |
| 33 | +* Prerequisite custom resources have not been included in the appropriate section of the operator metadata testing page |
| 34 | +* The package has not been marked as published in the Red Hat repo. |
| 35 | + |
| 36 | +# Upgrade Workflow |
| 37 | + |
| 38 | +_Note see Red Hat's [Gitbook](https://redhat-connect.gitbook.io/partner-guide-for-red-hat-openshift-and-container/certify-your-operator/upgrading-your-operator)_ |
| 39 | + |
| 40 | +1. Copy an existing version as the base |
| 41 | + |
| 42 | + ```console |
| 43 | + OLD_VERSION=1.4.0 |
| 44 | + NEW_VERSION=1.4.1 |
| 45 | + cd operator/bundle |
| 46 | + cp -r $OLD_VERSION $NEW_VERSION |
| 47 | + cp bundle-$OLD_VERSION.Dockerfile bundle-$NEW_VERSION.Dockerfile |
| 48 | + ``` |
| 49 | +2. Rename files with version numbers |
| 50 | + |
| 51 | + ```console |
| 52 | + mv $NEW_VERSION/manifests/cass-operator.v$OLD_VERSION.clusterserviceversion.yaml $NEW_VERSION/manifests/cass-operator.v$NEW_VERSION.clusterserviceversion.yaml |
| 53 | + ``` |
| 54 | + |
| 55 | +3. Update version numbers in ClusterServiceVersion files |
| 56 | + |
| 57 | + ```console |
| 58 | + sed s/"$OLD_VERSION"/$NEW_VERSION/g $NEW_VERSION/cass-operator.v$NEW_VERSION.clusterserviceversion.yaml |
| 59 | + sed s/"$OLD_VERSION"/$NEW_VERSION/g bundle-$NEW_VERSION.Dockerfile |
| 60 | + ``` |
| 61 | + |
| 62 | +4. Copy in updated CRD |
| 63 | + |
| 64 | + ```console |
| 65 | + cp ../deploy/crds/* $NEW_VERSION/manifests/ |
| 66 | + ``` |
| 67 | + |
| 68 | +5. Compare the old and new CRDs for differences and update `$NEW_VERSION/manifests/cass-operator.v$NEW_VERSION.lusterserviceversion.yaml` |
| 69 | + 1. Update `metadata.annotations.containerImage` version |
| 70 | + 2. Update `metadata.annotations.createdAt` datestamp |
| 71 | + 3. Update `metadata.annotations.name` field |
| 72 | + 4. Update `spec.install.spec.deployments[0].template.spec.containers[0].image` version |
| 73 | + 5. Update `spec.customresourcedefinitions.owned[0].specDescriptors` to include any new spec fields. See [Descriptor](https://github.com/openshift/console/blob/master/frontend/packages/operator-lifecycle-manager/src/components/descriptors/reference/reference.md) [Documentation](https://github.com/openshift/console/tree/release-4.3/frontend/packages/operator-lifecycle-manager/src/components/descriptors). |
| 74 | + 6. Update `spec.customresourcedefinitions.owned[0].statusDescriptors` to include any new status fields |
| 75 | + 7. Update `spec.replaces` to replace previous version |
| 76 | + 8. Update `spec.version` with new version value |
| 77 | +6. Build bundle container and push to staging repo |
| 78 | + |
| 79 | + ```console |
| 80 | + docker build -t bradfordcp/cass-operator-bundle:$NEW_VERSION -f bundle-$NEW_VERSION.Dockerfile . |
| 81 | + docker push bradfordcp/cass-operator-bundle:NEW_VERSION |
| 82 | + ``` |
| 83 | +7. Build local catalog index for testing |
| 84 | + |
| 85 | + ```console |
| 86 | + opm index add --bundles bradfordcp/cass-operator-bundle:$NEW_VERSION --tag bradfordcp/catalog-index:latest -u docker |
| 87 | + docker push bradfordcp/catalog-index:latest |
| 88 | + ``` |
| 89 | +8. Add index as a [`CatalogSource`](olm/catalogsource.yaml) in k8s |
| 90 | + |
| 91 | + ```console |
| 92 | + kubectl apply -f docs/developer/olm/catalogsource.yaml |
| 93 | + ``` |
| 94 | +9. Verify packagemanifests are being pulled from index |
| 95 | + |
| 96 | + ```console |
| 97 | + kubectl describe packagemanifests cass-operator -n olm |
| 98 | + ``` |
| 99 | +10. Create an [`OperatorGroup`](olm/operatorgroup.yaml) to tell cass-operator where to watch for CassDC instances |
| 100 | + |
| 101 | + ```console |
| 102 | + kubectl apply -f docs/developer/olm/operatorgroup.yaml |
| 103 | + ``` |
| 104 | +11. Install prereqs that OLM doesn't handle |
| 105 | + |
| 106 | + ```console |
| 107 | + kubectl apply -f docs/developer/olm/prereqs.yaml |
| 108 | + ``` |
| 109 | +12. Install cass-operator with OLM via a [`Subscription`](olm/subscription.yaml) |
| 110 | + |
| 111 | + ```console |
| 112 | + kubectl apply -f docs/developer/olm/cass-operator.subscription.yaml |
| 113 | + ``` |
| 114 | +13. Check the `InstallPlan` to see the operator successfully installed |
| 115 | + |
| 116 | + ```console |
| 117 | + kubectl describe installplan -n test-operator | less |
| 118 | + ``` |
| 119 | + |
| 120 | + If there is a failure, fix the issue locally, remove the `Subscription` and `CatalogSource`. Goto step 6 and repackage everything. |
| 121 | +14. Check the operator is running |
| 122 | + |
| 123 | + ```console |
| 124 | + kubectl get pods -n test-operator |
| 125 | + ``` |
| 126 | +14. Provision a sample cassdc in the default namespace |
| 127 | +15. Push to Red Hat |
| 128 | + |
| 129 | + ```console |
| 130 | + docker tag bradfordcp/cass-operator-bundle:$NEW_VERSION $REDHAT_REGISTRY/cass-operator-bundle:$NEW_VERSION |
| 131 | + docker push $REDHAT_REGISTRY/cass-operator-bundle:$NEW_VERSION |
| 132 | + ``` |
| 133 | +16. Red Hat automatically runs certification tests on push. These take 1-2 hours |
| 134 | +17. Login to the Red Hat project and verify certification results. Repeat steps 5-7 until certification passes |
| 135 | +18. Publish certified bundle |
0 commit comments