controller

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package controller implements the edge function controller that manages per-namespace edge runtimes with multiple dynamically-loaded functions.

Index

Constants

View Source
const (
	// DefaultControlPort is the default port for the edge-runtime control API.
	DefaultControlPort = 9000

	// DefaultServicePort is the default port for serving requests.
	DefaultServicePort = 8080
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerRuntime

type ContainerRuntime interface {
	// ExecNamespace creates and starts a new edge-runtime container for a namespace.
	ExecNamespace(ctx context.Context, id string, eszipDir string, servicePort, controlPort int) error

	// StopExec stops the execution of a container.
	StopExec(ctx context.Context, id string) error

	// DeleteExec deletes a container.
	DeleteExec(ctx context.Context, id string) error

	// ExecStatus returns the status of a container.
	ExecStatus(ctx context.Context, id string) (edgefunc.Status, error)

	// ListExecs returns all container executions.
	ListExecs(ctx context.Context) ([]edgefunc.Status, error)

	// Network returns the network manager for the runtime.
	Network() *network.Network
}

ContainerRuntime is the interface for creating and managing containers. This abstracts the runc runtime to allow for testing and potential future implementations (e.g., containerd, docker).

type EdgeController

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

EdgeController manages per-namespace edge runtimes with dynamically-loaded functions.

func NewEdgeController

func NewEdgeController(
	runtimeManager RuntimeManager,
	functionDeployer FunctionDeployer,
	functionRouter FunctionRouter,
	opts ...EdgeControllerOption,
) *EdgeController

NewEdgeController creates a new EdgeController.

func NewEdgeControllerFromRuntime

func NewEdgeControllerFromRuntime(runtime ContainerRuntime, eszipDir string, defaultNS Namespace) *EdgeController

NewEdgeControllerFromRuntime creates a fully-wired EdgeController from a ContainerRuntime.

func (*EdgeController) Deploy

Deploy deploys an EdgeFunctionRevision to the appropriate namespace runtime. If namespace is empty, uses the default namespace.

func (*EdgeController) FunctionDeployer

func (c *EdgeController) FunctionDeployer() FunctionDeployer

FunctionDeployer returns the function deployer (for advanced use cases).

func (*EdgeController) FunctionRouter

func (c *EdgeController) FunctionRouter() FunctionRouter

FunctionRouter returns the function router (for advanced use cases).

func (*EdgeController) GetFunctionStatus

func (c *EdgeController) GetFunctionStatus(ctx context.Context, namespace Namespace, functionID FunctionID) (*FunctionInfo, error)

GetFunctionStatus returns the status of a deployed function.

func (*EdgeController) GetRuntimeAddress

func (c *EdgeController) GetRuntimeAddress(ctx context.Context, namespace Namespace) (netip.Addr, int, error)

GetRuntimeAddress returns the address and port for a namespace's runtime.

func (*EdgeController) ListRuntimes

func (c *EdgeController) ListRuntimes(ctx context.Context) ([]*RuntimeInfo, error)

ListRuntimes returns all active runtimes.

func (*EdgeController) ResolveFunctionID

func (c *EdgeController) ResolveFunctionID(ctx context.Context, namespace Namespace, functionName string) (FunctionID, error)

ResolveFunctionID resolves a function name to its active function ID.

func (*EdgeController) Resolver

func (c *EdgeController) Resolver(next plugin.Handler) plugin.Handler

Resolver returns a DNS plugin handler for resolving edge function names. This implements the dns.Plugin interface for CoreDNS integration.

func (*EdgeController) RuntimeManager

func (c *EdgeController) RuntimeManager() RuntimeManager

RuntimeManager returns the runtime manager (for advanced use cases).

func (*EdgeController) TerminateRuntime

func (c *EdgeController) TerminateRuntime(ctx context.Context, namespace Namespace) error

TerminateRuntime terminates the runtime for a namespace.

func (*EdgeController) Undeploy

func (c *EdgeController) Undeploy(ctx context.Context, namespace Namespace, functionID FunctionID) error

Undeploy removes a function from its runtime.

type EdgeControllerOption

type EdgeControllerOption func(*EdgeController)

EdgeControllerOption configures an EdgeController.

func WithDefaultNamespace

func WithDefaultNamespace(ns Namespace) EdgeControllerOption

WithDefaultNamespace sets the default namespace for the controller.

type FunctionDeployer

type FunctionDeployer interface {
	// Deploy deploys an EdgeFunctionRevision to the appropriate runtime.
	Deploy(ctx context.Context, namespace Namespace, rev *extensionsv1alpha2.EdgeFunctionRevision) error

	// Undeploy removes a function from its runtime.
	Undeploy(ctx context.Context, namespace Namespace, functionID FunctionID) error

	// GetFunctionStatus returns the status of a deployed function.
	GetFunctionStatus(ctx context.Context, namespace Namespace, functionID FunctionID) (*FunctionInfo, error)
}

FunctionDeployer handles deploying functions to runtimes.

func NewFunctionDeployer

func NewFunctionDeployer(runtimeManager RuntimeManager, router FunctionRouter) FunctionDeployer

NewFunctionDeployer creates a new FunctionDeployer.

type FunctionHealthStatus

type FunctionHealthStatus struct {
	Ready bool   `json:"ready"`
	Error string `json:"error,omitempty"`
}

FunctionHealthStatus represents the health status of a single function.

type FunctionID

type FunctionID string

FunctionID uniquely identifies a function within a namespace. Typically derived from the EdgeFunctionRevision ref.

type FunctionInfo

type FunctionInfo struct {
	// FunctionID is the unique identifier for this function.
	FunctionID FunctionID

	// FunctionName is the human-readable name of the function.
	FunctionName string

	// RevisionRef is the EdgeFunctionRevision ref (e.g., hash of the code).
	RevisionRef string

	// EszipPath is the path to the eszip file inside the container.
	EszipPath string

	// Ready indicates whether the function has been bootstrapped and is ready to serve.
	Ready bool

	// ColdStartMs is the cold start time in milliseconds (from /_internal/ready response).
	ColdStartMs int64

	// LoadedAt is when the function was loaded into the runtime.
	LoadedAt time.Time
}

FunctionInfo contains information about a function loaded in a runtime.

type FunctionRouter

type FunctionRouter interface {
	// Resolve returns the FunctionID for a given function name in a namespace.
	// Returns the currently active revision's function ID.
	Resolve(ctx context.Context, namespace Namespace, functionName string) (FunctionID, error)

	// SetActiveRevision sets the active function ID for a function name.
	SetActiveRevision(ctx context.Context, namespace Namespace, functionName string, functionID FunctionID) error

	// GetRuntimeAddress returns the address and service port for a namespace's runtime.
	GetRuntimeAddress(ctx context.Context, namespace Namespace) (address netip.Addr, port int, err error)

	// RemoveFunction removes a function name mapping.
	RemoveFunction(ctx context.Context, namespace Namespace, functionName string) error
}

FunctionRouter tracks active function→runtime mappings and provides resolution.

func NewFunctionRouter

func NewFunctionRouter(runtimeManager RuntimeManager) FunctionRouter

NewFunctionRouter creates a new FunctionRouter.

type HealthResponse

type HealthResponse struct {
	Functions map[string]FunctionHealthStatus `json:"functions"`
}

HealthResponse is the response body from /_internal/health.

type Namespace

type Namespace string

Namespace represents a logical grouping of functions (e.g., project ID).

type ReadyRequest

type ReadyRequest struct {
	FunctionID string `json:"function_id"`
}

ReadyRequest is the request body for /_internal/ready.

type ReadyResponse

type ReadyResponse struct {
	Ready       bool  `json:"ready"`
	ColdStartMs int64 `json:"cold_start_ms"`
}

ReadyResponse is the response body from /_internal/ready.

type RuntimeClient

type RuntimeClient interface {
	// Upload registers a new function with the runtime.
	Upload(ctx context.Context, req UploadRequest) error

	// Ready bootstraps a worker for the function and returns readiness status.
	Ready(ctx context.Context, functionID string) (*ReadyResponse, error)

	// Health returns the health status of all functions in the runtime.
	Health(ctx context.Context) (*HealthResponse, error)

	// DeleteFunction unloads a function from the runtime.
	DeleteFunction(ctx context.Context, functionID string) error
}

RuntimeClient is the interface for communicating with an edge-runtime's control API.

func NewRuntimeClient

func NewRuntimeClient(address netip.Addr, port int) RuntimeClient

NewRuntimeClient creates a new client for communicating with an edge-runtime instance.

func NewRuntimeClientWithURL

func NewRuntimeClientWithURL(baseURL string) RuntimeClient

NewRuntimeClientWithURL creates a new client with a specific base URL.

type RuntimeInfo

type RuntimeInfo struct {
	// Namespace this runtime belongs to.
	Namespace Namespace

	// ContainerID is the container identifier (e.g., "edge-runtime-{namespace}").
	ContainerID string

	// Address is the IPv4 address of the runtime container.
	Address netip.Addr

	// ControlPort is the port for the control API (default 9000).
	ControlPort int

	// ServicePort is the port for serving requests (default 8080).
	ServicePort int

	// EszipDir is the host directory where eszip files are stored for this runtime.
	EszipDir string

	// Functions maps function IDs to their info for functions loaded in this runtime.
	Functions map[FunctionID]*FunctionInfo

	// CreatedAt is when the runtime was created.
	CreatedAt time.Time
	// contains filtered or unexported fields
}

RuntimeInfo contains information about a running edge-runtime container for a specific namespace.

func (*RuntimeInfo) DeleteFunction

func (r *RuntimeInfo) DeleteFunction(id FunctionID)

DeleteFunction removes function info, thread-safe.

func (*RuntimeInfo) GetFunction

func (r *RuntimeInfo) GetFunction(id FunctionID) (*FunctionInfo, bool)

GetFunction returns function info by ID, thread-safe.

func (*RuntimeInfo) ListFunctions

func (r *RuntimeInfo) ListFunctions() []FunctionID

ListFunctions returns all function IDs in this runtime, thread-safe.

func (*RuntimeInfo) SetFunction

func (r *RuntimeInfo) SetFunction(id FunctionID, info *FunctionInfo)

SetFunction sets function info, thread-safe.

type RuntimeManager

type RuntimeManager interface {
	// EnsureRuntime ensures a runtime exists for the given namespace.
	// Creates one if it doesn't exist.
	EnsureRuntime(ctx context.Context, namespace Namespace) (*RuntimeInfo, error)

	// GetRuntime returns the runtime info for a namespace, or nil if not exists.
	GetRuntime(ctx context.Context, namespace Namespace) (*RuntimeInfo, error)

	// TerminateRuntime stops and removes the runtime for a namespace.
	TerminateRuntime(ctx context.Context, namespace Namespace) error

	// ListRuntimes returns all active runtimes.
	ListRuntimes(ctx context.Context) ([]*RuntimeInfo, error)
}

RuntimeManager manages the lifecycle of per-namespace edge-runtime containers.

func NewRuntimeManager

func NewRuntimeManager(containerRuntime ContainerRuntime, opts ...RuntimeManagerOption) RuntimeManager

NewRuntimeManager creates a new RuntimeManager.

type RuntimeManagerOption

type RuntimeManagerOption func(*runtimeManagerImpl)

RuntimeManagerOption configures a RuntimeManager.

func WithBaseEszipDir

func WithBaseEszipDir(dir string) RuntimeManagerOption

WithBaseEszipDir sets the base directory for eszip files.

type UploadRequest

type UploadRequest struct {
	FunctionID   string `json:"function_id"`
	FunctionName string `json:"function_name"`
	EszipPath    string `json:"eszip_path"`
}

UploadRequest is the request body for /_internal/upload.

Jump to

Keyboard shortcuts

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