|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# shellcheck source=tests/scripts/lib.sh |
| 4 | +source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" |
| 5 | + |
| 6 | +STUB_BIN="$(cd "$(dirname "${BASH_SOURCE[0]}")/stub" && pwd)" |
| 7 | + |
| 8 | +nodes() { |
| 9 | + printf '%s\n' "$@" >"$WORK_DIR/nodes" |
| 10 | +} |
| 11 | + |
| 12 | +run_ensure_node_ip() { |
| 13 | + if [ -n "$1" ]; then |
| 14 | + printf 'node-ip: %s\n' "$1" >"$WORK_DIR/config.yaml" |
| 15 | + fi |
| 16 | + ( |
| 17 | + export PATH="$STUB_BIN:$PATH" K3S_CONFIG="$WORK_DIR/config.yaml" KUBECONFIG=/dev/null NODE_IP_ATTEMPTS=1 |
| 18 | + # shellcheck source=utils/colors.sh |
| 19 | + source "$TEST_ROOT/utils/colors.sh" |
| 20 | + # shellcheck source=utils/ensure_node_ip.sh |
| 21 | + source "$TEST_ROOT/utils/ensure_node_ip.sh" |
| 22 | + ensure_node_ip |
| 23 | + ) >"$WORK_DIR/output" 2>&1 || fail "ensure_node_ip exited $?: $(cat "$WORK_DIR/output")" |
| 24 | +} |
| 25 | + |
| 26 | +annotations() { |
| 27 | + grep ' annotate ' "$WORK_DIR/calls" 2>/dev/null || true |
| 28 | +} |
| 29 | + |
| 30 | +# The panel registered on its LAN IP, then game-node-server-setup.sh moved k3s |
| 31 | +# to Tailscale: the kubelet followed, the Node's InternalIP never did. |
| 32 | +test_a_panel_moved_to_tailscale_has_its_provided_ip_moved_too() { |
| 33 | + nodes "$(printf 'dietpi\t100.117.134.62,fd7a:115c:a1e0::c02b:863f\t192.168.2.199')" \ |
| 34 | + "$(printf 'game-node\t100.64.0.9\t100.64.0.9')" |
| 35 | + run_ensure_node_ip 100.117.134.62 |
| 36 | + assert_eq "$(annotations)" "--kubeconfig=/dev/null annotate node dietpi alpha.kubernetes.io/provided-node-ip=100.117.134.62 --overwrite" |
| 37 | +} |
| 38 | + |
| 39 | +test_a_node_already_on_its_ip_is_left_alone() { |
| 40 | + nodes "$(printf 'dietpi\t100.117.134.62\t100.117.134.62')" |
| 41 | + run_ensure_node_ip 100.117.134.62 |
| 42 | + assert_eq "$(annotations)" "" |
| 43 | +} |
| 44 | + |
| 45 | +test_a_panel_without_node_ip_never_asks_the_cluster() { |
| 46 | + nodes "$(printf 'dietpi\t192.168.2.199\t192.168.2.199')" |
| 47 | + run_ensure_node_ip "" |
| 48 | + assert_eq "$(cat "$WORK_DIR/calls" 2>/dev/null)" "" |
| 49 | +} |
| 50 | + |
| 51 | +# Annotating before k3s has restarted onto the new IP would name an address |
| 52 | +# the node does not have yet. |
| 53 | +test_a_node_k3s_has_not_moved_yet_is_left_alone() { |
| 54 | + nodes "$(printf 'dietpi\t192.168.2.199\t192.168.2.199')" |
| 55 | + run_ensure_node_ip 100.117.134.62 |
| 56 | + assert_eq "$(annotations)" "" |
| 57 | + assert_contains "$(cat "$WORK_DIR/output")" "re-run ./update.sh" |
| 58 | +} |
| 59 | + |
| 60 | +run_tests |
0 commit comments