Skip to content

Commit bb38a7c

Browse files
authored
chore(mariadb): extract inline startup scripts to external ConfigMap files (#2936)
1 parent 510cb44 commit bb38a7c

14 files changed

Lines changed: 2911 additions & 2737 deletions

addons/mariadb/scripts-ut-spec/backup_actionset_spec.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Describe "mariadb backup ActionSet account contract"
1515
}
1616

1717
semisync_cmpd_path() {
18-
printf "%s/addons/mariadb/templates/cmpd-replication.yaml" "$(repo_root)"
18+
printf "%s/addons/mariadb/scripts/replication-entrypoint.sh" "$(repo_root)"
1919
}
2020

2121
replication_merged_cmpd_path() {
22-
printf "%s/addons/mariadb/templates/cmpd-replication.yaml" "$(repo_root)"
22+
printf "%s/addons/mariadb/scripts/replication-entrypoint.sh" "$(repo_root)"
2323
}
2424

2525
remote_internal_admin_grants_backup_required_privileges() {

addons/mariadb/scripts-ut-spec/reconcile_runtime_overrides_spec.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,15 @@ EOF
230230

231231
It "cmpd-replication.yaml invokes reconcile-runtime-overrides.sh"
232232
cmpd_path() {
233-
printf "%s/addons/mariadb/templates/cmpd-replication.yaml" "$(repo_root)"
233+
printf "%s/addons/mariadb/scripts/replication-entrypoint.sh" "$(repo_root)"
234234
}
235235
When call grep -c 'reconcile-runtime-overrides.sh' "$(cmpd_path)"
236236
The output should not eq "0"
237237
End
238238

239239
It "cmpd-replication.yaml invokes reconcile-runtime-overrides.sh"
240240
cmpd_path() {
241-
printf "%s/addons/mariadb/templates/cmpd-replication.yaml" "$(repo_root)"
241+
printf "%s/addons/mariadb/scripts/replication-entrypoint.sh" "$(repo_root)"
242242
}
243243
When call grep -c 'reconcile-runtime-overrides.sh' "$(cmpd_path)"
244244
The output should not eq "0"

addons/mariadb/scripts-ut-spec/reconfigure_persisted_alpha86_spec.sh

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Describe "alpha.86 reconfigureAction.persisted semisync gates"
2525
ADDON_ROOT="${SHELLSPEC_CWD:?}/addons/mariadb"
2626
HELPERS_TPL="${ADDON_ROOT}/templates/_helpers.tpl"
2727
CMPD_SEMISYNC="${ADDON_ROOT}/templates/cmpd-replication.yaml"
28+
CMPD_ENTRYPOINT="${ADDON_ROOT}/scripts/replication-entrypoint.sh"
2829
CMPD_STANDALONE="${ADDON_ROOT}/templates/cmpd.yaml"
2930
CMPD_REPLICATION="${ADDON_ROOT}/templates/cmpd-replication.yaml"
3031
CMPD_GALERA="${ADDON_ROOT}/templates/cmpd-galera.yaml"
@@ -52,7 +53,7 @@ Describe "alpha.86 reconfigureAction.persisted semisync gates"
5253
/^[[:space:]]*start_mariadbd_process\(\) \{/ { in_func = 1; print; next }
5354
in_func && /^[[:space:]]*\}[[:space:]]*$/ { print; exit }
5455
in_func { print }
55-
' "${CMPD_SEMISYNC}"
56+
' "${CMPD_ENTRYPOINT}"
5657
}
5758

5859
extract_init_syncer_command_body() {
@@ -82,33 +83,33 @@ Describe "alpha.86 reconfigureAction.persisted semisync gates"
8283
awk '
8384
/chown -R mysql:mysql / { in_block = 1 }
8485
in_block { print }
85-
/^[[:space:]]+rm -f .* .replication-ready/ { in_block = 0 }
86-
' "${CMPD_SEMISYNC}"
86+
/^[[:space:]]*rm -f .* .replication-ready/ { in_block = 0 }
87+
' "${CMPD_ENTRYPOINT}"
8788
}
8889

8990
It "main container re-applies chgrp 1000 on runtime-overrides.d AFTER chown -R"
9091
When call main_container_bash_script
9192
The status should be success
9293
The output should include "chown -R mysql:mysql"
93-
The output should include "chgrp 1000 {{ .Values.dataMountPath }}/runtime-overrides.d"
94+
The output should include 'chgrp 1000 ${DATA_DIR}/runtime-overrides.d'
9495
End
9596

9697
It "main container re-applies chmod 0770 (g+rwx) on runtime-overrides.d AFTER chown -R"
9798
When call main_container_bash_script
9899
The status should be success
99-
The output should include "chmod 0770 {{ .Values.dataMountPath }}/runtime-overrides.d"
100+
The output should include 'chmod 0770 ${DATA_DIR}/runtime-overrides.d'
100101
End
101102

