Documentation
¶
Index ¶
- func CollectAllSourceIDs() mapset.Set[string]
- func Count() int
- func GetRepo[T any](repoSet datastore.RepoSet) T
- func Names() []string
- func Register(p CatalogPlugin)
- func RegisterAllFlags(fs *flag.FlagSet)
- func RegisterDatastoreEntries(entries ...DatastoreEntry)
- func Reset()
- type BasePathProvider
- type CatalogLoader
- type CatalogPlugin
- type Config
- type DatastoreEntry
- type DatastoreSpecProvider
- type FileWatcher
- type FlagProvider
- type LeaderAware
- type LifecycleState
- type Migration
- type PluginBase
- type PluginBaseConfig
- type Registry
- type Reloader
- type Server
- func (s *Server) AddReadinessCheck(name string, fn func() bool)
- func (s *Server) Init(ctx context.Context) error
- func (s *Server) MountRoutes() (chi.Router, error)
- func (s *Server) NotifyLeader(ctx context.Context)
- func (s *Server) Plugins() []CatalogPlugin
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) Stop(ctx context.Context) error
- type ServerConfig
- type SourceIDProvider
- type SourceKeyProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectAllSourceIDs ¶
CollectAllSourceIDs queries all registered plugins that implement SourceIDProvider and returns the union of their known source IDs.
func GetRepo ¶
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 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 ¶
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.
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 ¶
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 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 ¶
FileWatcher provides file change notifications. basecatalog's monitor singleton satisfies this interface.
type FlagProvider ¶
FlagProvider is an optional interface that plugins can implement to register custom CLI flags before flag parsing.
type LeaderAware ¶
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).
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 (*Server) AddReadinessCheck ¶
AddReadinessCheck registers a readiness check evaluated by the /readyz handler alongside plugin health. Must be called before serving traffic.
func (*Server) Init ¶
Init discovers all registered plugins and initializes them. Fails fast on the first plugin Init error.
func (*Server) MountRoutes ¶
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 ¶
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.
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 ¶
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.