network

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionTypeTestConnection ActionType = "test_connection"

	StatusStateUnknown      StatusState = "unknown"
	StatusStateReady        StatusState = "ready"
	StatusStateNeedsConfig  StatusState = "needs_config"
	StatusStateUnauthorized StatusState = "unauthorized"
)

Variables

View Source
var ErrNotSupported = errors.New("network operation not supported")

ErrNotSupported indicates the selected runtime or overlay driver cannot report a requested capability yet.

View Source
var ErrWorkspaceContainerMissing = errors.New("workspace is not created")

Functions

func NormalizeConfigBySchema

func NormalizeConfigBySchema(schema ConfigSchema, raw map[string]any) map[string]any

func ValidateConfigBySchema

func ValidateConfigBySchema(schema ConfigSchema, raw map[string]any) error

Types

type ActionType

type ActionType string

type AttachmentRequest

type AttachmentRequest struct {
	BotID       string
	ContainerID string
	Runtime     RuntimeNetworkRequest
	Overlay     BotOverlayConfig
	OverlayOnly bool // When true, skip runtime network setup/teardown (overlay-only mutation).
}

type AttachmentStatus

type AttachmentStatus struct {
	Runtime RuntimeNetworkStatus
	Overlay OverlayStatus
}

AttachmentStatus reports the outcome of runtime network and overlay attachment.

type BindingResolver

type BindingResolver interface {
	Resolve(ctx context.Context, botID string) (BotOverlayConfig, error)
}

type BotActionRequest

type BotActionRequest struct {
	Input map[string]any `json:"input,omitempty"`
}

type BotOverlayConfig

type BotOverlayConfig struct {
	Enabled  bool           `json:"enabled"`
	Provider string         `json:"provider,omitempty"`
	Config   map[string]any `json:"config,omitempty"`
}

type BotStatus

type BotStatus struct {
	Provider     string                  `json:"provider,omitempty"`
	Attached     bool                    `json:"attached"`
	State        string                  `json:"state,omitempty"`
	Title        string                  `json:"title,omitempty"`
	Description  string                  `json:"description,omitempty"`
	Message      string                  `json:"message,omitempty"`
	NetworkIP    string                  `json:"network_ip,omitempty"`
	ProxyAddress string                  `json:"proxy_address,omitempty"`
	Details      map[string]any          `json:"details,omitempty"`
	Workspace    *WorkspaceRuntimeStatus `json:"workspace,omitempty"`
}

type ConfigConstraint

type ConfigConstraint struct {
	Min  *float64 `json:"min,omitempty"`
	Max  *float64 `json:"max,omitempty"`
	Step *float64 `json:"step,omitempty"`
}

type ConfigField

type ConfigField struct {
	Key         string            `json:"key"`
	Type        FieldType         `json:"type"`
	Required    bool              `json:"required,omitempty"`
	Title       string            `json:"title,omitempty"`
	Description string            `json:"description,omitempty"`
	Placeholder string            `json:"placeholder,omitempty"`
	Default     any               `json:"default,omitempty"`
	Example     any               `json:"example,omitempty"`
	Order       int               `json:"order,omitempty"`
	Enum        []string          `json:"enum,omitempty"`
	Multiline   bool              `json:"multiline,omitempty"`
	Readonly    bool              `json:"readonly,omitempty"`
	Secret      bool              `json:"secret,omitempty"`
	Collapsed   bool              `json:"collapsed,omitempty"`
	Constraint  *ConfigConstraint `json:"constraint,omitempty"`
}

func (ConfigField) Validate

func (f ConfigField) Validate() error

type ConfigSchema

type ConfigSchema struct {
	Version int           `json:"version"`
	Title   string        `json:"title,omitempty"`
	Fields  []ConfigField `json:"fields"`
}

func (ConfigSchema) Validate

func (s ConfigSchema) Validate() error

type Controller

type Controller interface {
	EnsureAttached(ctx context.Context, req AttachmentRequest) (AttachmentStatus, error)
	Detach(ctx context.Context, req AttachmentRequest) error
	Status(ctx context.Context, req AttachmentRequest) (AttachmentStatus, error)
}

Controller coordinates container runtime networking and optional overlay attachment behind a single workspace-facing surface.

func NewController

func NewController(runtime Runtime, resolver BindingResolver, registry *Registry) Controller

NewController creates a controller with runtime networking and optional bot binding resolution for overlay providers.

type FieldType

type FieldType string
const (
	FieldTypeString   FieldType = "string"
	FieldTypeSecret   FieldType = "secret"
	FieldTypeNumber   FieldType = "number"
	FieldTypeBool     FieldType = "bool"
	FieldTypeEnum     FieldType = "enum"
	FieldTypeTextarea FieldType = "textarea"
)

type NetworkJoinTarget

type NetworkJoinTarget struct {
	Kind string
	Path string
	PID  uint32
}

type NodeListResponse

