Files
computer-playbook/scripts/tests/deploy/swarm/routine/06_drain_worker.sh
T
kevinveenbirkenbachandClaude Opus 5 a88508c998 fix(swarm): carry the drill handover in-process, not via $GITHUB_ENV
d9a4498b3 collapsed eleven CI steps into one, which broke the assumption every handover in the drill rested on: a $GITHUB_ENV write only comes back in the NEXT step. Inside one step nobody sees it. matrix.py reads os.environ["MGR_IP"], so every swarm job died with KeyError before the first deploy round; 05 -> 06 -> 07 passed INITIAL_NODE/NEW_NODE the same way and would have died next.

The node IPs now come from the topology SPOT: compose.yml already pins every node to those INFINITO_SWARM_*_IP keys, so the docker-inspect capture only read back what compose had set. It goes, together with the $GITHUB_ENV publish and lab_net. lab_domain_target reads the env instead, guarded by an assert task because lookup('env') yields '' for a missing key and an empty dnsmasq `address=/domain/` is valid syntax meaning NODATA -- the failure would have surfaced 30 retries later as a DNS problem.

INITIAL_NODE/NEW_NODE move to a SWARM_DRILL_ENV file, created fresh per distro so the previous distro's node cannot leak into the next drain. The out-of-drill callers of _context.sh keep working through a visible guard; both writers stay strict via :?.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 23:53:43 +02:00

53 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Drain the worker running the app and force a reschedule. The cluster runs
# without a registry and deploys with --resolve-image never, so a role that
# ships a build: context produces its <ENTITY>_custom:<tag> image only on the
# manager; mirror it onto each worker first so swarm can re-schedule there.
# Roles without a custom build use an upstream image present on every worker.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# shellcheck disable=SC1091
source "${SCRIPT_DIR}/../utils/_context.sh"
skip_if_no_swarm_service
skip_chaos_if_manager_pinned
[ -n "${INITIAL_NODE}" ] || {
echo "INITIAL_NODE not set"
exit 1
}
echo "==> Distributing ${CUSTOM_IMAGE_REPO} image to swarm workers"
IMAGE_TAG=$(docker exec "${MGR}" docker images --format '{{.Repository}}:{{.Tag}}' |
grep "^${CUSTOM_IMAGE_REPO}:" | head -1 || true)
if [ -z "${IMAGE_TAG}" ]; then
echo " no '${CUSTOM_IMAGE_REPO}:*' image on manager — role uses an upstream image; skipping distribution"
else
echo " image: ${IMAGE_TAG}"
for worker in "${WRK1}" "${WRK2}"; do
echo " -> ${worker}"
docker exec "${MGR}" docker save "${IMAGE_TAG}" |
docker exec -i "${worker}" docker load
done
fi
docker exec "${MGR}" docker node update --availability drain "${INITIAL_NODE}"
NEW_NODE=""
for i in $(seq 1 "${RESCHED_TIMEOUT}"); do
NEW_NODE=$(docker exec "${MGR}" docker service ps \
--filter desired-state=running \
--format '{{.Node}}' "${SERVICE_NAME}" | head -1)
if [ -n "${NEW_NODE}" ] && [ "${NEW_NODE}" != "${INITIAL_NODE}" ]; then
echo "Rescheduled from ${INITIAL_NODE} to ${NEW_NODE} after ${i}s"
echo "NEW_NODE=${NEW_NODE}" >>"${SWARM_DRILL_ENV:?SWARM_DRILL_ENV is required (exported by routine/00_one.sh)}"
exit 0
fi
sleep 1
done
echo "FAILURE: ${ENTITY} did not migrate from ${INITIAL_NODE}"
docker exec "${MGR}" docker service ps "${SERVICE_NAME}"
exit 1