knowledgemanager

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 Knowledge downloads.
	// This pool is independent of Model pulls.
	MaxConcurrentPulls = 2
	// DefaultPullTimeout is the default deadline for one Knowledge pull.
	DefaultPullTimeout = 6 * time.Hour

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

Variables

View Source
var ErrLocalKnowledgeDisabled = errors.New("local knowledge is disabled while watchdog is enabled")

ErrLocalKnowledgeDisabled is returned when local Knowledge 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 RefuseLocalKnowledgeApply

func RefuseLocalKnowledgeApply() error

RefuseLocalKnowledgeApply returns ErrLocalKnowledgeDisabled when watchdog is on.

Types

type Manager

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

Manager reconciles local Knowledge desired state and orchestrates artifact pulls.

func New

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

New constructs a Manager that reads desired Knowledge from db and writes under knowledgeRoot.

func (*Manager) ActivePullNames

func (m *Manager) ActivePullNames() []string

ActivePullNames returns Knowledge names that currently have an in-flight pull.

func (*Manager) ApplyControllerKnowledge

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

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

func (*Manager) ApplyManifest

func (m *Manager) ApplyManifest(doc *models.LocalKnowledgeManifest) (*models.LocalKnowledge, error)

ApplyManifest upserts a validated Knowledge 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.LocalKnowledge, []*models.ControllerKnowledge, error)

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

func (*Manager) Prune

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

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

func (*Manager) PruneDangling

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

PruneDangling removes unused local Knowledge rows and trees that are not in the keep set, then drops unreferenced blobs in knowledge/oci-store/.

func (*Manager) Reconcile

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

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

func (*Manager) Remove

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

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

func (*Manager) SaveControllerKnowledge

func (m *Manager) SaveControllerKnowledge(items []*models.ControllerKnowledge) error

SaveControllerKnowledge persists fleet-desired Knowledge 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.

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 Knowledge 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.LocalKnowledge) (*models.LocalKnowledge, error)

UpsertDesired inserts or updates a local Knowledge 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 Knowledge 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.

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 Knowledge artifact.

Jump to

Keyboard shortcuts

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