diff --git a/charts/questdb/templates/init_db_migrations_configmap.yaml b/charts/questdb/templates/init_db_migrations_configmap.yaml index a98064b..176d78e 100644 --- a/charts/questdb/templates/init_db_migrations_configmap.yaml +++ b/charts/questdb/templates/init_db_migrations_configmap.yaml @@ -7,50 +7,66 @@ 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" 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 + # MARKER is a glob (tables.d.*); it must stay unquoted so the shell + # 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 -d $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 -p "$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 + for item in ./* ; do + # 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 - mv .[^.]* "$DEST_DIR/" 2>/dev/null || true + # 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" ] || [ -L "$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 - 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..5522fcf 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.23" resources: requests: memory: "256Mi"