feat(plugins): load plugin and secret-engine files without a restart
docs/prds/plugin-settings-live.md: a `plugin-settings` change now applies live for plugin_dir, module_dir and secret_engine_dir, and a file dropped into any of those directories loads on the reconciliation tick. - PluginSettingsKind moves to ApplyMode "live" and joins runtimeResourceKinds, so a stored directory change re-layers immediately. - A reconciler re-runs the directory loads and the layering on the apply-status restamp interval. Files are content-hashed, so only new and changed files load. - plugin.Host grows Add and Replace for the running state (Register keeps its pre-Start rule), and plugin.LoadFile / secret.Registry.LoadFile are the single-file load paths the boot loader and the reconciler share. - Yaegi cannot unload, so a removed file keeps running and the removal is reported through apply status against the live version until restart; a clean pass clears it. - A plugin-settings document that changes skills_dir is refused before the layering, since skills_dir has no live consumer. - applystatus.Reporter.AppliedVersion lets the reconciliation report an outcome without resetting the version to zero.
This commit is contained in:
1 parent
e6f90b99e8
commit
9c0ac87ecf
13 files changed
+1162
-53
No files matched your search
+22
-15
@@ -56,25 +56,32 @@ func LoadDir(dir string, extraSymbols ...map[string]map[string]reflect.Value) ([
|
||||
|
||||
plugins := make([]Plugin, 0)
|
||||
for _, name := range names {
|
||||
path := filepath.Join(dir, name)
|
||||
src, err := os.ReadFile(path)
|
||||
p, err := LoadFile(filepath.Join(dir, name), extraSymbols...)
|
||||
if err != nil {
|
||||
slog.Default().Warn("skipping unreadable daemon plugin", "file", name, "err", err)
|
||||
continue
|
||||
}
|
||||
// Each plugin file is package main -- must use a fresh interpreter
|
||||
// to avoid symbol collisions between files.
|
||||
i, err := yaegiutil.New(interp.Options{}, extraSymbols...)
|
||||
if err != nil {
|
||||
slog.Default().Warn("skipping plugin -- interpreter setup failed", "file", name, "err", err)
|
||||
continue
|
||||
}
|
||||
p, err := yaegiutil.Resolve[Plugin](i, string(src), "main.Plugin")
|
||||
if err != nil {
|
||||
slog.Default().Warn("skipping plugin", "file", name, "err", err)
|
||||
slog.Default().Warn("skipping daemon plugin", "file", name, "err", err)
|
||||
continue
|
||||
}
|
||||
plugins = append(plugins, p)
|
||||
}
|
||||
return plugins, nil
|
||||
}
|
||||
|
||||
// LoadFile evaluates one plugin file. Each file is package main and needs a
|
||||
// fresh interpreter to avoid symbol collisions with the other files, so the
|
||||
// boot load (LoadDir) and a live directory reconciliation both load through
|
||||
// here rather than through two copies of the interpreter setup.
|
||||
func LoadFile(path string, extraSymbols ...map[string]map[string]reflect.Value) (Plugin, error) {
|
||||
src, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read plugin %s: %w", path, err)
|
||||
}
|
||||
i, err := yaegiutil.New(interp.Options{}, extraSymbols...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("plugin %s: interpreter setup: %w", path, err)
|
||||
}
|
||||
p, err := yaegiutil.Resolve[Plugin](i, string(src), "main.Plugin")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("plugin %s: %w", path, err)
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
Reference in new issue
Block a user