102103
It "main container re-applies chgrp 1000 on runtime-overrides.cnf loader AFTER chown -R"
103104
When call main_container_bash_script
104105
The status should be success
105-
The output should include "chgrp 1000 {{ .Values.dataMountPath }}/runtime-overrides.cnf"
106+
The output should include 'chgrp 1000 ${DATA_DIR}/runtime-overrides.cnf'
106107
End
107108

108109
It "main container re-applies chmod 0660 on runtime-overrides.cnf loader AFTER chown -R"
109110
When call main_container_bash_script
110111
The status should be success
111-
The output should include "chmod 0660 {{ .Values.dataMountPath }}/runtime-overrides.cnf"
112+
The output should include 'chmod 0660 ${DATA_DIR}/runtime-overrides.cnf'
112113
End
113114

114115
It "main container always overwrites loader to canonical content (recovers from corruption; Jack 07:03 B2 follow-up)"
@@ -129,10 +130,10 @@ Describe "alpha.86 reconfigureAction.persisted semisync gates"
129130
# AFTER-chown-R chgrp is what protects the kbagent permission
130131
# contract.
131132
When run sh -c '
132-
chown_line=$(grep -n "chown -R mysql:mysql" "'${CMPD_SEMISYNC}'" | head -1 | cut -d: -f1)
133+
chown_line=$(grep -n "chown -R mysql:mysql" "'${CMPD_ENTRYPOINT}'" | head -1 | cut -d: -f1)
133134
# Find all chgrp 1000 lines for the runtime-overrides dir and
134135
# take the LAST one (assumed to be the main container re-fixup).
135-
chgrp_line=$(grep -n "chgrp 1000 {{ \.Values\.dataMountPath }}/runtime-overrides\.d" "'${CMPD_SEMISYNC}'" | tail -1 | cut -d: -f1)
136+
chgrp_line=$(grep -n "chgrp 1000 \${DATA_DIR}/runtime-overrides\.d" "'${CMPD_ENTRYPOINT}'" | tail -1 | cut -d: -f1)
136137
if [ -n "${chown_line}" ] && [ -n "${chgrp_line}" ] && [ "${chgrp_line}" -gt "${chown_line}" ]; then
137138
echo "OK"
138139
else
@@ -189,7 +190,7 @@ Describe "alpha.86 reconfigureAction.persisted semisync gates"
189190
It "start_mariadbd_process function body includes the --defaults-extra-file flag"
190191
When call extract_start_mariadbd_function_body
191192
The status should be success
192-
The output should include "--defaults-extra-file={{ .Values.dataMountPath }}/runtime-overrides.cnf"
193+
The output should include '--defaults-extra-file=${DATA_DIR}/runtime-overrides.cnf'
193194
End
194195

195196
It "the --defaults-extra-file flag appears immediately after the mariadbd command (positional first arg)"
@@ -209,16 +210,16 @@ Describe "alpha.86 reconfigureAction.persisted semisync gates"
209210
}
210211
exit
211212
}
212-
" "'${CMPD_SEMISYNC}'"
213+
" "'${CMPD_ENTRYPOINT}'"
213214
'
214215
The status should be success
215216
The output should equal "OK"
216217
End
217218

218219
It "the --defaults-extra-file flag precedes --server-id in source order"
219220
When run sh -c '
220-
defaults_line=$(grep -n "defaults-extra-file=" "'${CMPD_SEMISYNC}'" | head -1 | cut -d: -f1)
221-
server_id_line=$(grep -n -- "--server-id=" "'${CMPD_SEMISYNC}'" | head -1 | cut -d: -f1)
221+
defaults_line=$(grep -n "defaults-extra-file=" "'${CMPD_ENTRYPOINT}'" | head -1 | cut -d: -f1)
222+
server_id_line=$(grep -n -- "--server-id=" "'${CMPD_ENTRYPOINT}'" | head -1 | cut -d: -f1)
222223
if [ -n "${defaults_line}" ] && [ -n "${server_id_line}" ] && [ "${defaults_line}" -lt "${server_id_line}" ]; then
223224
echo "OK"
224225
else

addons/mariadb/scripts-ut-spec/replication_merged_default_async_configmap_spec.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ Describe "alpha.89 merged CmpD default-async ConfigMap template"
6868
End
6969

7070
Describe "merged CmpD runtime semisync guard"
71+
entrypoint_path() {
72+
printf "%s/addons/mariadb/scripts/replication-entrypoint.sh" "$(repo_root)"
73+
}
74+
7175
It "declares the MARIADB_REPLICATION_MODE based semisync env helper before primary listener exposure"
72-
helper_line=$(grep -n '^ is_semisync_mode_env() {' "$(cmpd_path)" | cut -d: -f1)
73-
expose_line=$(grep -n '^ expose_sql_listener_for_primary_role() {' "$(cmpd_path)" | cut -d: -f1)
76+
helper_line=$(grep -n 'is_semisync_mode_env() {' "$(entrypoint_path)" | cut -d: -f1)
77+
expose_line=$(grep -n 'expose_sql_listener_for_primary_role() {' "$(entrypoint_path)" | cut -d: -f1)
7478
test -n "${helper_line}" && test -n "${expose_line}" && test "${helper_line}" -lt "${expose_line}"
7579
End
7680

