Skip to content

Refactor Daemon.create - prep for call to NRI plugin#51526

Merged
robmry merged 8 commits intomoby:masterfrom
robmry:refactor-create-mounts
Nov 25, 2025
Merged

Refactor Daemon.create - prep for call to NRI plugin#51526
robmry merged 8 commits intomoby:masterfrom
robmry:refactor-create-mounts

Conversation

@robmry
Copy link
Contributor

@robmry robmry commented Nov 14, 2025

- What I did

For NRI, the daemon will need to call a plugin with a container's config, and the plugin may modify the container - including its mount points.

So, set up the container's config before processing mount options and finding volumes to make it possible to call NRI first.

Plus some refactoring ...

  • Daemon.create called setHostConfig to assign opts.params.HostConfig directly to ctr.HostConfig, after the container was constructed.
  • It looked like opts.params.HostConfig and ctr.HostConfig were different, but they weren't.
  • setHostConfig did stuff that wasn't setting host config.

- How I did it

See individual commits.

- How to verify it

- Human readable description for the release notes

@robmry robmry added this to the 29.1.0 milestone Nov 14, 2025
@robmry robmry self-assigned this Nov 14, 2025
@robmry robmry added area/daemon Core Engine kind/refactor PR's that refactor, or clean-up code labels Nov 14, 2025
@robmry robmry force-pushed the refactor-create-mounts branch 6 times, most recently from 87bec98 to 1d3bf99 Compare November 16, 2025 13:58
The call from Daemon.create -> Daemon.setHostConfig acquired
container.Lock, but didn't need to because the container is
newly created and solely owned by the caller. The call from
Daemon.restore did not acquire the lock.

Signed-off-by: Rob Murray <[email protected]>
It's set later in Daemon.create, setHostConfig's only caller.

Signed-off-by: Rob Murray <[email protected]>
Daemon.createContainerOSSpecificSettings adds container config for
the OS, and creates volumes. Split those two things.

This will make it possible to call an NRI plugin after the config
is complete, before volumes are created - so the NRI plugin can
adjust a full set of config, including volumes.

Signed-off-by: Rob Murray <[email protected]>
Call registerMountPoints after the rest of the container's
configuration has been set up.

This will make it possible to call an NRI plugin with the
container's config, allowing it to adjust the mounts in that
config, before it's used to find volumes etc.

Signed-off-by: Rob Murray <[email protected]>
The container's constructor, Daemon.newContainer, already has
hostConfig and can just assign it directly.

Signed-off-by: Rob Murray <[email protected]>
Also:
- remove the hostConfig param from Daemon.createContainerVolumesOS.
- rename var container -> ctr

Signed-off-by: Rob Murray <[email protected]>
@robmry robmry force-pushed the refactor-create-mounts branch from 1d3bf99 to 96b8f9c Compare November 16, 2025 18:27
@robmry robmry marked this pull request as ready for review November 17, 2025 09:43
@robmry robmry requested a review from Copilot November 17, 2025 09:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors Daemon.create to prepare for integration with NRI (Node Resource Interface) plugins. The main goal is to set up the container's configuration before processing mount options and volumes, enabling NRI plugin calls that may modify container configuration including mount points.

Key changes:

  • Removed the setHostConfig method which was misleadingly named and performed operations beyond just setting host config
  • Restructured the container creation flow to set HostConfig during container construction rather than after
  • Separated OS-specific settings from volume creation into distinct functions

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
daemon/create.go Refactored container creation flow: removed setHostConfig call, moved registerLinks and registerMountPoints to separate steps, and split OS-specific operations
daemon/container.go Removed setHostConfig method; simplified setSecurityOptions to use container's existing HostConfig; set HostConfig during container construction in newContainer
daemon/volumes.go Updated registerMountPoints to accept container directly and read HostConfig from it, removing separate hostConfig parameter; renamed container to ctr for consistency
daemon/create_unix.go Split createContainerOSSpecificSettings into two functions: one for OS settings and a new createContainerVolumesOS for volume creation; moved mount/unmount operations to volume creation
daemon/create_windows.go Split createContainerOSSpecificSettings similarly to Unix version, separating volume creation into createContainerVolumesOS
daemon/daemon_unix.go Updated registerLinks to accept only container parameter and read HostConfig from it
daemon/daemon_windows.go Updated registerLinks signature to match Unix version
daemon/daemon.go Updated restore call to registerLinks to match new signature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@robmry robmry requested review from thaJeztah and vvoland November 17, 2025 09:44
Copy link
Member

@akerouanton akerouanton left a comment

Choose a reason for hiding this comment

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

Nice cleanup! LGTM

@robmry robmry merged commit abd4c10 into moby:master Nov 25, 2025
243 of 246 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/daemon Core Engine kind/refactor PR's that refactor, or clean-up code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants