Skip to content

Commit 3fb53e2

Browse files
razvanadwk67
andauthored
Generate OLM manifests (#54)
* Add build-manifests.sh * Generate metadata and CSV skeleton. * FIx metadata generation. * Add help and CLI args * Fix cli args * Update todo * Add SCCs to cluster roles. * Don't generate csv anymore and fix annotation indentation. * Added script to clean up after OLM * Update olm/build-manifests.sh Co-authored-by: Andrew Kenworthy <andrew.kenworthy@stackable.de> * Update olm/build-manifests.sh Co-authored-by: Andrew Kenworthy <andrew.kenworthy@stackable.de> * Clarify manual changes. * Update supported OS version range --------- Co-authored-by: Andrew Kenworthy <andrew.kenworthy@stackable.de>
1 parent c5fcae2 commit 3fb53e2

File tree

2 files changed

+178
-0
lines changed

2 files changed

+178
-0
lines changed

olm/build-manifests.sh

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Helper script to (re)generate OLM package manifests (skeletons).
4+
#
5+
# Usage:
6+
#
7+
# ./olm/build-manifests.sh -r <release as x.y.z> -c <location of the RH cert operators repo> -o <location of the operator repo>
8+
#
9+
# Example:
10+
#
11+
# ./olm/build-manifests.sh -r 23.11.0 -c $HOME/repo/stackable/openshift-certified-operators -o $HOME/repo/stackable/zookeeper-operator
12+
#
13+
# Before running the script:
14+
# * Update the supported OpenShift version range in the `generate_metadata()` function.
15+
#
16+
# The generated manifests need to be updated manually with the following steps:
17+
# * Copy the cluster service version file from the previous package version.
18+
# * Replace the contents of the deployment, and cluster role with the `spec` and `rules` from the newly generated files.
19+
# * Remove the unused generated files : service account, operator cluster role (not the product cluster role), role binding, deployment.
20+
# * Remove all Helm labels in all remaining files.
21+
# * Check or update the metadata/dependencies.yaml
22+
# * Update image tags and hashes
23+
24+
set -euo pipefail
25+
set -x
26+
27+
# CLI args
28+
OPENSHIFT_ROOT=""
29+
OP_ROOT=""
30+
RELEASE_VERSION=""
31+
32+
# derived from CLI args
33+
PRODUCT=""
34+
OPERATOR=""
35+
MANIFESTS_DIR=""
36+
METADATA_DIR=""
37+
38+
generate_metadata() {
39+
40+
# generate metadata
41+
rm -r -f "$METADATA_DIR"
42+
mkdir -p "$METADATA_DIR"
43+
44+
pushd "$METADATA_DIR"
45+
46+
cat >annotations.yaml <<-ANNOS
47+
---
48+
annotations:
49+
operators.operatorframework.io.bundle.channel.default.v1: stable
50+
operators.operatorframework.io.bundle.channels.v1: stable
51+
operators.operatorframework.io.bundle.manifests.v1: manifests/
52+
operators.operatorframework.io.bundle.mediatype.v1: registry+v1
53+
operators.operatorframework.io.bundle.metadata.v1: metadata/
54+
operators.operatorframework.io.bundle.package.v1: stackable-${OPERATOR}
55+
56+
com.redhat.openshift.versions: v4.10-v4.13
57+
ANNOS
58+
59+
cat >dependencies.yaml <<-DEPS
60+
---
61+
dependencies:
62+
- type: olm.package
63+
value:
64+
packageName: stackable-commons-operator
65+
version: "$RELEASE_VERSION"
66+
- type: olm.package
67+
value:
68+
packageName: stackable-secret-operator
69+
version: "$RELEASE_VERSION"
70+
DEPS
71+
72+
popd
73+
}
74+
75+
generate_manifests() {
76+
# generate manifests
77+
rm -r -f "$MANIFESTS_DIR"
78+
mkdir -p "$MANIFESTS_DIR"
79+
80+
pushd "$MANIFESTS_DIR"
81+
82+
# split crd
83+
cat "$OP_ROOT/deploy/helm/$OPERATOR/crds/crds.yaml" | yq -s '.spec.names.kind'
84+
85+
# expand config map, roles, service account, etc.
86+
helm template "$OPERATOR" "$OP_ROOT/deploy/helm/$OPERATOR" | yq -s '.metadata.name'
87+
88+
popd
89+
}
90+
91+
parse_inputs() {
92+
while [[ "$#" -gt 0 ]]; do
93+
case $1 in
94+
-r)
95+
RELEASE_VERSION="$2"
96+
shift
97+
;;
98+
-o)
99+
OP_ROOT="$2"
100+
shift
101+
;;
102+
-c)
103+
OPENSHIFT_ROOT="$2"
104+
shift
105+
;;
106+
*)
107+
echo "Unknown parameter passed: $1"
108+
exit 1
109+
;;
110+
esac
111+
shift
112+
done
113+
114+
# e.g. "airflow" instead of "airflow-operator"
115+
PRODUCT=$(basename "${OP_ROOT}" | cut -d- -f1)
116+
117+
OPERATOR="$PRODUCT-operator"
118+
MANIFESTS_DIR="$OPENSHIFT_ROOT/operators/stackable-$OPERATOR/$RELEASE_VERSION/manifests"
119+
METADATA_DIR="$OPENSHIFT_ROOT/operators/stackable-$OPERATOR/$RELEASE_VERSION/metadata"
120+
}
121+
122+
maybe_print_help() {
123+
SCRIPT_NAME=$(basename $0)
124+
if [ -z "$RELEASE_VERSION" ] || [ -z "$OP_ROOT" ] || [ -z "$OPENSHIFT_ROOT" ]; then
125+
cat <<-HELP
126+
(Re)generate OLM manifest skeletons.
127+
128+
Usage:
129+
130+
$SCRIPT_NAME -r <release> -c <dir-to-rh-cert-op-repo> -o <dir-to-op-repo>
131+
132+
Options:
133+
-r : Release version
134+
-c : Path to the RH certified operator repository
135+
-o : Path to the Stackable operator repository
136+
137+
Example:
138+
139+
$SCRIPT_NAME -r 23.11.0 -c $HOME/repo/stackable/openshift-certified-operators -o $HOME/repo/stackable/zookeeper-operator
140+
HELP
141+
142+
exit 1
143+
fi
144+
}
145+
146+
patch_cluster_roles() {
147+
pushd "$MANIFESTS_DIR"
148+
149+
# Add product SCC to product cluster role
150+
if [ -f "$PRODUCT-clusterrole.yml" ]; then
151+
yq -i '.rules += { "apiGroups": [ "security.openshift.io" ], "resources": [ "securitycontextconstraints" ], "resourceNames": ["stackable-products-scc" ], "verbs": ["use"]}' "$PRODUCT-clusterrole.yml"
152+
fi
153+
154+
# Add hostmount-anyuid SCC to operator cluster role
155+
if [ -f "$OPERATOR-clusterrole.yml" ]; then
156+
yq -i '.rules += { "apiGroups": [ "security.openshift.io" ], "resources": [ "securitycontextconstraints" ], "resourceNames": ["hostmount-anyuid" ], "verbs": ["use"]}' "$OPERATOR-clusterrole.yml"
157+
fi
158+
159+
popd
160+
161+
}
162+
163+
main() {
164+
parse_inputs "$@"
165+
maybe_print_help
166+
generate_metadata
167+
generate_manifests
168+
patch_cluster_roles
169+
}
170+
171+
main "$@"

olm/cleanup-secret-objects.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kubectl delete securitycontextconstraints.security.openshift.io stackable-secret-operator-scc
2+
kubectl delete securitycontextconstraints.security.openshift.io stackable-products-scc
3+
kubectl delete secretclasses.secrets.stackable.tech/tls
4+
kubectl delete crd secretclasses.secrets.stackable.tech
5+
kubectl delete sa -n stackable-operators secret-operator-serviceaccount
6+
kubectl delete clusterrolebinding secret-operator-clusterrolebinding
7+
kubectl delete clusterrole secret-operator-clusterrole

0 commit comments

Comments
 (0)