plugins

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, f Factory)

Register adds a Factory under the given name. Intended to be called during host bootstrap or from an out-of-tree plugin's init().

Panics on duplicate names — extension wiring is a startup-time concern, and a silent overwrite would mask a programming error.

Types

type BasePlugin

type BasePlugin struct{}

BasePlugin provides no-op implementations for all Plugin hooks. Embed it in your plugin struct and override only the hooks you need.

func (BasePlugin) Name

func (BasePlugin) Name() string

func (BasePlugin) PreCreatePod

func (BasePlugin) PreCreatePool

func (BasePlugin) PreDeletePool

func (BasePlugin) PreUpdatePool

func (BasePlugin) Start

type Factory

type Factory func(h framework.Handle, args framework.Args) (Plugin, error)

Factory constructs a Plugin from shared runtime dependencies (Handle) and plugin-specific parameters (Args). Passing nil args is legal for plugins that take no parameters.

func Get

func Get(name string) (Factory, error)

Get looks up a registered Factory. Returns (nil, error) if the name is unknown.

type Plugin

type Plugin interface {
	// Name returns a unique identifier for this plugin (used in logs).
	Name() string

	// Start is called once during bootstrap, after the host has constructed
	// every plugin but before the reconciler begins processing. Plugins that
	// need their own informers (e.g. a ConfigMap-backed catalog) register
	// them here via the supplied framework.Handle.Cache(). A non-nil error
	// aborts program startup.
	Start(ctx context.Context, h framework.Handle) error

	// PreCreatePool is called after input validation and template resolution,
	// before the SandboxPool is persisted to Kubernetes.
	// The plugin may:
	//   - Mutate pool.Labels / pool.Annotations / pool.Spec
	//   - Read from input for context (auth info, caller-supplied metadata)
	//   - Reject by returning an error (ideally *AdmissionError with status hint)
	PreCreatePool(ctx context.Context, pool *agentsv1alpha1.SandboxPool) *domain.AppError

	// PreUpdatePool is called before the SandboxPool update is persisted.
	// oldPool is the current state; newPool is the state that will be written.
	// The plugin may mutate newPool or reject the operation.
	// Return updated=true if newPool was mutated and must be persisted to Kubernetes.
	PreUpdatePool(ctx context.Context, newPool *agentsv1alpha1.SandboxPool, pods []corev1.Pod) (updated bool, err *domain.AppError)

	// PreDeletePool is called before the SandboxPool is deleted from Kubernetes.
	// The plugin may reject the operation.
	PreDeletePool(ctx context.Context, pool *agentsv1alpha1.SandboxPool) *domain.AppError

	// PreCreatePod is called after the Pod object is fully assembled but BEFORE
	// it is submitted to Kubernetes. Plugins may mutate pod.Spec (e.g. inject
	// NodeAffinity). A non-nil error aborts pod creation for this attempt;
	// the reconciler will retry on the next tick.
	PreCreatePod(ctx context.Context, pod *corev1.Pod, pool *agentsv1alpha1.SandboxPool) *domain.AppError
}

Plugin defines lifecycle hooks for SandboxPool operations. Implement only the hooks you need; embed BasePlugin for no-op defaults.

func Build

func Build(name string, h framework.Handle, args framework.Args) (Plugin, error)

Build is a convenience helper: look up a Factory by name and invoke it. Equivalent to Get(name) followed by f(h, args).

type PluginManager

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

PluginManager holds an ordered list of plugins and executes them sequentially for each lifecycle hook.

A nil *PluginManager is safe to use — all Run* methods are no-ops. This is the expected state for the open-source build (no plugins registered).

func NewPluginManager

func NewPluginManager(plugins ...Plugin) *PluginManager

NewPluginManager creates a PluginManager with the given plugins. Returns nil if no plugins are provided, enabling the nil-safe fast path.

func (*PluginManager) PreCreatePodHooks

func (m *PluginManager) PreCreatePodHooks(ctx context.Context, pod *corev1.Pod, pool *agentsv1alpha1.SandboxPool) *domain.AppError

PreCreatePodHooks calls PreCreatePod on every registered plugin in order. Returns the first error encountered (short-circuits).

func (*PluginManager) PreCreatePool

func (m *PluginManager) PreCreatePool(ctx context.Context, pool *agentsv1alpha1.SandboxPool) *domain.AppError

PreCreatePool calls PreCreate on every registered plugin in order. Returns the first error encountered (short-circuits).

func (*PluginManager) PreDeletePool

func (m *PluginManager) PreDeletePool(ctx context.Context, pool *agentsv1alpha1.SandboxPool) *domain.AppError

PreDeletePool calls PreDelete on every registered plugin in order. Returns the first error encountered (short-circuits).

func (*PluginManager) PreUpdatePool

func (m *PluginManager) PreUpdatePool(ctx context.Context, newPool *agentsv1alpha1.SandboxPool, pods []corev1.Pod) (bool, *domain.AppError)

PreUpdatePool calls PreUpdate on every registered plugin in order. Returns updated=true if any plugin mutated newPool, and the first error encountered (short-circuits).

func (*PluginManager) Start

Start invokes Start on every registered plugin in order. If any plugin returns an error, Start stops and returns immediately — the caller should treat this as a fatal bootstrap failure.

Safe to call on a nil receiver (no-op).

Jump to

Keyboard shortcuts

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