Skip to content

Refresh nspawn device config before machine startup - #412

Draft
hbc (bcho) with Copilot wants to merge 5 commits into
mainfrom
copilot/add-nspawn-config-hook
Draft

Refresh nspawn device config before machine startup#412
hbc (bcho) with Copilot wants to merge 5 commits into
mainfrom
copilot/add-nspawn-config-hook

Conversation

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Host device paths can change across host reboots, leaving the persisted nspawn config with stale bind mounts. This adds a systemd-managed refresh step so device mappings are rediscovered before an existing nspawn machine starts.

  • Startup hook

    • Writes unbounded-agent-nspawn-config@<machine>.service
    • Orders systemd-nspawn@<machine>.service after the refresh unit
  • Config regeneration

    • Adds hidden agent command:
      unbounded-agent regenerate-nspawn-config kube1
    • Loads the persisted applied config for the machine
    • Resolves fresh host device/GPU state
    • Rewrites the .nspawn config and service drop-in
  • Lifecycle cleanup

    • Removes the generated refresh unit during nspawn reset cleanup
  • Docs and tests

    • Updates nspawn reference docs for the refresh behavior
    • Extends render tests and snapshots for the new systemd dependency

Copilot AI changed the title [WIP] Add hook to regenerate nspawn config on host changes Refresh nspawn device config before machine startup Jul 7, 2026
Copilot AI requested a review from hbc (bcho) July 7, 2026 16:17

@bcho hbc (bcho) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot can we rename the oneshot target to regenerate config so we can further extend it to include other config regeneration in the future

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Copilot can we rename the oneshot target to regenerate config so we can further extend it to include other config regeneration in the future

Addressed in 71158be: the oneshot unit is now unbounded-agent-regenerate-config@<machine>.service and it runs the generalized hidden regenerate-config command.

Copilot AI requested a review from hbc (bcho) July 7, 2026 20:15
@bcho
hbc (bcho) marked this pull request as ready for review July 7, 2026 23:24
@bcho
hbc (bcho) requested a review from a team July 7, 2026 23:24
@bcho
hbc (bcho) marked this pull request as draft July 7, 2026 23:25
@bcho

Copy link
Copy Markdown
Member

Copilot resolve conflicts

…nfig-hook

# Conflicts:
#	pkg/agent/phases/rootfs/nspawn.go
#	pkg/agent/phases/rootfs/nspawn_render_test.go

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Copilot resolve conflicts

Resolved the conflicts by merging origin/main into the PR branch and preserving the regenerate-config behavior in merge commit 7edafe8.

@bcho

Copy link
Copy Markdown
Member

Copilot resolve conflict

…nfig-hook

# Conflicts:
#	pkg/agent/phases/rootfs/nspawn.go
#	pkg/agent/phases/rootfs/nspawn_render_test.go

Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>

Copilot AI commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Copilot resolve conflict

Resolved the latest conflicts by merging origin/main into the PR branch and preserving the regenerate-config behavior in merge commit df6920b.

@bcho
hbc (bcho) requested a balanced review from Copilot August 8, 2026 00:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds pre-start regeneration of nspawn device mappings so host reboot path changes are refreshed.

Changes:

  • Adds a systemd oneshot regeneration dependency.
  • Adds hidden regeneration commands and persisted-config loading.
  • Updates cleanup, documentation, render tests, and snapshots.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
cmd/agent/internal/cmd/cmd.go Registers regeneration commands.
cmd/agent/internal/cmd/nspawn_config.go Implements persisted-config regeneration.
docs/content/reference/agent/nspawn.md Documents refresh behavior and artifacts.
pkg/agent/goalstates/constants.go Defines regeneration unit naming.
pkg/agent/phases/reset/nspawn.go Removes generated units during cleanup.
pkg/agent/phases/rootfs/assets/config-regeneration.service Defines the pre-start oneshot.
pkg/agent/phases/rootfs/assets/service-override.conf Adds regeneration ordering.
pkg/agent/phases/rootfs/nspawn.go Renders regeneration units and nspawn configuration.
pkg/agent/phases/rootfs/nspawn_render_test.go Tests rendered dependencies and unit content.
pkg/agent/phases/rootfs/testdata/render/cpu-only.service-override.conf.golden Updates CPU snapshot.
pkg/agent/phases/rootfs/testdata/render/nvidia-all-helpers.service-override.conf.golden Updates NVIDIA helper snapshot.
pkg/agent/phases/rootfs/testdata/render/nvidia-gb300-rack-full.service-override.conf.golden Updates GB300 snapshot.
pkg/agent/phases/rootfs/testdata/service-override-kube1.conf.golden Updates kube1 snapshot.
pkg/agent/phases/rootfs/testdata/service-override-kube2.conf.golden Updates kube2 snapshot.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +205 to +206
if err := utilio.WriteFile(goalState.ServiceOverrideFile, overrideBuf.Bytes(), 0o644); err != nil {
return fmt.Errorf("write service override %s: %w", goalState.ServiceOverrideFile, err)
Comment on lines +76 to +78
gs, err := goalstates.ResolveMachine(log, cfg, machineName, nil)
if err != nil {
return fmt.Errorf("resolve machine goal state: %w", err)
Comment on lines +65 to +66
func regenerateNSpawnConfig(ctx context.Context, log *slog.Logger, machineName string) error {
cfg, ok, err := loadAppliedConfigForMachine(log, machineName)
Comment on lines +4 to +5
[Unit]
Description=Regenerate configuration for {{.MachineName}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agent: nspawn config should tolerate device mapping changes on the host after host restart

3 participants