|
1 | 1 | #!/usr/bin/env bash |
2 | | -# Mesh integration test for the github_runner_cluster role: stands up three k3s nodes in Docker on one machine, each in its own copy of the Compose project, and has the role join them through Headscale. Scenarios: hosted headscale_hosted: the role runs Headscale under Compose beside the first node. in_cluster headscale_in_cluster: the role runs Headscale inside the cluster, on the bootstrap server. existing headscale_existing: the policy check fails, with the entry to add, against a server whose policy lacks autoApprovers, and passes once it has one. Every scenario uses automatic server selection (three hosts, no overrides, so three servers). The cluster scenarios assert that etcd has three members, that every node is Ready, and that pods on different nodes reach each other over the mesh. |
| 2 | +# Mesh integration test for the github_runner_cluster role: stands up three k3s nodes in Docker on one machine, each in its own copy of the Compose project, and has the role join them through Headscale. Scenarios: hosted headscale_hosted: the role runs Headscale under Compose beside the first node. in_cluster headscale_in_cluster: the role runs Headscale inside the cluster, on the bootstrap server. existing headscale_existing: the policy check fails, with the entry to add, against a server whose policy lacks autoApprovers, and passes once it has one. Every scenario uses automatic server selection (three hosts, no overrides, so three servers). compose_faulty the role refuses a Docker Compose release that recreates the containers it has just built, before writing anything (run it under such a release; it is not in the default set). The cluster scenarios assert that etcd has three members, that every node is Ready, and that pods on different nodes reach each other over the mesh. |
3 | 3 | # |
4 | 4 | # Usage: tests/mesh/run.sh <scenario>... (default: all three). Needs Docker with Compose, and Python 3 with ansible-core (ANSIBLE_PLAYBOOK overrides which ansible-playbook runs). Creates only Docker objects named grtest-*, and removes them again on exit unless GRTEST_KEEP=1. |
5 | 5 | set -euo pipefail |
@@ -274,6 +274,37 @@ scenario_cluster() { |
274 | 274 | fi |
275 | 275 | } |
276 | 276 |
|
| 277 | +# The role must refuse a Docker Compose release that recreates the containers it has just built (see the check in the cluster role's tasks/main.yml) before it writes anything to the host. The workflow installs such a release for this scenario; every other scenario runs under a good one and so also shows the check lets that through. |
| 278 | +scenario_compose_faulty() { |
| 279 | + local output node |
| 280 | + reset_environment |
| 281 | + node="$(node_name 1)" |
| 282 | + mkdir -p "${work}/${node}" |
| 283 | + cat > "${work}/inventory.yml" <<EOF |
| 284 | +all: |
| 285 | + vars: |
| 286 | + ansible_connection: local |
| 287 | + ansible_python_interpreter: $(command -v python3) |
| 288 | + children: |
| 289 | + github_runner_cluster: |
| 290 | + vars: |
| 291 | + github_runner_cluster_k3s_token: ${k3s_token} |
| 292 | + hosts: |
| 293 | + ${node}: |
| 294 | + github_runner_cluster_dir: ${work}/${node} |
| 295 | + github_runner_cluster_compose_project: ${node} |
| 296 | +EOF |
| 297 | + log "The role must refuse Docker Compose $(docker compose version --short) before touching the host" |
| 298 | + if output=$(run_role 2>&1); then |
| 299 | + echo "$output"; fail "the role ran with a Compose release it should refuse" |
| 300 | + fi |
| 301 | + echo "$output" | grep -F "Fail if this host's Docker Compose recreates the containers it has just built" >/dev/null || { echo "$output"; fail "the role failed, but not at the Compose version check"; } |
| 302 | + echo "$output" | grep -F 'Upgrade the Docker Compose plugin on this host' >/dev/null || { echo "$output"; fail "the failure did not say to upgrade Compose"; } |
| 303 | + [ -z "$(ls -A "${work}/${node}")" ] || fail "the role wrote to the cluster directory before refusing: $(ls -A "${work}/${node}")" |
| 304 | + echo "$output" | grep -F 'Upgrade the Docker Compose plugin' | head -n 1 |
| 305 | + log "It did" |
| 306 | +} |
| 307 | + |
277 | 308 | scenario_existing() { |
278 | 309 | reset_environment |
279 | 310 | local fixtures="${repo_root}/tests/mesh/fixtures/headscale-existing" api_url api_key output |
@@ -322,6 +353,7 @@ for scenario in "${scenarios[@]}"; do |
322 | 353 | case "$scenario" in |
323 | 354 | hosted | in_cluster) scenario_cluster "$scenario" ;; |
324 | 355 | existing) scenario_existing ;; |
| 356 | + compose_faulty) scenario_compose_faulty ;; |
325 | 357 | # Re-checks a cluster a previous run kept with GRTEST_KEEP=1 and the same GRTEST_WORK, without rebuilding it. |
326 | 358 | assert) assert_cluster ;; |
327 | 359 | *) fail "unknown scenario ${scenario}" ;; |
|
0 commit comments