Skip to content

fix: resolve --lease-file under --state-dir - #18

Closed
CMGS wants to merge 3 commits into
mainfrom
fix/lease-path-and-help
Closed

fix: resolve --lease-file under --state-dir#18
CMGS wants to merge 3 commits into
mainfrom
fix/lease-path-and-help

Conversation

@CMGS

@CMGS CMGS commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

What

  • --lease-file no longer hardcodes /var/lib/cocoon/net/leases.json. It defaults to empty and resolves to <state-dir>/leases.json at run time, so a custom --state-dir keeps the daemon's lease file and the path teardown deletes in sync. leaseFileName moves to the shared cmd const block, giving daemon and teardown one owner for the name. The default installation path is unchanged.
  • --primary-nic help said "auto-detect if empty"; the real fallback is platform.DefaultNIC (eth0 on Volcengine, ens4 otherwise). Help and docs now say so.
  • adopt --dry-run prints an enis: row with the ENI IDs it records into pool.json and that teardown deletes (fix: persist adopted Volcengine ENI IDs #17), none when there are none.

Why

With --state-dir /srv/cocoon/net, the daemon persisted leases to /var/lib/cocoon/net/leases.json while teardown removed /srv/cocoon/net/leases.json. Stale leases survived a teardown, and the dry-run gave no preview of the ENI IDs that teardown will delete.

Test

TestResolveLeaseFile pins the three cases: default state dir, custom state dir, and an explicit --lease-file overriding both. It fails against the pre-fix behaviour:

--- FAIL: TestResolveLeaseFile/custom_state_dir
    utils_test.go:80: resolveLeaseFile() = "/var/lib/cocoon/net/leases.json", want "/srv/cocoon/net/leases.json"

Gates, GOWORK=off, both GOOS=linux and GOOS=darwin: make lint (0 issues each), make fmt-check, asl ./... (0 findings each), go test -race -count=1 ./... all green.

CMGS added 3 commits September 3, 2026 13:25
The daemon hardcoded /var/lib/cocoon/net/leases.json while teardown deletes
<state-dir>/leases.json, so a custom --state-dir made the daemon persist
leases outside the state directory and teardown remove a file nothing wrote.
The flag now defaults to empty and resolves to <state-dir>/leases.json at run
time; the default installation path is unchanged.

Two adjacent output fixes: --primary-nic help claimed auto-detection when the
real fallback is platform.DefaultNIC, and adopt --dry-run did not list the ENI
IDs it records into pool.json for teardown to delete.
@CMGS

CMGS commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by the rebased branch (same commits on the current main).

@CMGS CMGS closed this Sep 3, 2026
@CMGS
CMGS deleted the fix/lease-path-and-help branch September 3, 2026 05:41
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.

1 participant