diff --git a/package/gitea-runner-controller/hcloud.sh b/package/gitea-runner-controller/hcloud.sh index 53d04d00..a12e7980 100644 --- a/package/gitea-runner-controller/hcloud.sh +++ b/package/gitea-runner-controller/hcloud.sh @@ -636,7 +636,10 @@ gcr_vm_verify_rebuilt() { | select((.id | tostring) == $vm) | select(.status == "running") | select((.server_type.name // "") == $type) - | select((.server_type.architecture // "") == $arch) + | select((.server_type.architecture + | if . == "x86" then "amd64" + elif . == "arm" then "arm64" + else . end) == $arch) | select((.location.name // .datacenter.location.name // "") == $location) | select((.image.id | tostring) == $image) | .public_net.ipv4.ip diff --git a/test/package/gitea-runner-controller/test/idle-reuse.sh b/test/package/gitea-runner-controller/test/idle-reuse.sh index 990e6694..679a90ee 100644 --- a/test/package/gitea-runner-controller/test/idle-reuse.sh +++ b/test/package/gitea-runner-controller/test/idle-reuse.sh @@ -246,7 +246,7 @@ EOF printf '%s\n' '{"action":{"id":501,"status":"success","command":"rebuild_server","progress":100,"started":"2026-01-16T00:31:45+00:00","finished":"2026-01-16T00:32:15+00:00","error":null,"resources":[{"id":71,"type":"server"}]}}' > "$GCR_LAST_BODY" ;; GET:/servers/71) - printf '%s\n' '{"server":{"id":71,"status":"running","server_type":{"id":117,"name":"ccx53","architecture":"amd64"},"location":{"id":1,"name":"nbg1","city":"Nuremberg","country":"DE","network_zone":"eu-central"},"image":{"id":424242},"public_net":{"ipv4":{"ip":"192.0.2.71"}}}}' > "$GCR_LAST_BODY" + printf '%s\n' '{"server":{"id":71,"status":"running","server_type":{"id":117,"name":"ccx53","architecture":"x86"},"location":{"id":1,"name":"nbg1","city":"Nuremberg","country":"DE","network_zone":"eu-central"},"image":{"id":424242},"public_net":{"ipv4":{"ip":"192.0.2.71"}}}}' > "$GCR_LAST_BODY" ;; *) return 1 ;; esac @@ -337,6 +337,26 @@ if grep -Eq 'LEAK_ROOT|LEAK_CLOUD_INIT|LEAK_PRIVATE_KEY|LEAK_TOKEN|#cloud-config fi export GCR_LOG=error +# Hetzner names architectures x86/arm; allocation profiles use amd64/arm64. +# Normalize names without accepting a genuinely different architecture. +contract_request='GET:/servers/71' +for arch_pair in x86:amd64 arm:arm64; do + api_arch="${arch_pair%:*}" + profile_arch="${arch_pair#*:}" + jq -n --arg arch "$api_arch" \ + '{server:{id:71,status:"running",server_type:{name:"test-type",architecture:$arch},location:{name:"nbg1"},image:{id:424242},public_net:{ipv4:{ip:"192.0.2.71"}}}}' \ + > "$contract_body" + test "$(gcr_vm_verify_rebuilt 71 test-type nbg1 "$profile_arch" 424242)" = 192.0.2.71 + case "$profile_arch" in + amd64) wrong_arch=arm64 ;; + arm64) wrong_arch=amd64 ;; + esac + if gcr_vm_verify_rebuilt 71 test-type nbg1 "$wrong_arch" 424242; then + printf 'different server architecture must be rejected\n' >&2 + exit 1 + fi +done + # Incompatible image/profile remains idle and normal allocation creates anew. incompatible='{"job_id":"304","run_attempt":"1","repo":"","label":"","created_at":1000,"ttl_min":180,"vm_id":73,"vm_name":"gcr-304-1","runner_name":"","server_type":"cx53","budget_rate":"0.032","location":"nbg1","arch":"amd64","image_id":"313131","bootstrapped":false,"status":"idle_vm","idle_since":2000,"idle_expires_at":4600}' gcr_record_put 304 1 "$incompatible"