~ knotless Search/
↑↓ move↵ open⇧↵ all results

socialweb.computer/socialweb-computer-kcp

socialweb.computer: a compute market on atproto (kcp)

1 collaborator
0
0
26 lines · 1.4 KB Raw History
#!/usr/bin/env bash
# Plan 0044: the market holds none of our rentals before a hand run, and after one that could not clean up.
#   scripts/ci-hand-market.sh [list|delete]
# Every host in CI_BIDDER_HOSTS (the hand runner's env file) runs a prod bidder whose kcp admin kubeconfig is
# /var/lib/socialweb-computer/swc-bidder/handles/*/kcp/admin.kubeconfig (root only): list its ComputeVMs, or delete them,
# which makes the bidder stop the VM and publish vm.terminated. This host is reached directly, the others over ssh.
set -euo pipefail
mode=${1:-list}
case "$mode" in list|delete) ;; *) echo "usage: scripts/ci-hand-market.sh [list|delete]" >&2; exit 2 ;; esac
: "${CI_BIDDER_HOSTS:?CI_BIDDER_HOSTS: the bidder hosts, from the hand runner env file (plan 0044)}"
remote='set -eu
for k in /var/lib/socialweb-computer/swc-bidder/handles/*/kcp/admin.kubeconfig; do
  s=$(sed -n "s/^ *server: //p" "$k" | head -1)
  kc="kubectl --kubeconfig $k --server=${s%/clusters/*}/clusters/root"
  names=$($kc get computevms -o jsonpath="{range .items[*]}{.metadata.name} {end}")
  echo "${names:-none}"
  if [ "$1" = delete ] && [ -n "$names" ]; then $kc delete computevms $names --wait=true --timeout=180s; fi
done'
for h in $CI_BIDDER_HOSTS; do
  if [ "$h" = "$(hostname -s)" ]; then
    out=$(sudo sh -c "$remote" sh "$mode" 2>&1)
  else
    out=$(ssh -o ConnectTimeout=10 "$h" sudo sh -c "$(printf '%q' "$remote")" sh "$mode" 2>&1)
  fi
  printf '%s\n' "$out" | sed "s/^/$h: /"
done