Extract opstate and dmsnap into subpackages
Two leaves of the daemon package that carry no back-references to Daemon move out: - internal/daemon/opstate: generic Registry[T AsyncOp]. The AsyncOp interface methods are capitalised (ID, IsDone, UpdatedAt, Cancel); vmCreateOperationState and imageBuildOperationState implement it. - internal/daemon/dmsnap: Create, Cleanup, Remove plus the Handles type for device-mapper snapshot lifecycle. Takes an explicit Runner interface. The daemon-package snapshot.go keeps thin forwarders and a type alias so existing call sites and tests are untouched. Skipped on purpose: tap_pool has too many Daemon-scoped dependencies (config, store, closing, createTap) for a clean extraction at this stage; nat.go is already a thin facade over internal/hostnat; dns_routing.go tests tightly couple to package internals, so extraction would be more churn than payoff. Each can be revisited when a subsystem-level refactor forces the boundary. All tests green. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
59f2766139
commit
fdab4a7e68
7 changed files with 214 additions and 170 deletions
|
|
@ -11,10 +11,10 @@ import (
|
|||
"banger/internal/model"
|
||||
)
|
||||
|
||||
func (op *imageBuildOperationState) opID() string { return op.snapshot().ID }
|
||||
func (op *imageBuildOperationState) opIsDone() bool { return op.snapshot().Done }
|
||||
func (op *imageBuildOperationState) opUpdatedAt() time.Time { return op.snapshot().UpdatedAt }
|
||||
func (op *imageBuildOperationState) opCancel() { op.cancelOperation() }
|
||||
func (op *imageBuildOperationState) ID() string { return op.snapshot().ID }
|
||||
func (op *imageBuildOperationState) IsDone() bool { return op.snapshot().Done }
|
||||
func (op *imageBuildOperationState) UpdatedAt() time.Time { return op.snapshot().UpdatedAt }
|
||||
func (op *imageBuildOperationState) Cancel() { op.cancelOperation() }
|
||||
|
||||
type imageBuildProgressKey struct{}
|
||||
|
||||
|
|
@ -166,7 +166,7 @@ func (d *Daemon) BeginImageBuild(_ context.Context, params api.ImageBuildParams)
|
|||
}
|
||||
buildCtx, cancel := context.WithCancel(context.Background())
|
||||
op.setCancel(cancel)
|
||||
d.imageBuildOps.insert(op)
|
||||
d.imageBuildOps.Insert(op)
|
||||
go d.runImageBuildOperation(withImageBuildProgress(buildCtx, op), op, params)
|
||||
return op.snapshot(), nil
|
||||
}
|
||||
|
|
@ -181,7 +181,7 @@ func (d *Daemon) runImageBuildOperation(ctx context.Context, op *imageBuildOpera
|
|||
}
|
||||
|
||||
func (d *Daemon) ImageBuildStatus(_ context.Context, id string) (api.ImageBuildOperation, error) {
|
||||
op, ok := d.imageBuildOps.get(strings.TrimSpace(id))
|
||||
op, ok := d.imageBuildOps.Get(strings.TrimSpace(id))
|
||||
if !ok {
|
||||
return api.ImageBuildOperation{}, fmt.Errorf("image build operation not found: %s", id)
|
||||
}
|
||||
|
|
@ -189,7 +189,7 @@ func (d *Daemon) ImageBuildStatus(_ context.Context, id string) (api.ImageBuildO
|
|||
}
|
||||
|
||||
func (d *Daemon) CancelImageBuild(_ context.Context, id string) error {
|
||||
op, ok := d.imageBuildOps.get(strings.TrimSpace(id))
|
||||
op, ok := d.imageBuildOps.Get(strings.TrimSpace(id))
|
||||
if !ok {
|
||||
return fmt.Errorf("image build operation not found: %s", id)
|
||||
}
|
||||
|
|
@ -198,5 +198,5 @@ func (d *Daemon) CancelImageBuild(_ context.Context, id string) error {
|
|||
}
|
||||
|
||||
func (d *Daemon) pruneImageBuildOperations(olderThan time.Time) {
|
||||
d.imageBuildOps.prune(olderThan)
|
||||
d.imageBuildOps.Prune(olderThan)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue