plugin

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectAllSourceIDs

func CollectAllSourceIDs() mapset.Set[string]

CollectAllSourceIDs queries all registered plugins that implement SourceIDProvider and returns the union of their known source IDs.

func Count

func Count() int

Count returns the number of registered plugins.

func GetRepo

func GetRepo[T any](repoSet datastore.RepoSet) T

GetRepo extracts a typed repository from a RepoSet. Panics if the repository type is not found — this indicates a programming error in the datastore spec, not a runtime condition.

func Names

func Names() []string

Names returns all registered plugin names in registration order.

func Register

func Register(p CatalogPlugin)

Register adds a plugin to the global registry. This is typically called from a plugin's init() function. Panics if a plugin with the same name is already registered.

func RegisterAllFlags

func RegisterAllFlags(fs *flag.FlagSet)

RegisterAllFlags iterates all registered plugins and calls RegisterFlags on those implementing FlagProvider. Call this before flag.Parse().

func RegisterDatastoreEntries

func RegisterDatastoreEntries(entries ...DatastoreEntry)

RegisterDatastoreEntries adds datastore entries that will be collected by DatastoreSpec alongside plugin-contributed entries. This is used by test packages that can't import plugin packages due to circular dependencies.

func Reset

func Reset()

Reset clears the global registry and extra datastore entries. For testing only.

Types

type BasePathProvider

type BasePathProvider interface {
	BasePath() string
}

BasePathProvider is an optional interface that plugins can implement to specify their own API base path. If not implemented, the server computes it as /api/{name}_catalog/{version}.

type CatalogLoader

type CatalogLoader interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
}

CatalogLoader defines the interface for data loading strategies.

type CatalogPlugin

type CatalogPlugin interface {
	// Name returns the plugin name (e.g., "model", "dataset").
	// Used for routing and configuration lookup.
	Name() string

	// Version returns the API version (e.g., "v1alpha1").
	Version() string

	// Description returns a human-readable description of the plugin.
	Description() string

	// Init initializes the plugin with its configuration.
	// Called once during server startup before Start.
	Init(ctx context.Context, cfg Config) error

	// Start begins background operations (hot-reload, watchers, etc.).
	// Called after Init and after database migrations.
	Start(ctx context.Context) error

	// Stop gracefully shuts down the plugin.
	// Called during server shutdown.
	Stop(ctx context.Context) error

	// Healthy returns true if the plugin is functioning correctly.
	// Used for health check endpoints.
	Healthy() bool

	// RegisterRoutes mounts the plugin's HTTP routes on the provided router.
	// The router is the server's root router; plugins are responsible for
	// using full path patterns (e.g., "/api/model_catalog/v1alpha1/models").
	RegisterRoutes(router chi.Router) error

	// Migrations returns database migrations for this plugin.
	// Migrations are applied in order during server initialization.
	Migrations() []Migration
}

CatalogPlugin defines the interface that all catalog plugins must implement. Plugins register themselves via init() using the Register function.

func All

func All() []CatalogPlugin

All returns all registered plugins in registration order.

func Get

func Get(name string) (CatalogPlugin, bool)

Get returns a plugin by name. The returned boolean is true if the plugin is found, false otherwise.

type Config

type Config struct {
	// DB is the shared database connection.
	DB *gorm.DB

	// BasePath is the API base path for this plugin (e.g., "/api/model_catalog/v1alpha1").
	BasePath string

	// ConfigPaths are the paths to all sources.yaml files being used.
	ConfigPaths []string

	// RepoSet is the shared set of repositories from the datastore.
	RepoSet datastore.RepoSet

	// PerformanceMetricsPath holds paths to performance metrics data directories.
	PerformanceMetricsPath []string

	// Logger is a structured logger scoped to this plugin.
	Logger *slog.Logger
}

Config is passed to each plugin during Init.

type DatastoreEntry

type DatastoreEntry struct {
	TypeName string
	Category string // "context", "artifact", or "execution"
	Spec     *datastore.SpecType
}

DatastoreEntry describes a single entity type contributed by a plugin.

func ExtraDatastoreEntries

func ExtraDatastoreEntries() []DatastoreEntry

ExtraDatastoreEntries returns entries registered via RegisterDatastoreEntries.

type DatastoreSpecProvider

type DatastoreSpecProvider interface {
	DatastoreEntries() []DatastoreEntry
}

DatastoreSpecProvider is an optional interface that plugins implement to contribute their entity types to the shared DatastoreSpec. This avoids modifying spec.go when adding a new plugin.

type FileWatcher

type FileWatcher interface {
	Path(ctx context.Context, path string) (<-chan struct{}, error)
}

FileWatcher provides file change notifications. basecatalog's monitor singleton satisfies this interface.

type FlagProvider

type FlagProvider interface {
	RegisterFlags(fs *flag.FlagSet)
}

FlagProvider is an optional interface that plugins can implement to register custom CLI flags before flag parsing.

type LeaderAware

type LeaderAware interface {
	OnBecomeLeader(ctx context.Context) error
}

LeaderAware is an optional interface that plugins can implement to receive leadership notifications. When the pod becomes leader, the server calls OnBecomeLeader. The implementation should block until ctx is cancelled (leadership lost).

type LifecycleState