type NodeListResponse struct {
	Provider string       `json:"provider,omitempty"`
	Items    []NodeOption `json:"items,omitempty"`
	Message  string       `json:"message,omitempty"`
}

type NodeOption

type NodeOption struct {
	ID          string         `json:"id"`
	Value       string         `json:"value"`
	DisplayName string         `json:"display_name"`
	Description string         `json:"description,omitempty"`
	Online      bool           `json:"online"`
	Addresses   []string       `json:"addresses,omitempty"`
	CanExitNode bool           `json:"can_exit_node"`
	Selected    bool           `json:"selected"`
	Details     map[string]any `json:"details,omitempty"`
}

type NoopOverlayDriver

type NoopOverlayDriver struct{}

NoopOverlayDriver is the default overlay driver until a real SD-WAN provider is selected. It preserves current behavior by leaving overlay state untouched.

func (NoopOverlayDriver) Detach

func (NoopOverlayDriver) EnsureAttached

func (NoopOverlayDriver) Kind

func (NoopOverlayDriver) Kind() string

func (NoopOverlayDriver) Status

type OverlayDriver

type OverlayDriver interface {
	Kind() string
	EnsureAttached(ctx context.Context, req AttachmentRequest) (OverlayStatus, error)
	Detach(ctx context.Context, req AttachmentRequest) error
	Status(ctx context.Context, req AttachmentRequest) (OverlayStatus, error)
}

OverlayDriver is the runtime surface for a concrete configured provider instance bound to a bot.

type OverlayStatus

type OverlayStatus struct {
	Provider     string         `json:"provider,omitempty"`
	Attached     bool           `json:"attached"`
	State        string         `json:"state,omitempty"`
	Message      string         `json:"message,omitempty"`
	NetworkIP    string         `json:"network_ip,omitempty"`
	ProxyAddress string         `json:"proxy_address,omitempty"`
	Details      map[string]any `json:"details,omitempty"`
}

type Provider

type Provider interface {
	Kind() string
	Descriptor() ProviderDescriptor
	NormalizeConfig(raw map[string]any) (map[string]any, error)
	Status(ctx context.Context, cfg BotOverlayConfig) (ProviderStatus, error)
	ExecuteAction(ctx context.Context, cfg BotOverlayConfig, actionID string, input map[string]any) (ProviderActionExecution, error)
	ListNodes(ctx context.Context, botID string, cfg BotOverlayConfig) ([]NodeOption, error)
	BuildDriver(cfg BotOverlayConfig) (OverlayDriver, error)
}

Provider describes a supported network backend family such as Tailscale or NetBird. It is registered globally and later instantiated from stored provider records.

type ProviderAction

type ProviderAction struct {
	ID          string                `json:"id"`
	Type        ActionType            `json:"type"`
	Label       string                `json:"label"`
	Description string                `json:"description,omitempty"`
	Primary     bool                  `json:"primary,omitempty"`
	Status      *ProviderActionStatus `json:"status,omitempty"`
}

type ProviderActionExecution

type ProviderActionExecution struct {
	ActionID string         `json:"action_id"`
	Status   ProviderStatus `json:"status"`
	Output   map[string]any `json:"output,omitempty"`
}

type ProviderActionStatus

type ProviderActionStatus struct {
	Enabled bool   `json:"enabled"`
	Reason  string `json:"reason,omitempty"`
}

type ProviderCapabilities

type ProviderCapabilities struct {
	Mesh             bool `json:"mesh"`
	PrivateDNS       bool `json:"private_dns"`
	ServiceProxy     bool `json:"service_proxy"`
	EgressProxy      bool `json:"egress_proxy"`
	TransparentProxy bool `json:"transparent_proxy"`
	ExitNode         bool `json:"exit_node"`
	Userspace        bool `json:"userspace"`
	KernelTUN        bool `json:"kernel_tun"`
	NativeClient     bool `json:"native_client"`
	SidecarWorker    bool `json:"sidecar_worker"`
}

type ProviderDescriptor

type ProviderDescriptor struct {
	Kind         string               `json:"kind"`
	DisplayName  string               `json:"display_name"`
	Description  string               `json:"description,omitempty"`
	ConfigSchema ConfigSchema         `json:"config_schema"`
	Capabilities ProviderCapabilities `json:"capabilities"`
	Actions      []ProviderAction     `json:"actions,omitempty"`
}

type ProviderStatus

type ProviderStatus struct {
	State       StatusState    `json:"state"`
	Title       string         `json:"title,omitempty"`
	Description string         `json:"description,omitempty"`
	Details     map[string]any `json:"details,omitempty"`
}

type Registry

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

Registry stores overlay providers and exposes descriptor/capability queries.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty provider registry.

func (*Registry) Get

func (r *Registry) Get(kind string) (Provider, bool)

Get returns the provider for the given kind.

func (*Registry) GetCapabilities

func (r *Registry) GetCapabilities(kind string) (ProviderCapabilities, bool)

GetCapabilities returns the capability matrix for the given provider kind.

func (*Registry) GetDescriptor

