daemon split (2/5): extract *ImageService service
Second phase of splitting the daemon god-struct. ImageService now owns
all image + kernel registry operations: register/promote/delete/pull
for images (bundle + OCI paths), the six kernel commands, and the
shared SSH-key/work-seed injection helpers. imageOpsMu (the
publication-window lock) lives on the service; so do the three OCI
pull test seams pullAndFlatten / finalizePulledRootfs / bundleFetch.
The four files images.go, images_pull.go, image_seed.go, kernels.go
flipped their receivers from *Daemon to *ImageService.
FindImage moved with the service. Daemon keeps a thin FindImage
forwarder so callers reading the dispatch code see the obvious
facade and tests that pre-date the split still compile.
flattenNestedWorkHome — called from image_seed.go, vm_authsync.go,
and vm_disk.go across future service boundaries — became a
package-level helper taking a CommandRunner explicitly. Daemon keeps
a deprecated forwarder for now; the other services will use the
package form.
Lazy-init helper imageSvc() on Daemon mirrors hostNet() from
Phase 1, so test literals like &Daemon{store: db, runner: r, ...}
that don't spell out an ImageService still get a working one.
Tests that override the image test seams (autopull_test,
concurrency_test, images_pull_test, images_pull_bundle_test) now
assign d.img = &ImageService{...seams...}; the two-statement pattern
matches what Phase 1 established for HostNetwork.
Dispatch in daemon.go is cleaner now: every image/kernel RPC handler
is a single-liner forwarding to d.imageSvc().*. Phase 5 will do the
same for VM lifecycle.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
362009d747
commit
d7614a3b2b
15 changed files with 389 additions and 209 deletions
|
|
@ -71,14 +71,19 @@ func TestPullImageHappyPath(t *testing.T) {
|
|||
kernel, initrd, modules := writeFakeKernelTriple(t)
|
||||
|
||||
d := &Daemon{
|
||||
layout: paths.Layout{ImagesDir: imagesDir, OCICacheDir: cacheDir},
|
||||
store: openDaemonStore(t),
|
||||
runner: system.NewRunner(),
|
||||
layout: paths.Layout{ImagesDir: imagesDir, OCICacheDir: cacheDir},
|
||||
store: openDaemonStore(t),
|
||||
runner: system.NewRunner(),
|
||||
}
|
||||
d.img = &ImageService{
|
||||
layout: d.layout,
|
||||
store: d.store,
|
||||
runner: d.runner,
|
||||
pullAndFlatten: stubPullAndFlatten,
|
||||
finalizePulledRootfs: stubFinalizePulledRootfs,
|
||||
}
|
||||
|
||||
image, err := d.PullImage(context.Background(), api.ImagePullParams{
|
||||
image, err := d.img.PullImage(context.Background(), api.ImagePullParams{
|
||||
Ref: "docker.io/library/debian:bookworm",
|
||||
KernelPath: kernel,
|
||||
InitrdPath: initrd,
|
||||
|
|
@ -116,9 +121,14 @@ func TestPullImageRejectsExistingName(t *testing.T) {
|
|||
kernel, _, _ := writeFakeKernelTriple(t)
|
||||
|
||||
d := &Daemon{
|
||||
layout: paths.Layout{ImagesDir: imagesDir, OCICacheDir: t.TempDir()},
|
||||
store: openDaemonStore(t),
|
||||
runner: system.NewRunner(),
|
||||
layout: paths.Layout{ImagesDir: imagesDir, OCICacheDir: t.TempDir()},
|
||||
store: openDaemonStore(t),
|
||||
runner: system.NewRunner(),
|
||||
}
|
||||
d.img = &ImageService{
|
||||
layout: d.layout,
|
||||
store: d.store,
|
||||
runner: d.runner,
|
||||
pullAndFlatten: stubPullAndFlatten,
|
||||
finalizePulledRootfs: stubFinalizePulledRootfs,
|
||||
}
|
||||
|
|
@ -133,7 +143,7 @@ func TestPullImageRejectsExistingName(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err := d.PullImage(context.Background(), api.ImagePullParams{
|
||||
_, err := d.img.PullImage(context.Background(), api.ImagePullParams{
|
||||
Ref: "docker.io/library/debian:bookworm",
|
||||
KernelPath: kernel,
|
||||
})
|
||||
|
|
@ -144,13 +154,18 @@ func TestPullImageRejectsExistingName(t *testing.T) {
|
|||
|
||||
func TestPullImageRequiresKernel(t *testing.T) {
|
||||
d := &Daemon{
|
||||
layout: paths.Layout{ImagesDir: t.TempDir(), OCICacheDir: t.TempDir()},
|
||||
store: openDaemonStore(t),
|
||||
runner: system.NewRunner(),
|
||||
layout: paths.Layout{ImagesDir: t.TempDir(), OCICacheDir: t.TempDir()},
|
||||
store: openDaemonStore(t),
|
||||
runner: system.NewRunner(),
|
||||
}
|
||||
d.img = &ImageService{
|
||||
layout: d.layout,
|
||||
store: d.store,
|
||||
runner: d.runner,
|
||||
pullAndFlatten: stubPullAndFlatten,
|
||||
finalizePulledRootfs: stubFinalizePulledRootfs,
|
||||
}
|
||||
_, err := d.PullImage(context.Background(), api.ImagePullParams{
|
||||
_, err := d.img.PullImage(context.Background(), api.ImagePullParams{
|
||||
Ref: "docker.io/library/debian:bookworm",
|
||||
})
|
||||
if err == nil || !strings.Contains(err.Error(), "kernel") {
|
||||
|
|
@ -166,13 +181,18 @@ func TestPullImageCleansStagingOnFailure(t *testing.T) {
|
|||
}
|
||||
|
||||
d := &Daemon{
|
||||
layout: paths.Layout{ImagesDir: imagesDir, OCICacheDir: t.TempDir()},
|
||||
store: openDaemonStore(t),
|
||||
runner: system.NewRunner(),
|
||||
layout: paths.Layout{ImagesDir: imagesDir, OCICacheDir: t.TempDir()},
|
||||
store: openDaemonStore(t),
|
||||
runner: system.NewRunner(),
|
||||
}
|
||||
d.img = &ImageService{
|
||||
layout: d.layout,
|
||||
store: d.store,
|
||||
runner: d.runner,
|
||||
pullAndFlatten: failureSeam,
|
||||
finalizePulledRootfs: stubFinalizePulledRootfs,
|
||||
}
|
||||
_, err := d.PullImage(context.Background(), api.ImagePullParams{
|
||||
_, err := d.img.PullImage(context.Background(), api.ImagePullParams{
|
||||
Ref: "docker.io/library/debian:bookworm",
|
||||
KernelPath: kernel,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue