better startup flow

This commit is contained in:
ari committed 2026-11-01 14:20:13 -05:00
1 parent d7f5dba677
commit 650bcff83a
8 files changed
+345 -68

No files matched your search

+34
View File
@@ -35,6 +35,22 @@ const (
StateOffline State = "on an offline node"
)
type StartPhase string
const (
StartPlacing StartPhase = "placing"
StartBooting StartPhase = "booting"
StartRegistered StartPhase = "registered"
)
// StartEvent is only reported when Ensure really has to start the container.
type StartEvent struct {
Phase StartPhase
Node string
Drive string
Size model.Size
}
type Manager struct {
cfg *config.Config
store *state.Store
@@ -162,6 +178,13 @@ func (m *Manager) spec(u *model.Owner) node.StartSpec {
}
func (m *Manager) Ensure(ctx context.Context, id string, kind model.OwnerKind) (*model.Owner, error) {
return m.EnsureProgress(ctx, id, kind, nil)
}
func (m *Manager) EnsureProgress(ctx context.Context, id string, kind model.OwnerKind, progress func(StartEvent)) (*model.Owner, error) {
if progress == nil {
progress = func(StartEvent) {}
}
if m.IsMigrating(id) {
return nil, ErrMigrating
}
@@ -186,6 +209,7 @@ func (m *Manager) Ensure(ctx context.Context, id string, kind model.OwnerKind) (
defer m.startMu.Unlock()
if u.Node == "" {
progress(StartEvent{Phase: StartPlacing, Size: u.Size})
views, err := m.Views(ctx)
if err != nil {
return u, err
@@ -212,11 +236,13 @@ func (m *Manager) Ensure(ctx context.Context, id string, kind model.OwnerKind) (
return u, &node.NodeFullError{Node: u.Node}
}
log.Printf("container: starting %s for %s %s on %s (drive %s, %s)", u.Machine, u.Kind, u.ID, u.Node, u.Drive, u.Size)
progress(StartEvent{Phase: StartBooting, Node: u.Node, Drive: u.Drive, Size: u.Size})
if err := n.Start(ctx, m.spec(u)); err != nil {
log.Printf("container: starting %s on %s failed: %v", u.Machine, u.Node, err)
return u, err
}
log.Printf("container: %s is running on %s", u.Machine, u.Node)
progress(StartEvent{Phase: StartRegistered, Node: u.Node, Drive: u.Drive, Size: u.Size})
return u, nil
}
@@ -268,6 +294,14 @@ func (m *Manager) Poweroff(ctx context.Context, u *model.Owner) error {
return nil
}
func (m *Manager) WaitStopped(ctx context.Context, u *model.Owner) error {
n, err := m.nodeByName(u.Node)
if err != nil {
return err
}
return n.WaitStopped(ctx, u.Machine)
}
func (m *Manager) RunningOwners(ctx context.Context) []model.Owner {
byNodeMachine := map[string]model.Owner{}
for _, u := range m.store.Owners() {