type LifecycleState interface {
	IsLeader() bool
	SetLeader(bool)
	ShouldWriteDatabase() bool
	SetupFileWatchers(ctx context.Context) (context.Context, error)
	StopFileWatchers()
	WaitForInflightWrites(timeout time.Duration)
	Paths() []string
}

LifecycleState provides shared state management for a plugin's lifecycle. basecatalog.BaseLoader satisfies this interface.

type Migration

type Migration struct {
	Version     string
	Description string
	Up          func(db *gorm.DB) error
	Down        func(db *gorm.DB) error
}

Migration represents a database migration for a plugin.

type PluginBase

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

PluginBase provides the shared lifecycle implementation for catalog plugins. Embed this in concrete plugin structs to get Start, Stop, OnBecomeLeader, Healthy, and KnownSourceIDs for free.

func NewPluginBase

func NewPluginBase(cfg PluginBaseConfig) *PluginBase

NewPluginBase creates a PluginBase with the given configuration.

func (*PluginBase) Healthy

func (pb *PluginBase) Healthy() bool

Healthy returns true if the plugin has not encountered any runtime errors.

func (*PluginBase) KnownSourceIDs

func (pb *PluginBase) KnownSourceIDs() mapset.Set[string]

KnownSourceIDs returns the set of source IDs this plugin manages.

func (*PluginBase) OnBecomeLeader

func (pb *PluginBase) OnBecomeLeader(ctx context.Context) error

OnBecomeLeader handles the full leader lifecycle: sets leader state, runs leader operations, calls the optional OnLeaderReady hook, then blocks until the context is cancelled (leadership lost).

func (*PluginBase) Start

func (pb *PluginBase) Start(ctx context.Context) error

Start sets up file watchers, parses all configs, and launches background goroutines to watch for config file changes.

func (*PluginBase) Stop

func (pb *PluginBase) Stop(_ context.Context) error

Stop cancels file watchers and waits for inflight writes.

type PluginBaseConfig

type PluginBaseConfig struct {
	// Name is used for log messages and error wrapping.
	Name string

	// State manages leader election, file watchers, and write tracking.
	State LifecycleState

	// Loader performs config parsing and leader write operations.
	Loader Reloader

	// SourceIDs returns the set of source IDs known to this plugin.
	SourceIDs func() mapset.Set[string]

	// FileWatcher provides file change notifications.
	FileWatcher FileWatcher

	// OnLeaderReady is called after leader operations succeed.
	// Optional — nil means no post-leader hook.
	OnLeaderReady func(ctx context.Context) error
}

PluginBaseConfig holds the dependencies needed to construct a PluginBase.

type Registry

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

Registry holds all registered catalog plugins.

type Reloader

type Reloader interface {
	ParseAllConfigs() error
	ReloadParsing() error
	PerformLeaderOperations(ctx context.Context, allKnownSourceIDs mapset.Set[string]) error
}

Reloader defines the operations a concrete loader must provide for the shared plugin lifecycle (PluginBase) to work. Both modelcatalog.ModelLoader and mcpcatalog.MCPLoader satisfy this.

type Server

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

Server manages the lifecycle of catalog plugins and provides a unified HTTP server.

func NewServer

func NewServer(cfg ServerConfig) *Server

NewServer creates a new plugin server.

func (*Server) AddReadinessCheck

func (s *Server) AddReadinessCheck(name string, fn func() bool)

AddReadinessCheck registers a readiness check evaluated by the /readyz handler alongside plugin health. Must be called before serving traffic.

func (*Server) Init

func (s *Server) Init(ctx context.Context) error

Init discovers all registered plugins and initializes them. Fails fast on the first plugin Init error.

func (*Server) MountRoutes

func (s *Server) MountRoutes() (chi.Router, error)

MountRoutes creates the HTTP router with all plugin routes and server endpoints. Returns an error if any plugin fails to register its routes.

func (*Server) NotifyLeader

func (s *Server) NotifyLeader(ctx context.Context)

NotifyLeader notifies all LeaderAware plugins that this pod became leader. Each plugin's OnBecomeLeader runs in its own goroutine; this method blocks until all return (typically when ctx is cancelled / leadership lost).

func (*Server) Plugins

func (s *Server) Plugins() []CatalogPlugin

Plugins returns the list of initialized plugins.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start starts all plugins' background operations.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop gracefully shuts down all plugins in reverse order.

type ServerConfig

type ServerConfig struct {
	DB                     *gorm.DB
	ConfigPaths            []string
	PerformanceMetricsPath []string
	RepoSet                datastore.RepoSet
	Logger                 *slog.Logger
}

ServerConfig holds the dependencies needed to create a plugin Server.

type SourceIDProvider

type SourceIDProvider interface {
	KnownSourceIDs() mapset.Set[string]
}

SourceIDProvider is an optional interface that plugins can implement to expose their known source IDs. Used during leader operations to collect the union of all source IDs across plugins, preventing cross-contamination when cleaning up shared CatalogSource records.

type SourceKeyProvider

type SourceKeyProvider interface {
	SourceKey() string
}

SourceKeyProvider is an optional interface that plugins can implement to specify which key in sources.yaml they respond to. If not implemented, the plugin name is used as the config key.

Jump to

Keyboard shortcuts

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