Skip to content

Commit 2cc9866

Browse files
authored
Merge pull request #7 from indexdata/DEVOPS-6444-skip-enable
Make module enablement optional
2 parents a7a5a69 + 31cc8c0 commit 2cc9866

5 files changed

Lines changed: 26 additions & 19 deletions

File tree

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
This project provides Okapi deployment automation when deploying Okapi modules on Kubernetes.
44

5-
`okapi-hooks` is a helper container for Okapi module registration (deploy + install/uninstall + undeploy)
5+
`okapi-hooks` is a helper container for Okapi module registration (deploy + optional install/uninstall + undeploy)
66
and a corresponding Helm chart that binds to Helm's `post-instal` and `post-upgrade`
77
[lifecycle hooks](https://helm.sh/docs/topics/charts_hooks/).
88

9+
If a list of Okapi tenants is provided, the module will be enabled (installed)
10+
for each tenant in the list.
11+
912
While the container and the chart can be used independently, the intended use is as a subchart dependency
1013
in a parent Okapi module Helm chart, like so:
1114

@@ -31,15 +34,13 @@ moduleDescriptor: |
3134
"id" : "mod-x-0.1.0",
3235
"name" : "X Okapi module"
3336
}
34-
tenants:
35-
- mytenant
36-
3737
```
38+
3839
It's recommended that the module version in the ModuleDescriptor follows the parent chart version.
3940
4041
see [values.yaml](./chart/values.yaml) for a complete list of configuration options.
4142
42-
The parent chart is then build with:
43+
The parent chart is then built with:
4344
4445
```bash
4546
cd /path/to/parent/chart

chart/templates/_validate.tpl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,4 @@
1212
{{- if not .Values.moduleDescriptor -}}
1313
{{- fail "A valid .Values.moduleDescriptor is required!" -}}
1414
{{- end -}}
15-
{{- if empty .Values.tenants -}}
16-
{{- fail "A valid .Values.tenants is required!" -}}
17-
{{- end -}}
1815
{{- end -}}

chart/templates/okapi-hook-job.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ spec:
3333
- name: MODULE_URL
3434
value: "{{ .Values.moduleUrl }}"
3535
- name: OKAPI_TENANTS
36-
value: "{{ join "," .Values.tenants }}"
36+
value: "{{ join "," .Values.tenants | default([]) }}"
3737
- name: OKAPI_ADMIN_TENANT
3838
value: "{{ join "," .Values.supertenant }}"
3939
{{- range $k, $v := .Values.env }}

chart/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ moduleUrl: ""
1212
#ModuleDescriptor literal (JSON), NO DEFAULT
1313
moduleDescriptor: ""
1414
#Okapi tenant(s) to deploy the module to, NO DEFAULTS
15+
#If list is empty or undefined, module will be registered and deployed but
16+
#not enabled for any tenant
1517
tenants: []
1618

1719
#REQUIRED values with defaults in the subchart, may be overridden by parent chart:

okapi-hooks.sh

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,23 @@ login() {
3838

3939
# TODO: handle that previous instance is a different version
4040
hook_pre_delete() {
41-
for T in $OKAPI_TENANTS; do
42-
echo "[{\"id\":\"${SVCID}\",\"action\":\"disable\"}]" | post -d @- $U/_/proxy/tenants/$T/install
43-
done
41+
if test -n "${OKAPI_TENANTS}"; then
42+
for T in $OKAPI_TENANTS; do
43+
echo "[{\"id\":\"${SVCID}\",\"action\":\"disable\"}]" | post -d @- $U/_/proxy/tenants/$T/install
44+
done
45+
fi
4446
delete "$U/_/discovery/modules/${SVCID}/${INSTID}"
4547
delete "$U/_/proxy/modules/${SVCID}"
4648
}
4749

4850
hook_post_install() {
4951
echo $OKAPI_MD | post --fail-with-body -d @- $U/_/proxy/modules
5052
echo "{\"srvcId\":\"$SVCID\",\"instId\":\"${INSTID}\",\"url\":\"${MODULE_URL}\"}" | post --fail-with-body -d @- $U/_/discovery/modules
51-
for T in $OKAPI_TENANTS; do
52-
echo "[{ \"id\":\"${SVCID}\",\"action\":\"enable\"}]" | post --fail-with-body -d @- $U/_/proxy/tenants/$T/install
53-
done
53+
if test -n "${OKAPI_TENANTS}"; then
54+
for T in $OKAPI_TENANTS; do
55+
echo "[{ \"id\":\"${SVCID}\",\"action\":\"enable\"}]" | post --fail-with-body -d @- $U/_/proxy/tenants/$T/install
56+
done
57+
fi
5458
}
5559

5660
tenants_lookup() {
@@ -86,8 +90,7 @@ tenants_lookup() {
8690
prepare() {
8791
fail=false
8892
if test -z "$OKAPI_TENANTS"; then
89-
echo "OKAPI_TENANTS not set"
90-
fail=true
93+
echo "OKAPI_TENANTS not set, will deploy only (no enablement)"
9194
fi
9295
if test -z "$OKAPI_URL"; then
9396
echo "OKAPI_URL not set"
@@ -118,12 +121,16 @@ prepare() {
118121
OKAPI_ADMIN_TENANT=${OKAPI_ADMIN_TENANT:-supertenant}
119122
SVCID=`echo $OKAPI_MD | jq -r '.id'`
120123
INSTID=inst-${SVCID}
121-
OKAPI_TENANTS=$(echo "$OKAPI_TENANTS" | tr ',' ' ')
124+
if test -n "${OKAPI_TENANTS}"; then
125+
OKAPI_TENANTS=$(echo "$OKAPI_TENANTS" | tr ',' ' ')
126+
fi
122127
}
123128

124129
prepare
125130
login
126-
tenants_lookup
131+
if test -n "${OKAPI_TENANTS}"; then
132+
tenants_lookup
133+
fi
127134

128135
hook_pre_delete
129136
hook_post_install

0 commit comments

Comments
 (0)