modelmanager

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: EPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MaxConcurrentPulls is the global cap on in-flight model downloads.
	MaxConcurrentPulls = 2
	// DefaultPullTimeout is the default deadline for one model pull.
	DefaultPullTimeout = 6 * time.Hour

	OpStatusRunning   = "running"
	OpStatusSucceeded = "succeeded"
	OpStatusFailed    = "failed"
)
View Source
const (
	PruneModeDangling = "dangling"
)

Variables

View Source
var ErrLocalModelsDisabled = errors.New("local models are disabled while watchdog is enabled")

ErrLocalModelsDisabled is returned when local Model apply or pull is refused because watchdog is enabled.

Functions

func IdentityKey

func IdentityKey(registryID int, registryType, repo, revision string, files []string) string

IdentityKey is the pull identity: registry id + type + repo + revision + hash(files).

func RefuseLocalModelApply

func RefuseLocalModelApply() error

RefuseLocalModelApply returns ErrLocalModelsDisabled when watchdog is on.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager reconciles local Model desired state and orchestrates artifact pulls.

func New

func New(db *store.DB, modelsRoot string) *Manager

New constructs a Manager that reads desired models from db and writes under modelsRoot.

func (*Manager) ApplyControllerModels

func (m *Manager) ApplyControllerModels(ctx context.Context, items []*models.ControllerModel) error

ApplyControllerModels replaces the fleet-desired Model snapshot and upserts each row as a managed local Model. A managed Model occupies that on-disk name.

func (*Manager) ApplyManifest

func (m *Manager) ApplyManifest(doc *models.LocalModelManifest) (*models.LocalModel, error)

ApplyManifest upserts a validated Model document by metadata.name.

func (*Manager) Ensure

func (m *Manager) Ensure(needed int64) error

Ensure implements modelpull.DiskGuard.

func (*Manager) GetPull

func (m *Manager) GetPull(operationID string) (*PullOperation, bool)

GetPull returns a copy of one async pull operation.

func (*Manager) LoadDesired

func (m *Manager) LoadDesired() ([]*models.LocalModel, []*models.ControllerModel, error)

LoadDesired returns local Model rows plus any persisted controller Model rows.

func (*Manager) Prune

func (m *Manager) Prune(mode string) (*PruneReport, error)

Prune removes unused model artifacts. The only supported mode is dangling.

func (*Manager) PruneDangling

func (m *Manager) PruneDangling() (*PruneReport, error)

PruneDangling removes unused local models (rows and on-disk trees) that are not in the keep set, then drops unreferenced blobs.

func (*Manager) Reconcile

func (m *Manager) Reconcile(ctx context.Context) error

Reconcile compares desired local Models to on-disk state and starts pulls when needed.

func (*Manager) Remove

func (m *Manager) Remove(name string) error

Remove deletes one deployed model, its on-disk tree, and unused shared blobs.

func (*Manager) SaveControllerModels

func (m *Manager) SaveControllerModels(items []*models.ControllerModel) error

SaveControllerModels persists fleet-desired Model rows without starting a sync worker.

func (*Manager) SetDiskPolicy

func (m *Manager) SetDiskPolicy(directory string, thresholdPercent int64, stats func(path string) (free, total int64, err error))

SetDiskPolicy configures the free-space check used before a payload download.

func (*Manager) SetLiveConfig

func (m *Manager) SetLiveConfig(cfg *config.Config)

SetLiveConfig makes free-space checks read diskDirectory and availableDiskThreshold from the live Config singleton so CLI PATCH and controller config pushes apply without restarting the daemon.

func (*Manager) SetPullers

func (m *Manager) SetPullers(ociPuller, hfPuller Puller)

SetPullers replaces the OCI and Hugging Face adapters (tests).

func (*Manager) SetTimeout

func (m *Manager) SetTimeout(d time.Duration)

SetTimeout overrides the default pull deadline.

func (*Manager) StartPull

func (m *Manager) StartPull(name string) (*PullOperation, error)

StartPull begins an async pull for one model name. One in-flight pull per name; a second request returns the existing operation.

The caller context is not used after accept. Download runs on a detached background context so HTTP handlers can return 202 without canceling work.

func (*Manager) UpsertDesired

func (m *Manager) UpsertDesired(incoming *models.LocalModel) (*models.LocalModel, error)

UpsertDesired inserts or updates a local Model row, bumping generation on spec drift.

type PruneReport

type PruneReport struct {
	Mode         string   `json:"mode"`
	Removed      []string `json:"removed"`
	BlobsRemoved int      `json:"blobsRemoved"`
	StaleCleaned int      `json:"staleCleaned"`
}

PruneReport is the outcome of a model prune.

type PullOperation

type PullOperation struct {
	OperationID     string
	Status          string
	Progress        int
	BytesDownloaded int64
	BytesTotal      int64
	Name            string
	RegistryID      int
	Error           string
	StartedAt       time.Time
	EndedAt         *time.Time
}

PullOperation is the async pull status record (mirrors images:pull where sensible).

func (PullOperation) Snapshot

func (op PullOperation) Snapshot() map[string]any

Snapshot returns a JSON-ready view of the operation.

type Puller

type Puller interface {
	Pull(ctx context.Context, req modelpull.Request) (*modelpull.Result, error)
}

Puller downloads and materializes one model artifact.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL