Documentation
¶
Index ¶
- Constants
- func Copy(srcFile, dstFile string) error
- func CopyDir(dst, src string) error
- func CopyDirectory(scrDir, dest string) error
- func CopySymLink(source, dest string) error
- func CreateIfNotExists(dir string, perm os.FileMode) error
- func Exists(filePath string) bool
- func FindGoBinary() (string, error)
- func FindNodeBinary() (string, error)
- func FindPnpmBinary() (string, error)
- func HydrateBuildOpts(opts *types.BuildOpts) error
- func PrepareCommandWithBinaries(command string, args []string, binaries ...string) (*exec.Cmd, error)
- func ValidateForPhase(phase lifecycle.PluginPhase, meta config.PluginMeta, location string) error
- type CrashRecoveryState
- type DevServerChecker
- type HealthChecker
- type LoadPluginOptions
- type Manager
- type PluginBuilder
- type PluginPIDTracker
- type ReconcileResult
- type Reconciler
- type StateChangePayload
Constants ¶
const ( // Lifecycle state changes. EventStateChange = "plugin/state_change" // Install flow. EventInstallStarted = "plugin/install_started" EventInstallFinished = "plugin/install_finished" EventInstallError = "plugin/install_error" // Dev install flow. EventDevInstallStart = "plugin/dev_install_start" EventDevInstallError = "plugin/dev_install_error" EventDevInstallComplete = "plugin/dev_install_complete" // Plugin reload. EventReloadStart = "plugin/dev_reload_start" EventReloadError = "plugin/dev_reload_error" EventReloadComplete = "plugin/dev_reload_complete" // Update. EventUpdateStarted = "plugin/update_started" EventUpdateError = "plugin/update_error" EventUpdateComplete = "plugin/update_complete" // Initialization. EventInitComplete = "plugin/init_complete" // Crash recovery. EventCrashRecoveryFailed = "plugin/crash_recovery_failed" EventRecovered = "plugin/recovered" // State persistence. EventStateWriteError = "plugin/state_write_error" )
Plugin event constants.
const (
MaxPluginSize = 1024 * 1024 * 1024 // 1GB
)
Variables ¶
This section is empty.
Functions ¶
func CopyDirectory ¶
func CopySymLink ¶
func FindGoBinary ¶
FindGoBinary looks for the Go binary in a number of well-known paths in case it's not available in the PATH.
func FindNodeBinary ¶
FindNodeBinary tries to locate the Node.js binary across common install paths.
func FindPnpmBinary ¶
FindPnpmBinary looks for the Pnpm binary in a number of well-known paths in case it's not available in the PATH.
func HydrateBuildOpts ¶
HydrateBuildOpts adds the additional build options if they are not specified
func PrepareCommandWithBinaries ¶
func PrepareCommandWithBinaries( command string, args []string, binaries ...string, ) (*exec.Cmd, error)
PrepareCommandWithBinaries returns an exec.Cmd with extended PATH to include the directories of provided binary paths.
func ValidateForPhase ¶ added in v0.1.4
func ValidateForPhase(phase lifecycle.PluginPhase, meta config.PluginMeta, location string) error
ValidateForPhase checks that a plugin meets the requirements for the given phase.
Types ¶
type CrashRecoveryState ¶ added in v0.1.4
CrashRecoveryState tracks exponential backoff for a single plugin.
type DevServerChecker ¶
DevServerChecker allows the plugin manager to check if a plugin is managed by the dev server system.
type HealthChecker ¶ added in v0.1.4
type HealthChecker struct {
// contains filtered or unexported fields
}
HealthChecker periodically checks the health of running plugins and triggers crash recovery when issues are detected.
func NewHealthChecker ¶ added in v0.1.4
func NewHealthChecker(logger *zap.SugaredLogger, pm *pluginManager) *HealthChecker
NewHealthChecker creates a new HealthChecker.
func (*HealthChecker) CancelRecovery ¶ added in v0.1.4
func (hc *HealthChecker) CancelRecovery(pluginID string)
CancelRecovery cancels any in-progress crash recovery goroutine for the given plugin. This should be called when a plugin is uninstalled to prevent recovery loops.
func (*HealthChecker) HandleCrashWithBackoff ¶ added in v0.1.4
func (hc *HealthChecker) HandleCrashWithBackoff(pluginID string)
HandleCrashWithBackoff handles a plugin crash with exponential backoff. Uses an iterative loop instead of recursion to avoid stack growth.
func (*HealthChecker) Start ¶ added in v0.1.4
func (hc *HealthChecker) Start(ctx context.Context)
Start begins the periodic health check loop.
type LoadPluginOptions ¶
type LoadPluginOptions struct {
DevMode bool
DevModePath string
ExistingState *plugintypes.PluginStateRecord
}
LoadPluginOptions configures how a plugin is loaded.
type Manager ¶
type Manager interface {
Initialize(ctx context.Context) error
Run(ctx context.Context)
Shutdown()
InstallInDevMode() (*config.PluginMeta, error)
InstallFromPathPrompt() (*config.PluginMeta, error)
InstallPluginFromPath(path string) (*config.PluginMeta, error)
InstallPluginVersion(pluginID string, version string) (*config.PluginMeta, error)
LoadPlugin(id string, opts *LoadPluginOptions) (sdktypes.PluginInfo, error)
ReloadPlugin(id string) (sdktypes.PluginInfo, error)
UninstallPlugin(id string) (sdktypes.PluginInfo, error)
GetPlugin(id string) (sdktypes.PluginInfo, error)
ListPlugins() []sdktypes.PluginInfo
GetPluginMeta(id string) (config.PluginMeta, error)
ListPluginMetas() []config.PluginMeta
ListAvailablePlugins() ([]registry.AvailablePlugin, error)
SearchPlugins(query, category, sort string) ([]registry.AvailablePlugin, error)
GetPluginReadme(pluginID string) (string, error)
GetPluginVersions(pluginID string) ([]registry.VersionInfo, error)
GetPluginReviews(pluginID string, page int) ([]registry.Review, error)
GetPluginDownloadStats(pluginID string) (*registry.DownloadStats, error)
GetPluginReleaseHistory(pluginID string) ([]registry.VersionInfo, error)
HandlePluginCrash(pluginID string)
SetDevServerChecker(checker DevServerChecker)
SetDevServerManager(mgr *devserver.DevServerManager)
}
Manager manages the lifecycle and registration of plugins.
func NewManager ¶
func NewManager( logger *zap.SugaredLogger, resourceController resource.Controller, settingsController settings.Controller, execController pluginexec.Controller, networkerController networker.Controller, logsController pluginlogs.Controller, metricController pluginmetric.Controller, managers map[string]plugintypes.PluginManager, settingsProvider pkgsettings.Provider, registryClient *registry.Client, ) Manager
NewManager returns a new plugin manager.
type PluginBuilder ¶
type PluginBuilder struct{}
type PluginPIDTracker ¶
type PluginPIDTracker struct {
// contains filtered or unexported fields
}
PluginPIDTracker tracks PIDs of running plugin binary processes so that orphaned processes from a previous unclean shutdown (force-quit, crash, SIGKILL) can be cleaned up on the next startup.
On clean shutdown, client.Kill() already terminates plugin processes, so the saved PID file will typically be empty. The file only matters when shutdown was interrupted.
func NewPluginPIDTracker ¶
func NewPluginPIDTracker() *PluginPIDTracker
NewPluginPIDTracker creates a new tracker with an empty PID map.
func (*PluginPIDTracker) CleanupStale ¶
func (t *PluginPIDTracker) CleanupStale(logger *zap.SugaredLogger)
CleanupStale reads the PID file from a previous session, kills any processes that are still alive, and removes the file. This should be called early in Initialize(), before any new plugins are started.
func (*PluginPIDTracker) Record ¶
func (t *PluginPIDTracker) Record(pluginID string, pid int)
Record adds or updates the PID for a plugin. Called after a plugin binary is successfully started and the gRPC connection is established.
func (*PluginPIDTracker) Remove ¶
func (t *PluginPIDTracker) Remove(pluginID string)
Remove deletes the PID entry for a plugin. Called when a plugin is cleanly stopped via client.Kill().
func (*PluginPIDTracker) Save ¶
func (t *PluginPIDTracker) Save() error
Save persists the current pluginID→PID map to disk. This is called during Shutdown as a safety net — if all plugins were stopped cleanly the map is empty, but if shutdownPlugin failed for any plugin its PID will be saved for cleanup on the next startup.
type ReconcileResult ¶ added in v0.1.4
type ReconcileResult struct {
Records map[string]*plugintypes.PluginRecord
// Orphans are directories found on disk but not in persisted state.
Orphans []string
// Ghosts are entries in persisted state but not on disk.
Ghosts []string
}
ReconcileResult contains the reconciled plugin state.
type Reconciler ¶ added in v0.1.4
type Reconciler struct {
// contains filtered or unexported fields
}
Reconciler audits the filesystem against persisted state and produces a consistent set of plugin records for the manager.
func NewReconciler ¶ added in v0.1.4
func NewReconciler(logger *zap.SugaredLogger) *Reconciler
NewReconciler creates a new Reconciler.
func (*Reconciler) Reconcile ¶ added in v0.1.4
func (r *Reconciler) Reconcile( pluginDir string, persistedStates []plugintypes.PluginStateRecord, ) (*ReconcileResult, error)
Reconcile compares the filesystem with persisted state and produces a consistent set of plugin records.
func (*Reconciler) ReconcileFromFilesystem ¶ added in v0.1.4
func (r *Reconciler) ReconcileFromFilesystem( pluginDir string, ) (*ReconcileResult, error)
ReconcileFromFilesystem rebuilds state entirely from the filesystem. Used when the state file is corrupt or missing.
type StateChangePayload ¶ added in v0.1.4
type StateChangePayload struct {
PluginID string `json:"pluginID"`
From lifecycle.PluginPhase `json:"from"`
To lifecycle.PluginPhase `json:"to"`
Reason string `json:"reason"`
Timestamp time.Time `json:"timestamp"`
}
StateChangePayload is sent with EventStateChange.