manager

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: Apache-2.0 Imports: 21 Imported by: 6

Documentation

Overview

Package manager provides functionality for discovering, registering, and managing plugins. It supports registering plugins from a file system, loading them into appropriate registries, and managing their lifecycle. Precise life-cycle management is handled by the plugin client SDK. It has code that deals with start-up, shut-down etc. The manager is used for discovery and keeping track of plugins.

The Plugin Manager facilitates the use of plugins by:

  • Discovering plugins in a given location.
  • Registering component version repositories.

Plugin Management flow:

                  PLUGIN MANAGEMENT FLOW
                  ----------------------
                          |
                          v
+----------------------------------------------+
|  Manager discovers plugins on disk in folder |
+----------------------------------------------+
                          |
                          v
+----------------------------------------------+
|  For each discovered plugin, call            |
|  `capabilities` command that returns         |
|   JSON data via stdout                       |
+----------------------------------------------+
                          |
                          v
+----------------------------------------------+
|  Manager receives plugin's stderr stream     |
|  for ongoing log message forwarding          |
+----------------------------------------------+
                          |
                          v
+----------------------------------------------+
|  Manager stores plugin info (unstarted)      |
+----------------------------------------------+
                           |
                           |
+--------------------------+-----------------------------------------------+
|                                                                          |
v                                                                          v

+---------------------------------------------+ +---------------------------------------------+ | Elsewhere: Client requests plugin for | | GetReadWriteComponentVersionRepository... | | specific functionality using the right |<-->| attempts to find suitable plugin | | registry | +---------------------------------------------+ +---------------------------------------------+

|
v

+---------------------------------------------+ +---------------------------------------------+ | Function finds matching plugin from registry| -> | Found plugin is started | +---------------------------------------------+ +---------------------------------------------+

                                                                           |
                                                                           v
													+----------------------------------------------+
													| Plugin starts serving configured endpoints   |
													| - Handles REST calls (GetComponentVersion)   |
													| - Communicates via JSON payloads over UDS/TCP|
													+----------------------------------------------+

This shows how to register plugins found at a specified location (directory). The function scans the directory, finds plugins, and registers them.

package main

import (
    "context"
    "fmt"

    "example.com/manager"
)

func main() {
    ctx := context.Background()
    logger := slog.New(slog.NewTextHandler(os.Stdout))
    pm := manager.NewPluginManager(ctx, logger)

    err := pm.RegisterPlugins(ctx, "/path/to/plugins")
    if err != nil {
        fmt.Println("Error registering plugins:", err)
    }
}

This function will do two things. Find plugins, then figure out what type of plugins they are. The type of the plugin is determined through the capability it provides. For example, an OCMComponentVersionRepository type plugin which can discover component versions in given repository types ( i.e.: OCI Registry ) has a certain set of endpoints that identify it ( i.e.: AddComponentVersion, GetComponentVersion... ). This happens through an initial call to `capabilities` command on the plugin which will return a list of types and the type of the plugin constructed by one of the above Register* functions that can be used. This process is described in the `endpoints` package documentation.

Once the registration is successful, in order to get a plugin, call the appropriate function that gets back the right plugin. For example, for OCMComponentVersionRepository plugins the `Get*` function would be: `GetReadWriteComponentVersionRepositoryPluginForType`. Usage:

repo, err := componentversionrepository.GetReadWriteComponentVersionRepositoryPluginForType(ctx, registry, &spec, scheme)
r.NoError(err)

user, pass := "test", "password"

request := repov1.GetComponentVersionRequest[*v1.OCIRepository]{
	Repository: &spec,
	Name:       "ocm.software/ocmcli",
	Version:    "0.22.1",
}

desc, err := repo.GetComponentVersion(ctx, request, map[string]string{
	"username": user,
	"password": pass,
})

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPluginsFound = errors.New("no plugins found")

ErrNoPluginsFound is returned when a register plugin call finds no plugins.

Functions

This section is empty.

Types

type PluginManager

type PluginManager struct {
	// Registries containing various typed plugins. These should be called directly using the
	// plugin manager to locate a required plugin.
	ComponentVersionRepositoryRegistry *componentversionrepository.RepositoryRegistry
	CredentialRepositoryRegistry       *credentialrepository.RepositoryRegistry
	InputRegistry                      *input.RepositoryRegistry
	DigestProcessorRegistry            *digestprocessor.RepositoryRegistry
	ResourcePluginRegistry             *resource.ResourceRegistry
	BlobTransformerRegistry            *blobtransformer.Registry
	// contains filtered or unexported fields
}

PluginManager manages all connected plugins.

func NewPluginManager

func NewPluginManager(ctx context.Context) *PluginManager

NewPluginManager initializes the PluginManager the passed ctx is used for all plugins.

func (*PluginManager) RegisterPlugins

func (pm *PluginManager) RegisterPlugins(ctx context.Context, dir string, opts ...RegistrationOptionFn) error

RegisterPlugins walks through files in a folder and registers them as plugins if connection points can be established. This function doesn't support concurrent access.

func (*PluginManager) Shutdown

func (pm *PluginManager) Shutdown(ctx context.Context) error

Shutdown is called to terminate all plugins.

type RegistrationOptionFn

type RegistrationOptionFn func(*RegistrationOptions)

func WithConfiguration

func WithConfiguration(c *genericv1.Config) RegistrationOptionFn

WithConfiguration adds a configuration to the plugin.

func WithIdleTimeout

func WithIdleTimeout(d time.Duration) RegistrationOptionFn

WithIdleTimeout configures the maximum amount of time for a plugin to quit if it's idle.

type RegistrationOptions

type RegistrationOptions struct {
	IdleTimeout time.Duration
	Config      *genericv1.Config
}

Directories

Path Synopsis
Package contracts contains all the interface contracts for various capabilities of plugins.
Package contracts contains all the interface contracts for various capabilities of plugins.
digestprocessor/v1
Package v1 contains the contracts and types for OCM plugins dealing with digest information.
Package v1 contains the contracts and types for OCM plugins dealing with digest information.
input/v1
Package v1 contains the contracts and types for OCM plugins.
Package v1 contains the contracts and types for OCM plugins.
ocmrepository/v1
Package v1 contains the contracts and types for OCM plugins.
Package v1 contains the contracts and types for OCM plugins.
resource/v1
Package v1 contains the contracts and types for OCM plugins.
Package v1 contains the contracts and types for OCM plugins.
Package endpoints helps in constructing and tracking registered and declared types by plugins.
Package endpoints helps in constructing and tracking registered and declared types by plugins.
registries
componentversionrepository
Package componentversionrepository implements a plugin-based system for managing OCM component version repositories.
Package componentversionrepository implements a plugin-based system for managing OCM component version repositories.
digestprocessor
Package digestprocessor provides a registry for managing digest processor plugins.
Package digestprocessor provides a registry for managing digest processor plugins.
input
Package input provides a registry for managing input method plugins.
Package input provides a registry for managing input method plugins.
plugins
Package plugins provides various utilities and helpers for interacting with plugins, including sending HTTP requests to plugin endpoints, decoding request bodies, and validating plugin types against JSON schemas.
Package plugins provides various utilities and helpers for interacting with plugins, including sending HTTP requests to plugin endpoints, decoding request bodies, and validating plugin types against JSON schemas.
Package types contains the following types:
Package types contains the following types:

Jump to

Keyboard shortcuts

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