Skip to content

Commit c23128e

Browse files
razvanadwk67
andauthored
Better OLM package generation (#61)
* fix: update build-bundles.sh to * Update olm/build-bundles.sh Co-authored-by: Andrew Kenworthy <andrew.kenworthy@stackable.de> * fix: replace tabs with spaces * fix: remove more tabs and run shellcheck * fix: bundle name and add startingCSV to subscription * fix: use global operator group without target namespace --------- Co-authored-by: Andrew Kenworthy <andrew.kenworthy@stackable.de>
1 parent 4f567ef commit c23128e

File tree

3 files changed

+475
-412
lines changed

3 files changed

+475
-412
lines changed

olm/build-bundles.sh

Lines changed: 169 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,74 @@
11
#!/usr/bin/env bash
2-
# Usage:
3-
# ./olm/build-bundles.sh -r <release as x.y.z> -b <branch-name>
2+
#
3+
# Description
4+
#
5+
# This scripts generates the OLM manifests required to install an operator from a custom catalog.
6+
# These are not required to install an operator from the OperatorHub.
7+
#
8+
# The images are published under docker.stackable.tech/sandbox since they are only needed during development.
9+
#
10+
# This script makes the following *assumptions*:
11+
#
12+
# - There is a clone of the openshift-certified-operators repository in the folder passed as -c argument.
13+
# This is the same as the build-manifests.sh script.
14+
#
15+
# - The operator manifests for the given version have been generated with the build-manifests.sh script
16+
# and are available in that repository under operators/<operator>/version/manifests.
17+
#
18+
# - If a deployment is also done (with -d) then the namespace called "stackable-operators" is available.
19+
#
20+
# Usage
21+
#
22+
# ./olm/build-bundles.sh [options]
23+
#
24+
# Options
25+
#
26+
# -c <location of the RH cert operators repo>
427
# -r <release>: the release number (mandatory). This must be a semver-compatible value to patch-level e.g. 23.1.0.
5-
# -b <branch>: the branch name (mandatory) in the (stackable forked) openshift-certified-operators repository.
6-
# -o <operator-name>: the operator name (mandatory) e.g. airflow-operator.
7-
# -d <deploy>: optional flag for catalog deployment.
28+
# -o <operator-name>: the operator name (mandatory) e.g. airflow. Without the "-operator" suffix!
29+
# -d <deploy>: optional flag for operator deployment.
30+
#
31+
# Example
32+
#
33+
# ./olm/build-bundles.sh \
34+
# -r 23.4.1 \
35+
# -o secret \
36+
# -c $HOME/repo/stackable/openshift-certified-operators \
37+
# -d
838
#
9-
# e.g. ./olm/build-bundles.sh -r 23.4.1 -b secret-23.4.1 -o secret-operator -d
1039

1140
set -euo pipefail
1241
set -x
1342

14-
15-
SCRIPT_NAME=$(basename $0)
43+
SCRIPT_NAME=$(basename "$0")
1644

1745
parse_inputs() {
18-
INITIAL_DIR="$PWD"
19-
20-
VERSION=""
21-
BRANCH=""
22-
OPERATOR_NAME=""
23-
DEPLOY=false
24-
25-
while [[ "$#" -gt 0 ]]; do
26-
case $1 in
27-
-r|--release) VERSION="$2"; shift ;;
28-
-b|--branch) BRANCH="$2"; shift ;;
29-
-o|--operator) OPERATOR_NAME="$2"; shift ;;
30-
-d|--deploy) DEPLOY=true ;;
31-
*) echo "Unknown parameter passed: $1"; exit 1 ;;
32-
esac
33-
shift
34-
done
35-
36-
# e.g. "airflow" , "spark-k8s"
37-
OPERATOR=$(basename "${OPERATOR_NAME}" | rev | cut -d- -f2- | rev)
46+
VERSION=""
47+
OPERATOR=""
48+
DEPLOY=false
49+
50+
while [[ "$#" -gt 0 ]]; do
51+
case $1 in
52+
-r | --release)
53+
VERSION="$2"
54+
shift
55+
;;
56+
-c)
57+
OPENSHIFT_ROOT="$2"
58+
shift
59+
;;
60+
-o | --operator)
61+
OPERATOR="$2"
62+
shift
63+
;;
64+
-d | --deploy) DEPLOY=true ;;
65+
*)
66+
echo "Unknown parameter passed: $1"
67+
exit 1
68+
;;
69+
esac
70+
shift
71+
done
3872
}
3973

