Documentation
¶
Index ¶
- Constants
- type Package
- type RemovalState
- type Store
- func (s *Store) Delete(name string) bool
- func (s *Store) GetPendingMaintenance(name string) string
- func (s *Store) GetPendingSettings(name string) (addonutils.Values, int)
- func (s *Store) HandleEvent(event int, name string) context.Context
- func (s *Store) NeedUpdate(name, version, checksum string, settingsVersion int, maintenance string) bool
- func (s *Store) RemovalState(name string) RemovalState
- func (s *Store) Update(name, version string, settingsVersion int, settings addonutils.Values, ...) context.Context
- func (s *Store) UpdateSettings(name string, settingsVersion int, settings addonutils.Values) bool
Constants ¶
const ( EventUpdate = iota EventRemove EventSchedule )
Event types determine context cancellation behavior in newContext.
Root events (EventUpdate, EventRemove) cancel the entire context tree and create a fresh root. All in-flight tasks for the package see ctx.Done().
Child events (EventSchedule) cancel only the previous context for the same event key, then create a new child of the current root.
EventSchedule is shared by both enable and disable flows, providing mutual cancellation: enabling cancels a pending disable and vice versa.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Package ¶
type Package struct {
// contains filtered or unexported fields
}
Package holds the lifecycle state for a single runtime package: version tracking, pending settings, and a tree of cancellable contexts for coordinating concurrent operations.
Package does not hold the loaded runtime instance (Application/Module) — those live in plain maps on Runtime. This keeps the Store type-agnostic.
Context hierarchy:
root (ctx/cancel) — created by EventUpdate or EventRemove └── EventSchedule child — cancelled on enable↔disable transition
type RemovalState ¶ added in v1.77.2
type RemovalState int
RemovalState reports how far a package's teardown has got.
const ( // RemovalDone means nothing is tracked under the name, so nothing is left to tear down. RemovalDone RemovalState = iota // RemovalPending means the package is still tracked and no teardown has been issued yet. RemovalPending // RemovalInFlight means a teardown is already enqueued; re-issuing EventRemove would cancel it. RemovalInFlight )
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages lifecycle contexts and pending settings for all runtime packages. It is type-agnostic — it does not hold the loaded Application/Module instances, only the version, settings, and context tree needed for change detection and cancellation. The actual runtime instances live in plain maps on Runtime.
Store is not thread-safe; callers must hold Runtime.mu before calling any method.
func (*Store) Delete ¶
Delete removes a package entry from the store if it still exists and is in the removed state set by HandleEvent(EventRemove). Returns true if the entry was deleted.
Safe against re-creation races: Update clears the removal marker before this cleanup, so Delete returns false and preserves the re-created entry.
func (*Store) GetPendingMaintenance ¶ added in v1.77.0
GetPendingMaintenance returns the latest maintenance mode stored for a package. Called by schedulePackage to pass the current mode into the Run task. Empty means the package is managed normally.
func (*Store) GetPendingSettings ¶ added in v1.76.0
func (s *Store) GetPendingSettings(name string) (addonutils.Values, int)
GetPendingSettings returns the latest settings and their schema version stored for a package. Called by schedulePackage to pass current settings and version into the Configure task so it can convert from the stored version to latest. This late-binding approach ensures settings changes that arrive between Update and schedule are automatically picked up.
func (*Store) HandleEvent ¶
HandleEvent renews the context for the given event type and returns it.
For EventRemove: clears version and settings before renewing context, so a subsequent Update sees the package as new (enabling re-create after remove).
Returns nil if the package doesn't exist in the store, or if EventSchedule arrives after removal has started and must not supersede teardown.
func (*Store) NeedUpdate ¶ added in v1.76.0
func (s *Store) NeedUpdate(name, version, checksum string, settingsVersion int, maintenance string) bool
NeedUpdate reports whether the package needs processing: true if the package is new or being removed, the version changed, the settings checksum differs, the settings schema version changed, or the maintenance mode changed. Used as a fast-path check before the more expensive Update call.
func (*Store) RemovalState ¶ added in v1.77.2
func (s *Store) RemovalState(name string) RemovalState
RemovalState reports the teardown state of a package. The explicit removal marker lets callers wait instead of re-issuing EventRemove, independently of whether the package version is empty.
func (*Store) Update ¶
func (s *Store) Update(name, version string, settingsVersion int, settings addonutils.Values, maintenance string) context.Context
Update registers a new package or processes a version change.
Returns a new root context (EventUpdate) when:
- Package not in store → creates entry, returns root context
- Version differs → cancels all in-flight tasks, returns new root context
- Package is being removed → cancels teardown and starts the re-created generation
Returns nil when only settings, settingsVersion or maintenance changed (no new context needed — the new values are stored and will be picked up by the scheduler via GetPendingSettings/GetPendingMaintenance on next Reschedule, or by the next Configure task in the schedule pipeline).
Callers should check for nil: a nil return with a settings- or maintenance-only change means the caller should trigger Reschedule to re-apply them.
func (*Store) UpdateSettings ¶ added in v1.77.0
UpdateSettings stores new pending settings and their schema version for an already-tracked package without touching its version or context tree. Returns true if the settings checksum or settingsVersion changed and the caller should Reschedule, false if nothing changed or the package is not tracked yet.
Unlike Update, this never creates or cancels a context: in-flight deploy and load tasks are left running. It is the settings-only counterpart to Update, used when settings change independently of a version change. The ModuleConfig enabled intent is tracked separately by the global module, not here.