7781
It "routes primary listener semisync reset through the guarded helper"
78-
count=$(grep -c 'reset_semisync_master_ack_receiver_if_enabled "primary-' "$(cmpd_path)")
82+
count=$(grep -c 'reset_semisync_master_ack_receiver_if_enabled "primary-' "$(entrypoint_path)")
7983
The variable count should equal 2
8084
End
8185

@@ -85,7 +89,7 @@ Describe "alpha.89 merged CmpD default-async ConfigMap template"
8589
/if is_semisync_mode_env; then/ { in_guard=1 }
8690
in_guard && /SET GLOBAL rpl_semi_sync_master_enabled=0; SET GLOBAL rpl_semi_sync_master_enabled=1;/ { found_guarded=1 }
8791
END { exit !(found_log && found_guarded) }
88-
' "$(cmpd_path)"
92+
' "$(entrypoint_path)"
8993
End
9094
End
9195

addons/mariadb/scripts-ut-spec/replication_merged_semisync_startup_recovery_spec.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
Describe "cmpd-replication.yaml semisync startup recovery"
55
template_file() {
6-
printf "%s/addons/mariadb/templates/cmpd-replication.yaml" "${SHELLSPEC_CWD:?}"
6+
printf "%s/addons/mariadb/scripts/replication-entrypoint.sh" "${SHELLSPEC_CWD:?}"
77
}
88

99
template_contains() {
@@ -50,11 +50,11 @@ Describe "cmpd-replication.yaml semisync startup recovery"
5050
stale_prestop_cleanup_clears_role_publish_markers() {
5151
awk '
5252
index($0, "decision=clear-stale-prestop-fence-on-container-start") { block = 1 }
53-
block && index($0, "rm -f {{ .Values.dataMountPath }}/.prestop-fence-started") { rmblock = 1 }
54-
rmblock && index($0, "{{ .Values.dataMountPath }}/.sql-listener-ready") { sql = 1 }
55-
rmblock && index($0, "{{ .Values.dataMountPath }}/.primary-read-write-ready") { primary = 1 }
56-
rmblock && index($0, "{{ .Values.dataMountPath }}/.replication-ready") { replica = 1 }
57-
block && index($0, "elif [ -f \"{{ .Values.dataMountPath }}/.prestop-fence-started\" ]; then") { exit }
53+
block && index($0, "rm -f ${DATA_DIR}/.prestop-fence-started") { rmblock = 1 }
54+
rmblock && index($0, "${DATA_DIR}/.sql-listener-ready") { sql = 1 }
55+
rmblock && index($0, "${DATA_DIR}/.primary-read-write-ready") { primary = 1 }
56+
rmblock && index($0, "${DATA_DIR}/.replication-ready") { replica = 1 }
57+
block && index($0, "elif [ -f \"${DATA_DIR}/.prestop-fence-started\" ]; then") { exit }
5858
END { exit(sql && primary && replica ? 0 : 1) }
5959
' "$(template_file)"
6060
}
@@ -93,7 +93,7 @@ Describe "cmpd-replication.yaml semisync startup recovery"
9393
index($0, "elif [ -n \"${PRIMARY_SID}\" ] || [ \"${POD_INDEX}\" -gt 0 ]; then") { branch = 1 }
9494
branch && index($0, "while true; do") { loop = 1 }
9595
loop && index($0, "if [ -z \"${PRIMARY_SID}\" ] || [ \"${PRIMARY_SID}\" = \"${SERVICE_ID}\" ]; then") { no_primary = 1 }
96-
no_primary && index($0, "if [ ! -f \"{{ .Values.dataMountPath }}/.sql-listener-ready\" ]; then") { stale_guard = 1 }
96+
no_primary && index($0, "if [ ! -f \"${DATA_DIR}/.sql-listener-ready\" ]; then") { stale_guard = 1 }
9797
no_primary && index($0, "reconcile_sql_listener_for_syncer_primary_once || true") { reconcile = 1 }
9898
no_primary && index($0, "_no_primary_iters=") { exit(reconcile && !stale_guard ? 0 : 1) }
9999
END { exit(reconcile && !stale_guard ? 0 : 1) }
@@ -193,7 +193,7 @@ Describe "cmpd-replication.yaml semisync startup recovery"
193193
End
194194

195195
It "keeps the preStop fence on later startup attempts in the same container lifecycle"
196-
When call template_contains 'elif [ -f "{{ .Values.dataMountPath }}/.prestop-fence-started" ]; then'
196+
When call template_contains 'elif [ -f "${DATA_DIR}/.prestop-fence-started" ]; then'
197197
The status should be success
198198
The output should include ".prestop-fence-started"
199199
End

0 commit comments

Comments
 (0)