Skip to content

Commit 9257764

Browse files
fmastemgmeier
authored andcommitted
wb | add automatic check for node.ssd_directory cleanup during cloud deployments
1 parent 076afc8 commit 9257764

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

nix/workbench/backend/nomad/cloud.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,10 @@ allocate-run-nomadcloud() {
707707
&& jqtest '.node.utxo_lmdb' "${dir}"/profile.json \
708708
&& jqtest '(.cluster.nomad.host_volumes.producer | length) > 0' "${dir}"/profile.json
709709
then
710-
# Index on the "host_volumes" array.
710+
# Iterate over the profile's Nomad "host_volumes" array by key/index.
711711
for host_volume_key in $(jq_tolist '.cluster.nomad.host_volumes.producer | keys' "${dir}"/profile.json)
712712
do
713-
# Compare the SSD directory the node will use and volume destination.
713+
# Compare defined node's SSD directory with this volume's destination.
714714
local ssd_directory host_volume_destination
715715
ssd_directory="$(jq -r '.node.ssd_directory' "${dir}"/profile.json)"
716716
host_volume_destination="$(jq -r ".cluster.nomad.host_volumes.producer[${host_volume_key}].destination" "${dir}"/profile.json)"
@@ -721,10 +721,16 @@ allocate-run-nomadcloud() {
721721
host_volume_source="$(jq -r ".cluster.nomad.host_volumes.producer[${host_volume_key}].source" "${dir}"/profile.json)"
722722
host_volume_path="$(wb nomad clients ssh "${client_name}" cat /etc/nomad.json | jq -r ".client.host_volume[\"${host_volume_source}\"].path")"
723723
local rm_command
724+
# Won't remove hidden files like ".mounted".
724725
rm_command="rm -rf \"${host_volume_path}\"/*"
725-
msg "$(yellow "About to: \"${rm_command}\"")"
726-
read -p "Hit enter to continue ..."
726+
msg "$(yellow "Cleaning up SSD host volume. Executing: \"${rm_command}\" on Nomad client \"${client_name}\" (${client_id}) ...")"
727727
wb nomad clients ssh "${client_name}" "${rm_command}"
728+
# Check that the directory is empty (hidden files ignored).
729+
if wb nomad clients ssh "${client_name}" "ls \"${host_volume_path}\"/" | grep --invert-match --quiet -E "^0$"
730+
then
731+
msg "$(yellow "WARNING: Nomad client \"${client_name}\" (${client_id}) still has files in \"${host_volume_path}\"")"
732+
read -p "Hit enter to continue ..."
733+
fi
728734
fi
729735
done
730736
fi

0 commit comments

Comments
 (0)