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
|
|
@ -38,7 +38,7 @@ func TestKernelListReturnsSeededEntries(t *testing.T) {
|
|||
seedKernelEntry(t, kernelsDir, "alpine-3.23")
|
||||
|
||||
d := &Daemon{layout: paths.Layout{KernelsDir: kernelsDir}}
|
||||
result, err := d.KernelList(context.Background())
|
||||
result, err := d.imageSvc().KernelList(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("KernelList: %v", err)
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ func TestKernelShowAndDeleteThroughDispatch(t *testing.T) {
|
|||
|
||||
func TestKernelShowMissingEntry(t *testing.T) {
|
||||
d := &Daemon{layout: paths.Layout{KernelsDir: t.TempDir()}}
|
||||
_, err := d.KernelShow(context.Background(), "nope")
|
||||
_, err := d.imageSvc().KernelShow(context.Background(), "nope")
|
||||
if err == nil || !strings.Contains(err.Error(), "not found") {
|
||||
t.Fatalf("KernelShow missing: err=%v", err)
|
||||
}
|
||||
|
|
@ -94,7 +94,7 @@ func TestKernelShowMissingEntry(t *testing.T) {
|
|||
|
||||
func TestKernelDeleteRejectsInvalidName(t *testing.T) {
|
||||
d := &Daemon{layout: paths.Layout{KernelsDir: t.TempDir()}}
|
||||
if err := d.KernelDelete(context.Background(), "../escape"); err == nil {
|
||||
if err := d.imageSvc().KernelDelete(context.Background(), "../escape"); err == nil {
|
||||
t.Fatalf("KernelDelete should reject traversal")
|
||||
}
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ func TestRegisterImageResolvesKernelRef(t *testing.T) {
|
|||
store: openDaemonStore(t),
|
||||
}
|
||||
|
||||
image, err := d.RegisterImage(context.Background(), api.ImageRegisterParams{
|
||||
image, err := d.imageSvc().RegisterImage(context.Background(), api.ImageRegisterParams{
|
||||
Name: "testbox",
|
||||
RootfsPath: rootfs,
|
||||
KernelRef: "void-6.12",
|
||||
|
|
@ -139,7 +139,7 @@ func TestRegisterImageRejectsKernelRefAndPath(t *testing.T) {
|
|||
layout: paths.Layout{KernelsDir: kernelsDir},
|
||||
store: openDaemonStore(t),
|
||||
}
|
||||
_, err := d.RegisterImage(context.Background(), api.ImageRegisterParams{
|
||||
_, err := d.imageSvc().RegisterImage(context.Background(), api.ImageRegisterParams{
|
||||
Name: "testbox",
|
||||
RootfsPath: rootfs,
|
||||
KernelRef: "void-6.12",
|
||||
|
|
@ -175,7 +175,7 @@ func TestKernelImportCopiesArtifactsAndWritesManifest(t *testing.T) {
|
|||
runner: system.NewRunner(),
|
||||
}
|
||||
|
||||
entry, err := d.KernelImport(context.Background(), api.KernelImportParams{
|
||||
entry, err := d.imageSvc().KernelImport(context.Background(), api.KernelImportParams{
|
||||
Name: "void-6.12",
|
||||
FromDir: src,
|
||||
Distro: "void",
|
||||
|
|
@ -210,7 +210,7 @@ func TestKernelPullRejectsUnknownCatalogEntry(t *testing.T) {
|
|||
layout: paths.Layout{KernelsDir: t.TempDir()},
|
||||
runner: system.NewRunner(),
|
||||
}
|
||||
_, err := d.KernelPull(context.Background(), api.KernelPullParams{Name: "unknown"})
|
||||
_, err := d.imageSvc().KernelPull(context.Background(), api.KernelPullParams{Name: "unknown"})
|
||||
if err == nil || !strings.Contains(err.Error(), "not in catalog") {
|
||||
t.Fatalf("KernelPull unknown: err=%v", err)
|
||||
}
|
||||
|
|
@ -224,7 +224,7 @@ func TestKernelPullRefusesOverwriteWithoutForce(t *testing.T) {
|
|||
layout: paths.Layout{KernelsDir: kernelsDir},
|
||||
runner: system.NewRunner(),
|
||||
}
|
||||
_, err := d.KernelPull(context.Background(), api.KernelPullParams{Name: "void-6.12"})
|
||||
_, err := d.imageSvc().KernelPull(context.Background(), api.KernelPullParams{Name: "void-6.12"})
|
||||
if err == nil || !strings.Contains(err.Error(), "already pulled") {
|
||||
t.Fatalf("KernelPull without --force: err=%v", err)
|
||||
}
|
||||
|
|
@ -232,7 +232,7 @@ func TestKernelPullRefusesOverwriteWithoutForce(t *testing.T) {
|
|||
|
||||
func TestKernelCatalogReportsPulledStatus(t *testing.T) {
|
||||
d := &Daemon{layout: paths.Layout{KernelsDir: t.TempDir()}}
|
||||
result, err := d.KernelCatalog(context.Background())
|
||||
result, err := d.imageSvc().KernelCatalog(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("KernelCatalog: %v", err)
|
||||
}
|
||||
|
|
@ -247,7 +247,7 @@ func TestKernelImportRejectsMissingFromDir(t *testing.T) {
|
|||
layout: paths.Layout{KernelsDir: t.TempDir()},
|
||||
runner: system.NewRunner(),
|
||||
}
|
||||
_, err := d.KernelImport(context.Background(), api.KernelImportParams{Name: "x"})
|
||||
_, err := d.imageSvc().KernelImport(context.Background(), api.KernelImportParams{Name: "x"})
|
||||
if err == nil || !strings.Contains(err.Error(), "--from") {
|
||||
t.Fatalf("KernelImport without --from: err=%v", err)
|
||||
}
|
||||
|
|
@ -262,7 +262,7 @@ func TestRegisterImageMissingKernelRef(t *testing.T) {
|
|||
layout: paths.Layout{KernelsDir: t.TempDir()},
|
||||
store: openDaemonStore(t),
|
||||
}
|
||||
_, err := d.RegisterImage(context.Background(), api.ImageRegisterParams{
|
||||
_, err := d.imageSvc().RegisterImage(context.Background(), api.ImageRegisterParams{
|
||||
Name: "testbox",
|
||||
RootfsPath: rootfs,
|
||||
KernelRef: "never-imported",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue