#!/usr/bin/env bash # M8.9 read-only placement check (ADR-0076) for a disposable environment. # # tools/ops/scheduling-check.sh [--context NAME] # # Verifies the node plan against the live cluster, changing nothing: # - exactly one Ready worker carries aevolution.io/stores=true, and it is not a # control-plane node; # - the environment's aevolution-objects volume is pinned to that node (local # volumes cannot follow a region to another node); # - the evo-region pod runs there; # - nodes labelled aevolution.io/compute=true are listed, with whether they can # take work (Ready, schedulable). None is valid: compute is only a preference. # Adding a node: label it aevolution.io/compute=true and re-run. Only stateless pods # move to it; a region moves between nodes only through a backup restore or a clone # onto that node's storage (ADR-0074/0075), never by rescheduling. set -euo pipefail usage() { echo "usage: $0 [--context NAME]" >&2; exit 2; } [ $# -ge 1 ] || usage env="$1"; shift case "$env" in dev|stage) ;; *) echo "refused: '$env' is not a disposable environment (only dev or stage; never world0)" >&2 exit 2 ;; esac k=(kubectl --request-timeout=30s) [ "${1:-}" = "--context" ] && [ -n "${2:-}" ] && k+=(--context "$2") ns="evolution-$env" failures=0 ok() { echo " ok $*"; } bad() { echo " FAIL $*"; failures=$((failures + 1)); } ready='{range .status.conditions[?(@.type=="Ready")]}{.status}{end}' echo "stores node" stores="$("${k[@]}" get nodes -l aevolution.io/stores=true -o name | sed 's#^node/##')" if [ "$(grep -c . <<< "$stores")" = 1 ]; then ok "one stores node: $stores"; else bad "stores nodes: '${stores//$'\n'/ }' (need exactly one)"; fi store_node="$(head -1 <<< "$stores")" if [ -n "$store_node" ]; then [ "$("${k[@]}" get node "$store_node" -o jsonpath="$ready")" = True ] && ok "$store_node Ready" || bad "$store_node not Ready" "${k[@]}" get node "$store_node" -o jsonpath='{.metadata.labels}' | grep -q 'node-role.kubernetes.io/control-plane' && bad "$store_node is a control-plane node" || ok "$store_node is a worker" fi echo "objects volume ($ns)" pv="$("${k[@]}" get pvc -n "$ns" aevolution-objects -o jsonpath='{.spec.volumeName}' 2> /dev/null || true)" if [ -z "$pv" ]; then bad "aevolution-objects is not bound" else pinned="$("${k[@]}" get pv "$pv" -o jsonpath='{.spec.nodeAffinity.required.nodeSelectorTerms[*].matchExpressions[*].values[*]}')" [ "$pinned" = "$store_node" ] && ok "$pv pinned to $pinned" || bad "$pv pinned to '$pinned', not the stores node '$store_node'" fi echo "region host" placed="$("${k[@]}" get pods -n "$ns" -l app.kubernetes.io/name=evo-region -o jsonpath='{range .items[*]}{.metadata.name}={.spec.nodeName}{"\n"}{end}')" if [ -z "$placed" ]; then bad "no evo-region pod"; fi while IFS='=' read -r pod node; do [ -n "$pod" ] || continue [ "$node" = "$store_node" ] && ok "$pod on $node" || bad "$pod on '$node', not the stores node" done <<< "$placed" echo "compute nodes (preferred for stateless AEvolution pods)" compute="$("${k[@]}" get nodes -l aevolution.io/compute=true -o name | sed 's#^node/##')" if [ -z "$compute" ]; then echo " none labelled: stateless pods schedule anywhere (single-node plan)" else while read -r node; do state="$("${k[@]}" get node "$node" -o jsonpath="$ready")" cordoned="$("${k[@]}" get node "$node" -o jsonpath='{.spec.unschedulable}')" echo " $node Ready=$state schedulable=$([ "$cordoned" = true ] && echo no || echo yes)" done <<< "$compute" fi placed_am="$("${k[@]}" get pods -n aevolution-monitoring -l app.kubernetes.io/name=alertmanager -o jsonpath='{.items[0].spec.nodeName}' 2> /dev/null || true)" [ -n "$placed_am" ] && echo " alertmanager runs on $placed_am" echo [ "$failures" = 0 ] && echo "PASS scheduling plan in $ns" || { echo "FAIL $failures check(s) in $ns"; exit 1; }