Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Procedure to Publish Operator on OperatorHub #225

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 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:/k8s-operatorhub/community-operators),
you must be listed as an approver in our [operator CI configuration](https:/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,49 @@ 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:/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:/k8s-operatorhub/community-operators.git
```

4. Install the [crane](https:/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 git. 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 defaults to submitting pull requests to the k8s-operatorhub/community-operators catalog, but
other catalogs with the same format are supported.

The script accepts the following environment variables:

- `OPERATORHUB_DIR`: directory where the operator catalog repository was cloned.
- `VERSION`: version of the operator to submit for update. Do not include the leading `v` in the
version name.
- `HUB_REPO`: Regular expression to match for the operator catalog. Defaults to
`k8s-operatorhub\/community-operators` - be sure to escape special characters when overriding
this value.

Once the script completes and pushes the branch to your fork, open a pull request against the
[community operators](https:/k8s-operatorhub/community-operators) repository.

### Step 5 (optional): Update other operator catalogs

OperatorHub.io is not the only catalog that can be used to publish operators on Kubernetes
clusters. Community members can use the `release-operatorhub.sh` script to update any other catalog
that uses the OperatorHub file structure by providing appropriate environment variable overrides.

Maintainers are not required to submit updates to other operator catalogs.
61 changes: 61 additions & 0 deletions hack/release-operatorhub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/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 the operator catalog repository
# - The machine running this script has crane installed: https:/google/go-containerregistry/blob/main/cmd/crane/README.md

# Environment variables to tune the script's behavior
# - OPERATORHUB_DIR: The local path to the operator catalog repository.
# - VERSION: The version of the operator to release.
# - HUB_REPO: A regular expression to match the GitHub org/repository of the catalog. Note that this
# is a regular expression, so special characters need to be escaped.

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

echo "Preparing to release Shipwright Operator ${VERSION} to Operator catalog github.com/${HUB_REPO}"

if [[ ! -d "$OPERATORHUB_DIR" ]]; then
echo "Please clone the operator catalog repository 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 catalog repository"
exit 1
fi

upstreamURL=$(git remote get-url upstream)
if [[ ! "$upstreamURL" =~ ${hubRegEx} ]]; then
echo "Please set the upstream remote ${upstreamURL} to the operator catalog 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