func (r *Registry) GetDescriptor(kind string) (ProviderDescriptor, bool)

GetDescriptor returns the read-only descriptor for the given provider kind.

func (*Registry) List

func (r *Registry) List() []Provider

List returns all registered providers.

func (*Registry) ListDescriptors

func (r *Registry) ListDescriptors() []ProviderDescriptor

ListDescriptors returns all registered provider descriptors.

func (*Registry) MustRegister

func (r *Registry) MustRegister(provider Provider)

MustRegister calls Register and panics on error.

func (*Registry) Register

func (r *Registry) Register(provider Provider) error

Register adds a provider to the registry.

type Runtime

type Runtime interface {
	Kind() string
	Descriptor() RuntimeDescriptor
	EnsureNetwork(ctx context.Context, req RuntimeNetworkRequest) (RuntimeNetworkStatus, error)
	RemoveNetwork(ctx context.Context, req RuntimeNetworkRequest) error
	StatusNetwork(ctx context.Context, req RuntimeNetworkRequest) (RuntimeNetworkStatus, error)
}

Runtime is the behavioral surface exposed by a container/runtime adapter to the network controller.

func NewContainerRuntimeFromBackend

func NewContainerRuntimeFromBackend(backend string, svc containerRuntimeService) Runtime

NewContainerRuntimeFromBackend wraps the current runtime network service with the network package's runtime abstraction.

type RuntimeCapabilities

type RuntimeCapabilities struct {
	SidecarWorker        bool `json:"sidecar_worker"`
	RuntimeNetworkSetup  bool `json:"runtime_network_setup"`
	JoinContainerNetwork bool `json:"join_container_network"`
	JoinNamespacePath    bool `json:"join_namespace_path"`
	CNI                  bool `json:"cni"`
	Devices              bool `json:"devices"`
	Capabilities         bool `json:"capabilities"`
	Privileged           bool `json:"privileged"`
}

RuntimeCapabilities describes how a runtime can host or join networking.

type RuntimeDescriptor

type RuntimeDescriptor struct {
	Kind         string              `json:"kind"`
	DisplayName  string              `json:"display_name"`
	Capabilities RuntimeCapabilities `json:"capabilities"`
}

RuntimeDescriptor is the read-only metadata exported by a runtime adapter.

type RuntimeNetworkRequest

type RuntimeNetworkRequest struct {
	ContainerID string
	JoinTarget  NetworkJoinTarget
}

RuntimeNetworkRequest describes the container network attachment target for a runtime adapter.

type RuntimeNetworkStatus

type RuntimeNetworkStatus struct {
	Attached bool
	IP       string
}

RuntimeNetworkStatus describes the current state of the container runtime network attachment.

type Service

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

func NewService

func NewService(log *slog.Logger, queries dbstore.Queries, registry *Registry, runtime statusRuntime, runtimeKind, cniBinDir, cniConfDir, networkStateRoot string) *Service

func (*Service) ExecuteActionBot

func (s *Service) ExecuteActionBot(ctx context.Context, botID, actionID string, input map[string]any) (ProviderActionExecution, error)

func (*Service) GetBotConfig

func (s *Service) GetBotConfig(ctx context.Context, botID string) (BotOverlayConfig, error)

func (*Service) ListBotNodes

func (s *Service) ListBotNodes(ctx context.Context, botID string) (NodeListResponse, error)

func (*Service) ListMeta

func (s *Service) ListMeta(_ context.Context) []ProviderDescriptor

func (*Service) PrepareBotConfigForWrite

func (s *Service) PrepareBotConfigForWrite(cfg BotOverlayConfig) (BotOverlayConfig, error)

func (*Service) ReconcileBot

func (s *Service) ReconcileBot(ctx context.Context, botID string, previous, next BotOverlayConfig) error

func (*Service) Resolve

func (s *Service) Resolve(ctx context.Context, botID string) (BotOverlayConfig, error)

func (*Service) SetController

func (s *Service) SetController(ctrl Controller)

SetController injects the network controller after construction to break the Service ↔ Controller circular dependency (Controller depends on Service as its BindingResolver).

func (*Service) StatusBot

func (s *Service) StatusBot(ctx context.Context, botID string) (BotStatus, error)

type StatusState

type StatusState string

type WorkspaceRuntimeStatus

type WorkspaceRuntimeStatus struct {
	State             string `json:"state"` // workspace_missing | runtime_unavailable | task_stopped | network_target_ready | unknown
	ContainerID       string `json:"container_id,omitempty"`
	TaskStatus        string `json:"task_status,omitempty"`
	PID               uint32 `json:"pid,omitempty"`
	NetworkTargetKind string `json:"network_target_kind,omitempty"`
	NetworkTarget     string `json:"network_target,omitempty"`
	NetworkAttached   bool   `json:"network_attached,omitempty"`
	Message           string `json:"message,omitempty"`
}

WorkspaceRuntimeStatus describes the bot workspace runtime state (foundation before SD-WAN overlay).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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