Skip to content

Commit

Permalink
doc: Procedure to Publish Operator on OperatorHub
Browse files Browse the repository at this point in the history
Add a procedure and script to publish an operator release to the
upstream k8s community operators OperatorHub. The script requires the
user to fork the upstream k8s operators repsository and afterwards
submit a pull request by hand.

In the future this procedure/script can be added to our release
automation so when an operator release is published, we initiate the
process to update the upstream OperatorHub catalog.

Signed-off-by: Adam Kaplan <[email protected]>
  • Loading branch information
adambkaplan committed Jul 8, 2024
1 parent ebc4b09 commit 70d8acb
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/development/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This document outlines the steps required to release the operator. This document
have achieved the "Approver"/"Maintainer" status, and have permission to manually trigger GitHub
Actions on this repo.

To release operator updates to the [k8s community operators](https://github.com/k8s-operatorhub/community-operators),
you must be listed as an approver in our [operator CI configuration](https://github.com/k8s-operatorhub/community-operators/blob/main/operators/shipwright-operator/ci.yaml)
or request approval from a listed GitHub user.

## Release Candidates (`X.Y.0-rcN`)

### Step 0: Set Up the Release Branch
Expand Down Expand Up @@ -78,3 +82,36 @@ Work with the community to get these pull requests merged.
Repeat the process in [Step 1](#step-1-create-a-release-candidate) and
[Step 2](#step-2-publish-draft-release) above to create the release. For an official release, the
version should adhere to the `X.Y.Z` format (not extra dashes).

### Step 3 (if needed): Set up your machine to run the OperatorHub release script

The OperatorHub release script requires the following:

1. Fork the [k8s community-operators](https://github.com/k8s-operatorhub/community-operators)
repository.
2. Clone your fork with the `origin` remote name. Be sure to set your name and email in your local
`git` configuration.
3. Add the community operators repository as the `upstream` remote:

```sh
$ git remote add upstream https://github.com/k8s-operatorhub/community-operators.git
```

4. Install the [crane](https://github.com/google/go-containerregistry/blob/main/cmd/crane/README.md)
tool locally.

### Step 4: Update the Operator on OperatorHub.io

[OperatorHub.io](https://operatorhub.io) publishes a catalog of operators sourced from the
community operators repository. To add a new operator version, we must submit a pull request
to the appropriate Git repository.

Run the script `./hack/release-operatorhub.sh` to create a new release branch in your fork.
The script accepts the following environment variables:

- `OPERATORHUB_DIR`: directory where the community operators repository was cloned.
- `VERSION`: version of the operator to submit for update. Do not include the leading `v` in the
version name.

Once the script completes and pushes the branch to your fork, open a pull request against the
[community operators](https://github.com/k8s-operatorhub/community-operators) repository.
54 changes: 54 additions & 0 deletions hack/release-operatorhub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

set -eu -o pipefail

# This script generates a pull request to add the release to operatorhub.io
# Prerequisites:
# - The user has cloned and forked https://github.com/k8s-operatorhub/community-operators
# - The machine running this script has crane installed: https://github.com/google/go-containerregistry/blob/main/cmd/crane/README.md

OPERATORHUB_DIR=${OPERATORHUB_DIR:-$HOME/go/src/github.com/k8s-operatorhub/community-operators}
VERSION=${VERSION:-latest}
# Regular expression match [https://github.com/|[email protected]:]
hubRegEx="(https:\/\/github\.com\/|git@github\.com:)k8s-operatorhub"

echo "Preparing to release Shipwright Operator ${VERSION} to OperatorHub"

if [[ ! -d "$OPERATORHUB_DIR" ]]; then
echo "Please clone the community-operators repository to $OPERATORHUB_DIR"
exit 1
fi

pushd "$OPERATORHUB_DIR"

originURL=$(git remote get-url origin)
if [[ "$originURL" =~ ${hubRegEx} ]]; then
echo "Please set the origin remote to your fork of the operator hub repository"
exit 1
fi

upstreamURL=$(git remote get-url upstream)
if [[ ! "$upstreamURL" =~ ${hubRegEx} ]]; then
echo "Please set the upstream remote ${upstreamURL} to the operator hub repository"
exit 1
fi

git fetch
git switch main
git pull upstream main
git checkout -b "shipwright-${VERSION}"

mkdir -p "operators/shipwright-operator/${VERSION}"
pushd "operators/shipwright-operator/${VERSION}"

crane export "ghcr.io/shipwright-io/operator/operator-bundle:v${VERSION}" - | tar -xv

popd

# Commit and push changes to our GitHub fork
git add "operators/shipwright-operator/${VERSION}"
git commit -m "Update Shipwright Operator to ${VERSION}"
git commit --amend --no-edit -s
git push --set-upstream origin "shipwright-${VERSION}"

popd

0 comments on commit 70d8acb

Please sign in to comment.