4074
bundle-clean() {
@@ -43,107 +77,129 @@ bundle-clean() {
4377
}
4478

4579
build-bundle() {
46-
opm alpha bundle generate --directory manifests --package "${OPERATOR_NAME}-package" --output-dir bundle --channels stable --default stable
47-
cp metadata/*.yaml bundle/metadata/
48-
docker build -t "docker.stackable.tech/stackable/${OPERATOR_NAME}-bundle:${VERSION}" -f bundle.Dockerfile .
49-
docker push "docker.stackable.tech/stackable/${OPERATOR_NAME}-bundle:${VERSION}"
50-
opm alpha bundle validate --tag "docker.stackable.tech/stackable/${OPERATOR_NAME}-bundle:${VERSION}" --image-builder docker
80+
opm alpha bundle generate --directory manifests --package "${OPERATOR}-package" --output-dir bundle --channels stable --default stable
81+
cp metadata/*.yaml bundle/metadata/
82+
docker build -t "docker.stackable.tech/sandbox/${OPERATOR}-bundle:${VERSION}" -f bundle.Dockerfile .
83+
docker push "docker.stackable.tech/sandbox/${OPERATOR}-bundle:${VERSION}"
84+
opm alpha bundle validate --tag "docker.stackable.tech/sandbox/${OPERATOR}-bundle:${VERSION}" --image-builder docker
85+
86+
echo "Bundle built successfully!"
5187
}
5288

53-
setup() {
54-
if [ -d "catalog" ]; then
55-
rm -rf catalog
56-
fi
89+
catalog-clean() {
90+
if [ -d "catalog" ]; then
91+
rm -rf catalog
92+
fi
5793

58-
mkdir -p catalog
59-
rm -f catalog.Dockerfile
60-
rm -f catalog-source.yaml
94+
rm -f catalog.Dockerfile
95+
rm -f catalog-source.yaml
96+
rm -f subscription.yaml
97+
rm -f operator-group.yaml
6198
}
6299

63100
catalog() {
64-
opm generate dockerfile catalog
65-
66-
echo "Initiating package: ${OPERATOR}"
67-
opm init "stackable-${OPERATOR}-operator" \
68-
--default-channel=stable \
69-
--description=./README.md \
70-
--output yaml > "catalog/stackable-${OPERATOR}-operator.yaml"
71-
echo "Add operator to package: ${OPERATOR}"
72-
{
73-
echo "---"
74-
echo "schema: olm.channel"
75-
echo "package: stackable-${OPERATOR}-operator"
76-
echo "name: stable"
77-
echo "entries:"
78-
echo "- name: ${OPERATOR}-operator.v${VERSION}"
79-
} >> "catalog/stackable-${OPERATOR}-operator.yaml"
80-
echo "Render operator: ${OPERATOR}"
81-
opm render "docker.stackable.tech/stackable/${OPERATOR}-operator-bundle:${VERSION}" --output=yaml >> "catalog/stackable-${OPERATOR}-operator.yaml"
82-
83-
echo "Validating catalog..."
84-
opm validate catalog
85-
86-
echo "Build and push catalog for all ${OPERATOR} operator..."
87-
docker build . -f catalog.Dockerfile -t "docker.stackable.tech/stackable/stackable-${OPERATOR}-catalog:${VERSION}"
88-
docker push "docker.stackable.tech/stackable/stackable-${OPERATOR}-catalog:${VERSION}"
101+
mkdir -p catalog
102+
103+
opm generate dockerfile catalog
104+
105+
echo "Initiating package: ${OPERATOR}"
106+
opm init "stackable-${OPERATOR}-operator" \
107+
--default-channel=stable \
108+
--output yaml >"catalog/stackable-${OPERATOR}-operator.yaml"
109+
##--description="TODO: add description here" \
110+
111+
echo "Add operator to package: ${OPERATOR}"
112+
{
113+
echo "---"
114+
echo "schema: olm.channel"
115+
echo "package: stackable-${OPERATOR}-operator"
116+
echo "name: stable"
117+
echo "entries:"
118+
echo "- name: ${OPERATOR}-operator.v${VERSION}"
119+
} >>"catalog/stackable-${OPERATOR}-operator.yaml"
120+
echo "Render operator: ${OPERATOR}"
121+
opm render "docker.stackable.tech/sandbox/${OPERATOR}-bundle:${VERSION}" --output=yaml >>"catalog/stackable-${OPERATOR}-operator.yaml"
122+
123+
echo "Validating catalog..."
124+
opm validate catalog
125+
126+
echo "Build and push catalog for all ${OPERATOR} operator..."
127+
docker build . -f catalog.Dockerfile -t "docker.stackable.tech/sandbox/stackable-${OPERATOR}-catalog:${VERSION}"
128+
docker push "docker.stackable.tech/sandbox/stackable-${OPERATOR}-catalog:${VERSION}"
129+
130+
echo "Generating catalog source..."
131+
{
132+
echo "---"
133+
echo "apiVersion: operators.coreos.com/v1alpha1"
134+
echo "kind: CatalogSource"
135+
echo "metadata:"
136+
echo " name: stackable-${OPERATOR}-catalog"
137+
echo "spec:"
138+
echo " sourceType: grpc"
139+
echo " image: docker.stackable.tech/sandbox/stackable-${OPERATOR}-catalog:${VERSION}"
140+
echo " displayName: Stackable Catalog"
141+
echo " publisher: Stackable GmbH"
142+
echo " updateStrategy:"
143+
echo " registryPoll:"
144+
echo " interval: 10m"
145+
} >catalog-source.yaml
146+
147+
echo "Generating subscription ..."
148+
{
149+
echo "---"
150+
echo "apiVersion: operators.coreos.com/v1alpha1"
151+
echo "kind: Subscription"
152+
echo "metadata:"
153+
echo " name: stackable-${OPERATOR}-subscription"
154+
echo "spec:"
155+
echo " channel: stable"
156+
echo " name: stackable-${OPERATOR}-operator" # this is the package name NOT the operator-name
157+
echo " source: stackable-${OPERATOR}-catalog"
158+
echo " sourceNamespace: stackable-operators"
159+
echo " startingCSV: ${OPERATOR}-operator.v${VERSION}"
160+
} >subscription.yaml
161+
162+
echo "Generating operator group ..."
163+
{
164+
echo "---"
165+
echo "apiVersion: operators.coreos.com/v1"
166+
echo "kind: OperatorGroup"
167+
echo "metadata:"
168+
echo " name: stackable-operator-group"
169+
} >operator-group.yaml
170+
171+
echo "Catalog, operator group and subscription built (but not deployed) successfully!"
89172
}
90173

91174
deploy() {
92-
if $DEPLOY; then
93-
echo "Deploying catalog..."
94-
95-
{
96-
echo "---"
97-
echo "apiVersion: operators.coreos.com/v1alpha1"
98-
echo "kind: CatalogSource"
99-
echo "metadata:"
100-
echo " name: stackable-${OPERATOR}-catalog"
101-
echo " namespace: stackable-operators"
102-
echo "spec:"
103-
echo " sourceType: grpc"
104-
echo " image: docker.stackable.tech/stackable/stackable-${OPERATOR}-catalog:${VERSION}"
105-
echo " displayName: Stackable Catalog"
106-
echo " publisher: Stackable GmbH"
107-
echo " updateStrategy:"
108-
echo " registryPoll:"
109-
echo " interval: 10m"
110-
} >> catalog-source.yaml
111-
112-
kubectl apply -f catalog-source.yaml
113-
echo "Catalog deployment successful!"
114-
fi
175+
if $DEPLOY; then
176+
kubectl apply --namespace stackable-operators -f catalog-source.yaml
177+
kubectl apply --namespace stackable-operators -f subscription.yaml
178+
kubectl apply --namespace stackable-operators -f operator-group.yaml
179+
echo "Operator deployment done!"
180+
else
181+
echo "Skip operator deployment!"
182+
fi
115183
}
116184

117185
main() {
118-
parse_inputs "$@"
119-
if [ -z "${VERSION}" ] || [ -z "${BRANCH}" ] || [ -z "${OPERATOR_NAME}" ]; then
120-
echo "Usage: $SCRIPT_NAME -r <release> -b <branch> -o <operator>"
121-
exit 1
122-
fi
123-
124-
TMPFOLDER=$(mktemp -d -t 'openshift-bundles-XXXXXXXX')
125-
cd "${TMPFOLDER}"
126-
127-
git clone "git@github.com:stackabletech/openshift-certified-operators.git" --depth 1 --branch "${BRANCH}" --single-branch "${TMPFOLDER}/openshift-certified-operators/"
128-
129-
cd "${TMPFOLDER}/openshift-certified-operators/operators/stackable-${OPERATOR}-operator/${VERSION}"
130-
131-
# clean up any residual files from previous actions
132-
bundle-clean
133-
build-bundle
186+
parse_inputs "$@"
187+
if [ -z "${VERSION}" ] || [ -z "${OPENSHIFT_ROOT}" ] || [ -z "${OPERATOR}" ]; then
188+
echo "Usage: $SCRIPT_NAME -r <release> -o <operator> -c <path-to-openshift-repo>"
189+
exit 1
190+
fi
134191

135-
# should not be pushed to repo (unintentionally) once bundle is built, so clean up straight away
136-
bundle-clean
192+
# this is the same folder that is also used by build-manifests.sh
193+
cd "${OPENSHIFT_ROOT}/operators/stackable-${OPERATOR}-operator/${VERSION}"
137194

138-
echo "Bundle-build successful!"
195+
# clean up any residual files from previous actions
196+
bundle-clean
197+
build-bundle
139198

140-
pushd "$INITIAL_DIR/olm"
141-
setup
142-
catalog
143-
deploy
199+
catalog-clean
200+
catalog
144201

145-
popd
146-
echo "Catalog built successfully!"
202+
deploy
147203
}
148204

149205
main "$@"

0 commit comments

Comments
 (0)