Skip to content

fix(allocation): destroy and apply free the ledger entries of machines gone; teardown forgets stale ones - #120

Merged
Teg79 merged 1 commit into
mainfrom
fix/ledger-stale-entries
Nov 18, 2026
Merged

Teg79 merged 1 commit into
mainfrom
fix/ledger-stale-entries

Conversation

@Teg79

@Teg79 Teg79 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • internal/provision/ledger.go (new):
    • stateHostnames: the machines in an environment's Terraform state (module.service["…"], module.vm["…"]), declared in urbex.yaml or not;
    • freeGone: removes from the allocation ledger the machines that left the state and that urbex.yaml no longer declares, and says so (Freed the addresses of …).
  • apply: reads the state before (vanished machines included) and after terraform apply, and frees the addresses of what left. That covers an application removed from urbex.yaml and deleted by apply --delete-data (or a plain delete), which is how pgtest-board-staging stayed in the lab's ledger.
  • destroy: frees every machine its state held, not only the services urbex.yaml lists.
  • teardown: with no environment folder left, an entry the ledger still holds (left by an older urbex) is forgotten if its machine is gone from Proxmox (Forgot stale entries of the allocation ledger …, naming host and VMID). If its machine still exists, teardown stops and names it, with what to do: delete it in the pool, or put its application back and urbex destroy. Nothing urbex doesn't account for is deleted. Before, any ledger entry was a bare "project environments still exist".
  • Tests: TestStateHostnames, TestFreeGone (removed and deleted → freed; still declared → kept; another project's → kept), TestForgetStaleLedger (all gone → forgotten; one live → stops naming it).

Companion docs: urbforge/urbex#93.

Why

#115, found in the Forgejo spike: a stale pgtest-board-staging entry (the application had been removed from urbex.yaml before its environment was destroyed) blocked urbex teardown, and had to be removed by hand.

Tests I ran

  • go test ./..., mise run lint: pass.
  • mise run e2e: PASSED (24 steps), destroy and teardown included.
  • On the lab, the real case: the stale entry, with its LXC 9129 gone from Proxmox. Handled then by a one-off script; the new teardown logic does the same check (VMID not in Proxmox → forget).

Checklist before review

Fixes #115

🤖 Generated with Claude Code

https://claude.ai/code/session_0182yxsfwRowwnxCfgrQwjnA

…s gone; teardown forgets stale ones

apply frees the entries of machines that left the Terraform state and urbex.yaml no longer declares; destroy frees every machine the state held, not only the declared ones. teardown, with no environment left, forgets entries whose machines are gone from Proxmox and stops, naming them, on those that still exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0182yxsfwRowwnxCfgrQwjnA
@Teg79
Teg79 merged commit 697890b into main Nov 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(allocation): destroy removes the ledger entries of services no longer in urbex.yaml

2 participants