addon

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigImage = "_image"

ConfigImage is the well-known key used in variant config maps to pass the resolved container image to provider saga actions.

Variables

This section is empty.

Functions

func IsSharedVariant added in v0.7.0

func IsSharedVariant(variantName string) bool

IsSharedVariant returns true if the variant is a shared-server variant.

func NameFromRef

func NameFromRef(ref entity.Id) string

NameFromRef extracts the addon name from an entity reference like "addon/postgresql".

func ParseStorageGb added in v0.7.0

func ParseStorageGb(s string) int64

ParseStorageGb converts a Kubernetes-style size string (e.g. "1Gi", "50Gi") to an int64 value in gigabytes. Returns 1 if the string cannot be parsed.

func ResolveImage added in v0.7.0

func ResolveImage(baseImage, defaultVersion, requestedVersion string) string

ResolveImage returns the container image for the given version. If version is empty, the default version is used. If version contains ":", it is used as the full image reference. Otherwise, it is appended as a tag to the base image.

func SanitizeIdentifier added in v0.7.0

func SanitizeIdentifier(name string, maxLen int) string

SanitizeIdentifier converts a name into a safe database identifier by keeping only lowercase alphanumeric characters and underscores, converting uppercase to lowercase and hyphens to underscores, and truncating to maxLen.

Types

type AddonAssociation

type AddonAssociation struct {
	ID      entity.Id
	App     entity.Id
	Addon   entity.Id
	Variant string
	Entity  *entity.Entity
}

AddonAssociation holds the state needed for deprovisioning.

type AddonDefinition

type AddonDefinition struct {
	Name           string
	DisplayName    string
	Description    string
	DefaultVariant string
	Variants       []VariantDefinition
	BaseImage      string // container image without tag (e.g., "oci.miren.cloud/postgres")
	DefaultVersion string // default tag when no version is specified (e.g., "17")
}

AddonDefinition describes an addon's metadata and available variants.

type AddonProvider

type AddonProvider interface {
	// LocalityMode returns where this addon's backing resources run.
	LocalityMode() LocalityMode

	// Provision creates the backing resources for an addon and returns the
	// environment variables and entity attributes to store.
	Provision(ctx context.Context, app App, variant Variant) (*ProvisionResult, error)

	// AdjustEnvVars is called when provisioned env vars collide with existing
	// app env vars. The provider can rename or adjust variables.
	AdjustEnvVars(ctx context.Context, result *ProvisionResult, assoc AddonAssociation, collisions []string) ([]Variable, error)

	// Deprovision tears down the backing resources for an addon.
	Deprovision(ctx context.Context, assoc AddonAssociation) error
}

AddonProvider defines the interface that addon implementations must satisfy.

type App

type App struct {
	ID   entity.Id
	Name string
}

App identifies the application an addon is being attached to.

type CreateSandboxPoolSpec

type CreateSandboxPoolSpec struct {
	Name             string
	Image            string
	Env              []string
	Ports            []compute_v1alpha.SandboxSpecContainerPort
	DesiredInstances int64
	Labels           types.Labels
	SandboxPrefix    string
	Command          string
	Mounts           []compute_v1alpha.SandboxSpecContainerMount
	Volumes          []compute_v1alpha.SandboxSpecVolume
	// PortWaitTimeout overrides the sandbox controller's port-bind health
	// check budget. Parsed via time.ParseDuration (e.g. "60s"). Empty means
	// use the default (15s). Addons with slow cold-init should set this.
	PortWaitTimeout string
}

CreateSandboxPoolSpec describes the desired sandbox pool configuration.

type ImageChecker added in v0.7.0

type ImageChecker interface {
	CheckImage(ctx context.Context, image string) error
}

ImageChecker validates that a container image is accessible in its registry.

type LocalityMode added in v0.7.0

type LocalityMode string

LocalityMode describes where an addon's backing resources run.

const (
	// OnCluster means the addon runs within the Miren cluster.
	OnCluster LocalityMode = "on_cluster"
	// Remote means the addon connects to an external service.
	Remote LocalityMode = "remote"
)

type ProviderFramework

type ProviderFramework struct {
	EC      *entityserver.Client
	EAC     *entityserver_v1alpha.EntityAccessClient
	Storage saga.Storage
	Log     *slog.Logger
}

ProviderFramework provides common operations that addon providers need when creating backing infrastructure (pools, services, etc).

func NewProviderFramework

func NewProviderFramework(log *slog.Logger, ec *entityserver.Client, eac *entityserver_v1alpha.EntityAccessClient, storage saga.Storage) *ProviderFramework

