11#! /bin/bash
22
3+ # This script patches the kubebuilder generated files to make them ready for helm
4+ # The patching is done via a combination of `yq` to add valid YAML to the appropriate location
5+ # and then `sed` is used to replace some text with Helm templating.
6+ # This can't be done in one step because `yq` (or `kustomize` for that matter) can't manipulate
7+ # YAML once helm templating has been added.
8+
39# Patch catalogd rbac
410catalogd_rbac_filelist=(
511 helm/olmv1/base/catalogd/rbac/experimental/* .yaml
612 helm/olmv1/base/catalogd/rbac/standard/* .yaml
713)
814for f in " ${catalogd_rbac_filelist[@]} " ; do
915 yq -i ' .metadata.labels["app.kubernetes.io/name"] = "catalogd"' " ${f} "
10- rm -f " ${f} .bak"
16+ yq -i ' with(.; select(.kind == "Role") | .rules += { "replaceMe": "catalogd-role-rules"})' " ${f} "
17+ yq -i ' with(.; select(.kind == "ClusterRole") | .rules += { "replaceMe": "catalogd-cluster-role-rules"})' " ${f} "
1118done
1219
1320# Patch operator-controller rbac
@@ -17,7 +24,8 @@ operator_controller_rbac_filelist=(
1724)
1825for f in " ${operator_controller_rbac_filelist[@]} " ; do
1926 yq -i ' .metadata.labels["app.kubernetes.io/name"] = "operator-controller"' " ${f} "
20- rm -f " ${f} .bak"
27+ yq -i ' with(.; select(.kind == "Role") | .rules += { "replaceMe": "operator-controller-role-rules"})' " ${f} "
28+ yq -i ' with(.; select(.kind == "ClusterRole") | .rules += { "replaceMe": "operator-controller-cluster-role-rules"})' " ${f} "
2129done
2230
2331# Patch catalogd webhook
@@ -35,10 +43,9 @@ for f in "${catalogd_webhook_filelist[@]}"; do
3543 yq -i ' .webhooks[0].clientConfig.service.port = 9443' " ${f} "
3644 yq -i ' .webhooks[0].matchConditions[0].name = "MissingOrIncorrectMetadataNameLabel"' " ${f} "
3745 yq -i ' .webhooks[0].matchConditions[0].expression = "\"name\" in object.metadata && (!has(object.metadata.labels) || !(\"olm.operatorframework.io/metadata.name\" in object.metadata.labels) || object.metadata.labels[\"olm.operatorframework.io/metadata.name\"] != object.metadata.name)"' " ${f} "
38- rm -f " ${f} .bak"
3946done
4047
41- # Patch everything genericly
48+ # Patch everything generically
4249filelist=(
4350 helm/olmv1/base/catalogd/rbac/experimental/* .yaml
4451 helm/olmv1/base/catalogd/rbac/standard/* .yaml
@@ -56,10 +63,14 @@ for f in "${filelist[@]}"; do
5663 # Patch in the temporary items
5764 yq -i ' .metadata.annotations.replaceMe = "annotations"' " ${f} "
5865 yq -i ' .metadata.labels.replaceMe = "labels"' " ${f} "
59- # Replace with helm template - must be done last or yq will complain about the file formXat
66+ # Replace with helm template - must be done last or yq will complain about the file format
6067 sed -i.bak ' s/replaceMe: annotations/{{- include "olmv1.annotations" . | nindent 4 }}/g' " ${f} "
6168 sed -i.bak ' s/replaceMe: labels/{{- include "olmv1.labels" . | nindent 4 }}/g' " ${f} "
6269 sed -i.bak ' s/olmv1-system/{{ .Values.namespaces.olmv1.name }}/g' " ${f} "
70+ sed -i.bak ' s/- replaceMe: catalogd-role-rules/{{- include "olmv1.catalogd.role.rules" . | nindent 2 }}/g' " ${f} "
71+ sed -i.bak ' s/- replaceMe: catalogd-cluster-role-rules/{{- include "olmv1.catalogd.clusterRole.rules" . | nindent 2 }}/g' " ${f} "
72+ sed -i.bak ' s/- replaceMe: operator-controller-role-rules/{{- include "olmv1.operatorController.role.rules" . | nindent 2 }}/g' " ${f} "
73+ sed -i.bak ' s/- replaceMe: operator-controller-cluster-role-rules/{{- include "olmv1.operatorController.clusterRole.rules" . | nindent 2 }}/g' " ${f} "
6374 # Delete sed's backup file
6475 rm -f " ${f} .bak"
6576done
0 commit comments