1
1
#! /bin/bash
2
2
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
+
3
9
# Patch catalogd rbac
4
10
catalogd_rbac_filelist=(
5
11
helm/olmv1/base/catalogd/rbac/experimental/* .yaml
6
12
helm/olmv1/base/catalogd/rbac/standard/* .yaml
7
13
)
8
14
for f in " ${catalogd_rbac_filelist[@]} " ; do
9
15
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} "
11
18
done
12
19
13
20
# Patch operator-controller rbac
@@ -17,7 +24,8 @@ operator_controller_rbac_filelist=(
17
24
)
18
25
for f in " ${operator_controller_rbac_filelist[@]} " ; do
19
26
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} "
21
29
done
22
30
23
31
# Patch catalogd webhook
@@ -35,10 +43,9 @@ for f in "${catalogd_webhook_filelist[@]}"; do
35
43
yq -i ' .webhooks[0].clientConfig.service.port = 9443' " ${f} "
36
44
yq -i ' .webhooks[0].matchConditions[0].name = "MissingOrIncorrectMetadataNameLabel"' " ${f} "
37
45
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"
39
46
done
40
47
41
- # Patch everything genericly
48
+ # Patch everything generically
42
49
filelist=(
43
50
helm/olmv1/base/catalogd/rbac/experimental/* .yaml
44
51
helm/olmv1/base/catalogd/rbac/standard/* .yaml
@@ -56,10 +63,14 @@ for f in "${filelist[@]}"; do
56
63
# Patch in the temporary items
57
64
yq -i ' .metadata.annotations.replaceMe = "annotations"' " ${f} "
58
65
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
60
67
sed -i.bak ' s/replaceMe: annotations/{{- include "olmv1.annotations" . | nindent 4 }}/g' " ${f} "
61
68
sed -i.bak ' s/replaceMe: labels/{{- include "olmv1.labels" . | nindent 4 }}/g' " ${f} "
62
69
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} "
63
74
# Delete sed's backup file
64
75
rm -f " ${f} .bak"
65
76
done
0 commit comments