NewProviderFramework creates a new provider framework.

func (*ProviderFramework) CreateSandboxPool

func (fw *ProviderFramework) CreateSandboxPool(ctx context.Context, spec CreateSandboxPoolSpec) (entity.Id, error)

CreateSandboxPool creates a fixed-mode SandboxPool entity.

func (*ProviderFramework) CreateService

func (fw *ProviderFramework) CreateService(ctx context.Context, name string, matchLabels types.Labels, port int64) (entity.Id, error)

CreateService creates a network Service entity that routes to pods matching the given labels.

func (*ProviderFramework) DeleteDiskByName added in v0.7.0

func (fw *ProviderFramework) DeleteDiskByName(ctx context.Context, diskName string) error

DeleteDiskByName finds a disk entity by its Name field and deletes it. Returns nil if no disk with that name exists.

func (*ProviderFramework) DeleteSandboxPool

func (fw *ProviderFramework) DeleteSandboxPool(ctx context.Context, poolID entity.Id) error

DeleteSandboxPool scales a pool to zero and then deletes it.

func (*ProviderFramework) DeleteService

func (fw *ProviderFramework) DeleteService(ctx context.Context, serviceID entity.Id) error

DeleteService deletes a network Service entity.

func (*ProviderFramework) GetServiceAddress

func (fw *ProviderFramework) GetServiceAddress(ctx context.Context, serviceID entity.Id) (string, error)

GetServiceAddress reads the Service entity and returns its first allocated IP.

func (*ProviderFramework) ScalePool

func (fw *ProviderFramework) ScalePool(ctx context.Context, poolID entity.Id, desired int64) error

ScalePool sets the desired instances on a pool.

func (*ProviderFramework) WaitForPool

func (fw *ProviderFramework) WaitForPool(ctx context.Context, poolID entity.Id, timeout time.Duration) error

WaitForPool watches a pool entity until it has at least one ready instance or the timeout is reached.

func (*ProviderFramework) WaitForServiceAddress

func (fw *ProviderFramework) WaitForServiceAddress(ctx context.Context, serviceID entity.Id, timeout time.Duration) (string, error)

WaitForServiceAddress watches a Service entity until it has an IP address or the timeout is reached.

type ProvisionResult

type ProvisionResult struct {
	EnvVars []Variable
	Attrs   []entity.Attr
}

ProvisionResult is returned by a provider after successful provisioning.

type Registry

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

Registry holds registered addon providers and their definitions.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new addon registry.

func (*Registry) EnsureEntities

func (r *Registry) EnsureEntities(ctx context.Context, ec *entityserver.Client) error

EnsureEntities creates or updates Addon entities in the entity store for each registered addon, so they can be discovered by the CLI and API.

func (*Registry) Get

Get returns the provider and definition for the named addon.

func (*Registry) GetVariantConfig

func (r *Registry) GetVariantConfig(addonName, variantName, version string) (map[string]string, error)

GetVariantConfig returns the provider-internal config for a specific variant, with the resolved container image injected under the ConfigImage key. If version is empty, the addon's default version is used.

func (*Registry) ListAddons

func (r *Registry) ListAddons() []AddonDefinition

ListAddons returns all registered addon definitions.

func (*Registry) Register

func (r *Registry) Register(name string, provider AddonProvider, def AddonDefinition)

Register adds an addon provider with its definition to the registry.

func (*Registry) ResolveAddonAndVariant

func (r *Registry) ResolveAddonAndVariant(spec string) (addonName, variantName string, err error)

ResolveAddonAndVariant parses a spec like "miren-postgresql:small" into addon name and variant name. If no variant is specified, the default variant is used.

type RegistryImageChecker added in v0.7.0

type RegistryImageChecker struct{}

RegistryImageChecker checks image accessibility by resolving the manifest against the remote registry.

func NewRegistryImageChecker added in v0.7.0

func NewRegistryImageChecker() *RegistryImageChecker

func (*RegistryImageChecker) CheckImage added in v0.7.0

func (c *RegistryImageChecker) CheckImage(ctx context.Context, image string) error

type Variable

type Variable struct {
	Key       string
	Value     string
	Sensitive bool
}

Variable represents an environment variable contributed by an addon.

type Variant

type Variant struct {
	Name   string
	Config map[string]string
}

Variant describes the variant selected for provisioning.

type VariantDefinition

type VariantDefinition struct {
	Name        string
	Description string
	Details     map[string]string // display key-value pairs shown to users
	Config      map[string]string // provider-internal configuration
}

VariantDefinition describes a single variant within an addon.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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