#!/usr/bin/env bash
# scripts/pre-flight-checks.sh
#
# STATUS: PLACEHOLDER — drafted alongside deploy runbook.
#
# Pre-deploy sanity check. Reads-only; no state changes. Run before
# `juju deploy` to surface issues that would cause the deploy to fail
# during settle.
#
# Exit codes:
# 0 all checks pass
# 1 fatal — do not deploy
# 2 warning — review then decide
set -euo pipefail
# Strict mode hardening
shopt -s inherit_errexit 2>/dev/null || true
IFS=$'\n\t'
FATAL=0
WARN=0
fail() { echo "FAIL: $*" >&2; FATAL=$((FATAL+1)); }
warn() { echo "WARN: $*" >&2; WARN=$((WARN+1)); }
pass() { echo "PASS: $*"; }
note() { echo "NOTE: $*"; }
# TODO during drafting:
# - Juju controller reachable
# - MAAS API reachable; machines in expected state
# - NetBox reachable; VR0 DC0 prefixes/VLANs present (use --verify-only on imports)
# - jumphost /etc/hosts contains all expected API VIP hostnames
# - All KVM VMs (openstack0-3) reachable and Ready in MAAS
# - capi-mgmt.maas k3s healthy
# - Vault unseal keys present and readable
# - Disk space on /var/lib/libvirt/images sufficient for snapshots
# - bundle.yaml parses as valid YAML
# - overlay parses as valid YAML
# - Channel pins in bundle resolvable on Charmhub
note "Placeholder pre-flight script — not yet implemented."
echo
echo "Summary: ${FATAL} fatal, ${WARN} warning"
if [[ $FATAL -gt 0 ]]; then
exit 1
elif [[ $WARN -gt 0 ]]; then
exit 2
fi
exit 0