From 257f81fe269e6802842e5b1d7d25b94ad72f127a Mon Sep 17 00:00:00 2001 From: Steven Sklar Date: Wed, 18 Feb 2026 11:30:16 -0500 Subject: [PATCH 1/6] use slimmer image for init container --- .../init_db_migrations_configmap.yaml | 31 +++++++++---------- charts/questdb/templates/statefulset.yaml | 2 +- charts/questdb/values.yaml | 4 +-- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/charts/questdb/templates/init_db_migrations_configmap.yaml b/charts/questdb/templates/init_db_migrations_configmap.yaml index a98064b..560cd30 100644 --- a/charts/questdb/templates/init_db_migrations_configmap.yaml +++ b/charts/questdb/templates/init_db_migrations_configmap.yaml @@ -7,10 +7,9 @@ metadata: {{- include "questdb.labels" . | nindent 4 }} data: migrate_to_helm_v1.sh: | - #!/bin/bash + #!/bin/sh - set -e - shopt -s extglob + set -e SOURCE_DIR="/mnt/questdb" DEST_DIR="db" @@ -19,38 +18,38 @@ data: cd $SOURCE_DIR - if [[ -z $(ls $MARKER 2>/dev/null) ]] ; then + if [ -z "$(ls $MARKER 2>/dev/null)" ] ; then echo "File '$MARKER' not found. Nothing to move." exit 0 fi # If the db dir already exists, move its contents to a temp dir - if [[ -e $DEST_DIR ]]; then - - # Check that the temp dir does not already exist. This is highly + if [ -e "$DEST_DIR" ]; then + + # Check that the temp dir does not already exist. This is highly # unlikely and we fail if this is the case - if [[ -e $TEMP_DIR ]]; then + if [ -e "$TEMP_DIR" ]; then echo "$TEMP_DIR exists! exiting data migration" exit 1 - fi + fi # Move the existing db dir to the temp location mv "$DEST_DIR" "$TEMP_DIR" fi - + # Make the target db dir - mkdir $DEST_DIR + mkdir "$DEST_DIR" - # Move all regular files into the db dir - mv !($DEST_DIR) $DEST_DIR + # Move all visible files and dirs (except db) into the db dir + find . -maxdepth 1 ! -name '.' ! -name "$DEST_DIR" ! -name '.*' -exec mv {} "$DEST_DIR/" \; # Move any hidden files - mv .[^.]* "$DEST_DIR/" 2>/dev/null || true + find . -maxdepth 1 -name '.*' ! -name '.' ! -name '..' -exec mv {} "$DEST_DIR/" \; # Check if the temp dir exists in the new location, if so, move it back to db/db - if [[ -d "$DEST_DIR/$TEMP_DIR" ]]; then - mv $DEST_DIR/$TEMP_DIR $DEST_DIR/$DEST_DIR + if [ -d "$DEST_DIR/$TEMP_DIR" ]; then + mv "$DEST_DIR/$TEMP_DIR" "$DEST_DIR/$DEST_DIR" fi echo "Migration complete!" diff --git a/charts/questdb/templates/statefulset.yaml b/charts/questdb/templates/statefulset.yaml index d315656..6ba2d81 100644 --- a/charts/questdb/templates/statefulset.yaml +++ b/charts/questdb/templates/statefulset.yaml @@ -112,7 +112,7 @@ spec: initContainers: - name: init-db-migration image: "{{ .Values.dataMigration.image.repository }}:{{ .Values.dataMigration.image.tag }}" - command: ["bash", "/mnt/migration_scripts/migrate_to_helm_v1.sh"] + command: ["sh", "/mnt/migration_scripts/migrate_to_helm_v1.sh"] securityContext: {{- include "generateSecurityContext" . | nindent 12 }} volumeMounts: diff --git a/charts/questdb/values.yaml b/charts/questdb/values.yaml index 507c44a..5856f94 100644 --- a/charts/questdb/values.yaml +++ b/charts/questdb/values.yaml @@ -134,9 +134,9 @@ serviceAccount: dataMigration: image: - repository: debian + repository: alpine pullPolicy: IfNotPresent - tag: 12.10-slim + tag: "3.21" resources: requests: memory: "256Mi" From 2501e66087f3387b9de428b33ca0551d9e7c5cee Mon Sep 17 00:00:00 2001 From: Steven Sklar Date: Wed, 18 Feb 2026 15:53:57 -0500 Subject: [PATCH 2/6] fix --- .../templates/init_db_migrations_configmap.yaml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/charts/questdb/templates/init_db_migrations_configmap.yaml b/charts/questdb/templates/init_db_migrations_configmap.yaml index 560cd30..ae9768d 100644 --- a/charts/questdb/templates/init_db_migrations_configmap.yaml +++ b/charts/questdb/templates/init_db_migrations_configmap.yaml @@ -16,7 +16,7 @@ data: TEMP_DIR="db_helm_migration_1_tmp_$(date +"%Y%m%d%H%M%S")" MARKER="tables.d.*" - cd $SOURCE_DIR + cd "$SOURCE_DIR" if [ -z "$(ls $MARKER 2>/dev/null)" ] ; then echo "File '$MARKER' not found. Nothing to move." @@ -42,10 +42,16 @@ data: mkdir "$DEST_DIR" # Move all visible files and dirs (except db) into the db dir - find . -maxdepth 1 ! -name '.' ! -name "$DEST_DIR" ! -name '.*' -exec mv {} "$DEST_DIR/" \; + for item in ./* ; do + [ "$(basename "$item")" = "$DEST_DIR" ] && continue + mv "$item" "$DEST_DIR/" + done # Move any hidden files - find . -maxdepth 1 -name '.*' ! -name '.' ! -name '..' -exec mv {} "$DEST_DIR/" \; + for item in ./.[!.]* ./..?* ; do + [ -e "$item" ] || continue + mv "$item" "$DEST_DIR/" + done # Check if the temp dir exists in the new location, if so, move it back to db/db if [ -d "$DEST_DIR/$TEMP_DIR" ]; then From 5b83e3292115668549e2e6f3c61932e9969f60c3 Mon Sep 17 00:00:00 2001 From: Steven Sklar Date: Mon, 23 Feb 2026 14:54:36 -0500 Subject: [PATCH 3/6] fix --- charts/questdb/templates/init_db_migrations_configmap.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/questdb/templates/init_db_migrations_configmap.yaml b/charts/questdb/templates/init_db_migrations_configmap.yaml index ae9768d..e371748 100644 --- a/charts/questdb/templates/init_db_migrations_configmap.yaml +++ b/charts/questdb/templates/init_db_migrations_configmap.yaml @@ -39,7 +39,7 @@ data: fi # Make the target db dir - mkdir "$DEST_DIR" + mkdir -p "$DEST_DIR" # Move all visible files and dirs (except db) into the db dir for item in ./* ; do From 49a53d4b143f4d92ad774d31b0c2448c7aeeba5d Mon Sep 17 00:00:00 2001 From: Steven Sklar Date: Mon, 23 Feb 2026 14:56:15 -0500 Subject: [PATCH 4/6] bump alpine --- charts/questdb/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/questdb/values.yaml b/charts/questdb/values.yaml index 5856f94..5522fcf 100644 --- a/charts/questdb/values.yaml +++ b/charts/questdb/values.yaml @@ -136,7 +136,7 @@ dataMigration: image: repository: alpine pullPolicy: IfNotPresent - tag: "3.21" + tag: "3.23" resources: requests: memory: "256Mi" From 02a7e1d4ddb2f124a8685c01e62bf99b74e5d602 Mon Sep 17 00:00:00 2001 From: Steve Sklar Date: Tue, 7 Jul 2026 14:45:21 -0400 Subject: [PATCH 5/6] Address review: preserve symlink parity, harden migration loops - Restore parity with the old bash script for broken hidden symlinks: `[ -e ]` follows the link so a broken symlink was silently skipped. Add `|| [ -L ]` so broken symlinks (hidden and visible) are migrated. - Replace `[ ... ] && continue` (fragile under `set -e`) with a plain `if` in the visible-files loop. - Add the same null-glob guard to the visible-files loop that the hidden loop already had, so the two loops behave consistently. - Document the intentional unquoted `$MARKER` glob with a shellcheck disable directive; `shellcheck -s sh` is now clean. Verified end-to-end under dash (POSIX sh) across normal, existing-db, broken visible/hidden symlink, and no-marker cases; helm lint passes. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../templates/init_db_migrations_configmap.yaml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/charts/questdb/templates/init_db_migrations_configmap.yaml b/charts/questdb/templates/init_db_migrations_configmap.yaml index e371748..34ebe1f 100644 --- a/charts/questdb/templates/init_db_migrations_configmap.yaml +++ b/charts/questdb/templates/init_db_migrations_configmap.yaml @@ -18,6 +18,9 @@ data: cd "$SOURCE_DIR" + # MARKER is a glob (tables.d.*); it must stay unquoted so the shell + # expands it to detect the marker file. + # shellcheck disable=SC2086 if [ -z "$(ls $MARKER 2>/dev/null)" ] ; then echo "File '$MARKER' not found. Nothing to move." exit 0 @@ -43,13 +46,19 @@ data: # Move all visible files and dirs (except db) into the db dir for item in ./* ; do - [ "$(basename "$item")" = "$DEST_DIR" ] && continue + # Skip if the glob matched nothing (null-glob guard). -L also covers + # broken symlinks, which -e (it follows the link) would miss. + [ -e "$item" ] || [ -L "$item" ] || continue + if [ "$(basename "$item")" = "$DEST_DIR" ]; then + continue + fi mv "$item" "$DEST_DIR/" done - # Move any hidden files + # Move any hidden files, including broken symlinks (-e follows the link, + # so a broken symlink needs the -L check to be picked up) for item in ./.[!.]* ./..?* ; do - [ -e "$item" ] || continue + [ -e "$item" ] || [ -L "$item" ] || continue mv "$item" "$DEST_DIR/" done From 807b9b1a54c25ac8689ed468688c2350468f98e9 Mon Sep 17 00:00:00 2001 From: Steve Sklar Date: Tue, 7 Jul 2026 15:43:01 -0400 Subject: [PATCH 6/6] Harden marker check: use ls -d so a directory marker registers `ls $MARKER` lists a directory's *contents*, so if the tables.d.* glob matched an empty directory the guard read "not found" and skipped the migration entirely. `ls -d` lists each match's own name instead, so any match (file, empty dir, or non-empty dir) correctly registers as found. Pre-existing edge (the old bash script had the same `ls $MARKER`); the marker is normally a file, but this closes the hole cheaply on a line already touched by this PR. Verified under dash and on a real alpine:3.23 busybox init container in kind: empty-directory marker now migrates (realtable.d relocated into db/ with contents intact); file/non-empty-dir markers and the no-marker "Nothing to move" path are unchanged. shellcheck -s sh clean; helm lint passes. Co-Authored-By: Claude Opus 4.8 (1M context) --- charts/questdb/templates/init_db_migrations_configmap.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/charts/questdb/templates/init_db_migrations_configmap.yaml b/charts/questdb/templates/init_db_migrations_configmap.yaml index 34ebe1f..176d78e 100644 --- a/charts/questdb/templates/init_db_migrations_configmap.yaml +++ b/charts/questdb/templates/init_db_migrations_configmap.yaml @@ -19,9 +19,11 @@ data: cd "$SOURCE_DIR" # MARKER is a glob (tables.d.*); it must stay unquoted so the shell - # expands it to detect the marker file. + # expands it to detect the marker. -d lists each match's own name + # rather than a directory's contents, so an (empty) directory match + # still registers as "found". # shellcheck disable=SC2086 - if [ -z "$(ls $MARKER 2>/dev/null)" ] ; then + if [ -z "$(ls -d $MARKER 2>/dev/null)" ] ; then echo "File '$MARKER' not found. Nothing to move." exit 0 fi