| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Creates a ZFS dataset per PV. The helper pod runs with hostPID, and all |
| 3 | # ZFS and filesystem operations are performed in the host's mount namespace |
| 4 | # (nsenter -t 1 -m). Running zfs directly inside the helper container would |
| 5 | # mount the dataset only inside the container's own mount namespace; the |
| 6 | # workload would then write into the parent dataset, and the child dataset |
| 7 | # would shadow that data after the next host reboot. |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 8 | # |
| 9 | # The provisioner passes the volume path as $VOL_DIR (v0.0.2x and later); |
| 10 | # older versions passed it as -p. |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 11 | set -eu |
| 12 | |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 13 | absolutePath=${VOL_DIR:-} |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 14 | while getopts "m:s:p:" opt |
| 15 | do |
| 16 | case $opt in |
| 17 | p) |
| 18 | absolutePath=$OPTARG |
| 19 | ;; |
| 20 | s) |
| 21 | sizeInBytes=$OPTARG |
| 22 | ;; |
| 23 | m) |
| 24 | volMode=$OPTARG |
| 25 | ;; |
| 26 | esac |
| 27 | done |
| Matthias Andreas Benkard | ea83916 | 2026-11-04 20:47:43 +0100 | [diff] [blame] | 28 | [ -n "$absolutePath" ] || { echo "setup: no volume path given" >&2; exit 1; } |
| Matthias Andreas Benkard | 05e482e | 2026-11-04 11:05:51 +0100 | [diff] [blame] | 29 | |
| 30 | host() { nsenter -t 1 -m -- "$@"; } |
| 31 | |
| 32 | host zfs create "rpool${absolutePath}" |
| 33 | host zfs mount "rpool${absolutePath}" 2>/dev/null || : |
| 34 | host findmnt -n -o SOURCE "${absolutePath}" | grep -qx "rpool${absolutePath}" |
| 35 | host chmod 0777 "${absolutePath}" |