@@ -13,10 +13,67 @@ local files_in_dir = std.native('list_dir')(dir_path, true);
1313/* Remove file_extension from file list */
1414local files = [ std.strReplace (file, file_extension, '' ) for file in files_in_dir ];
1515
16+ local bitnami_ready =
17+ '[ -f /opt/bitnami/postgresql/tmp/.initialized ] || [ -f /bitnami/postgresql/.initialized ]\n ' ;
18+
19+ // NOTE(sg): The Helm chart has custom logic to inject the `bitnami_ready`
20+ // string in the postgres container's readiness probe when it's rendered with
21+ // an image that contains exactly `bitnami/`. We mimic the Helm chart's
22+ // behavior for images that contain `bitnamilegacy/` here since those still
23+ // are bitnami images and will have the bitnami special readiness indication
24+ // file.
25+ local patchReadinessProbe(obj) =
26+ if std.startsWith (params.images.postgresql.repository, 'bitnamilegacy/' )
27+ && obj.kind == 'StatefulSet'
28+ && obj.metadata.name == 'keycloak-postgresql'
29+ then
30+ local containers = obj.spec.template.spec.containers;
31+ assert
32+ std.length (containers) == 1 :
33+ 'Expected builtin postgres statefulset to have a single container' ;
34+ // extract the readiness probe command
35+ local rcommand = containers[0 ].readinessProbe.exec.command;
36+ // extract the sh -c -e prefix
37+ local shell = rcommand[0 :std.length (rcommand) - 1 ];
38+ assert
39+ shell[0 ] == '/bin/sh' :
40+ 'expected readiness command to start with\n /bin/sh' ;
41+ // patch the command string with a second line checking for the bitnami
42+ // initialized file.
43+ local cmd = rcommand[std.length (rcommand) - 1 ];
44+ assert
45+ std.startsWith (cmd, 'exec pg_isready' ) :
46+ 'expected readiness probe to use `exec pg_isready`' ;
47+ local patched_cmd = [ cmd + bitnami_ready ];
48+ obj {
49+ spec+: {
50+ template+: {
51+ spec+: {
52+ containers: [
53+ containers[0 ] {
54+ readinessProbe+: {
55+ exec: {
56+ // set the patched command
57+ command: shell + patched_cmd,
58+ },
59+ },
60+ },
61+ ],
62+ },
63+ },
64+ },
65+ }
66+ else
67+ obj;
68+
1669{
1770 [file]:
1871 if params.postgresql_helm_values.enabled
19- then com.yaml_load(std.extVar('output_path' ) + '/' + file + file_extension)
20- else []
72+ then
73+ patchReadinessProbe(
74+ com.yaml_load(std.extVar('output_path' ) + '/' + file + file_extension)
75+ )
76+ else
77+ []
2178 for file in files
2279}
0 commit comments