diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index 6990971..6327910 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -7303,6 +7303,89 @@ PIMOX_CONTAINERD_EOF done } +ensure_pimox_node_ephemeral_storage_headroom() { + local enabled="${LAB_PIMOX_NODE_STORAGE_CLEANUP:-true}" + local cp_host="${LAB_CLUSTER_CONTROL_PLANE_LAN_IP:-}" + local cp_user="${LAB_CLUSTER_CONTROL_PLANE_USER:-jv}" + local cp_node="${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME:-pimox-cp-01}" + local cp_key="${LAB_CLUSTER_CONTROL_PLANE_SSH_KEY_PATH:-/home/jv/.ssh/id_ed25519}" + local spec_file="${REPO_ROOT}/.lab/pimox-workers.tsv" + local max_log_size="${LAB_PIMOX_NODE_LOG_MAX_SIZE:-200M}" + local journal_size="${LAB_PIMOX_NODE_JOURNAL_MAX_SIZE:-200M}" + local -a node_entries=() + local worker_key + local worker_host + local worker_user + local worker_node + local worker_key_path + local node_entry + local node_host + local node_user + local node_name + local node_key_path + + if [[ "${LAB_CLUSTER_PROFILE:-debian}" != "pimox" ]]; then + return 0 + fi + if disabled_value "${enabled}"; then + echo "Skipping Pimox node ephemeral-storage cleanup because LAB_PIMOX_NODE_STORAGE_CLEANUP=${enabled}." + return 0 + fi + if ! truthy "${enabled}"; then + echo "LAB_PIMOX_NODE_STORAGE_CLEANUP must be true or false." >&2 + exit 1 + fi + if [[ ! "${max_log_size}" =~ ^[0-9]+[KMG]?$ || ! "${journal_size}" =~ ^[0-9]+[KMG]?$ ]]; then + echo "LAB_PIMOX_NODE_LOG_MAX_SIZE and LAB_PIMOX_NODE_JOURNAL_MAX_SIZE must be size values like 200M." >&2 + exit 1 + fi + + if [[ -n "${cp_host}" ]]; then + node_entries+=("${cp_host}"$'\t'"${cp_user}"$'\t'"${cp_node}"$'\t'"${cp_key}") + fi + if [[ -s "${spec_file}" ]]; then + while IFS=$'\t' read -r worker_key worker_host worker_user worker_node worker_key_path; do + [[ -n "${worker_host}" && -n "${worker_user}" && -n "${worker_node}" && -n "${worker_key_path}" ]] || continue + node_entries+=("${worker_host}"$'\t'"${worker_user}"$'\t'"${worker_node}"$'\t'"${worker_key_path}") + done <"${spec_file}" + fi + if ((${#node_entries[@]} == 0)); then + echo "Could not resolve Pimox nodes for ephemeral-storage cleanup." >&2 + exit 1 + fi + + for node_entry in "${node_entries[@]}"; do + IFS=$'\t' read -r node_host node_user node_name node_key_path <<<"${node_entry}" + echo "Ensuring ephemeral-storage headroom on ${node_name} (${node_user}@${node_host})..." + refresh_lab_ssh_known_host "${node_host}" + ssh -i "${node_key_path}" -o BatchMode=yes -o ConnectTimeout=10 -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new "${node_user}@${node_host}" \ + "LAB_PIMOX_NODE_LOG_MAX_SIZE='${max_log_size}' LAB_PIMOX_NODE_JOURNAL_MAX_SIZE='${journal_size}' bash -s" <<'PIMOX_NODE_STORAGE_EOF' +set -eu + +echo "-- before --" +df -h / /var/lib/containerd 2>/dev/null || df -h / + +if command -v crictl >/dev/null 2>&1; then + sudo crictl ps -a --state Exited -q 2>/dev/null | xargs -r sudo crictl rm 2>/dev/null || true + sudo crictl rmi --prune 2>/dev/null || true +fi + +if command -v journalctl >/dev/null 2>&1; then + sudo journalctl --vacuum-size="${LAB_PIMOX_NODE_JOURNAL_MAX_SIZE:-200M}" >/dev/null 2>&1 || true +fi + +for log_dir in /var/log/pods /var/log/containers; do + if [ -d "${log_dir}" ]; then + sudo find "${log_dir}" -type f -name '*.log' -size +"${LAB_PIMOX_NODE_LOG_MAX_SIZE:-200M}" -print -exec truncate -s 0 {} \; 2>/dev/null || true + fi +done + +echo "-- after --" +df -h / /var/lib/containerd 2>/dev/null || df -h / +PIMOX_NODE_STORAGE_EOF + done +} + apps() { local app_ready_wait_seconds="${LAB_APPS_READY_WAIT_SECONDS:-180}" local app_resource_wait_seconds="${LAB_APPS_RESOURCE_WAIT_SECONDS:-120}" @@ -7344,6 +7427,7 @@ apps() { ensure_pimox_registry_storage_path ensure_pimox_registry_endpoint_forwarding "${registry_endpoint}" ensure_pimox_containerd_registry_refresh "${registry_endpoint}" + ensure_pimox_node_ephemeral_storage_headroom ensure_cosign_keypair publish_cosign_public_key_config_map