Documentation
¶
Index ¶
- Constants
- func SplitSandboxID(id string) (clusterID, rawID string)
- func WriteClusterConfig(ctx context.Context, c client.Client, namespace, name string, ...) error
- type ClusterConfig
- type ClusterEntry
- type ConfigDiff
- type ConfigMapWriter
- type GatewayConfig
- type HostAliasSubscriber
- type ParsedPoolRef
- type Store
- func (s *Store) All() []ClusterEntry
- func (s *Store) ApplyConfig(cfg ClusterConfig) ConfigDiff
- func (s *Store) Get(clusterID string) (ClusterEntry, bool)
- func (s *Store) HostAliases() []corev1.HostAlias
- func (s *Store) LoadFromConfigMapObject(cm *corev1.ConfigMap) error
- func (s *Store) LoadFromData(data []byte) error
- func (s *Store) LoadFromFile(path string) error
- func (s *Store) Set(entries []ClusterEntry)
- func (s *Store) SubscribeHostAliases(fn HostAliasSubscriber)
- func (s *Store) WatchConfigMap(ctx context.Context, informerCache cache.Cache, namespace, name string) error
- type URLKind
Constants ¶
const ClusterConfigKey = "config.yaml"
ClusterConfigKey is the ConfigMap data key that holds the full snapshot (clusters + host aliases) pushed by the Manager.
const LegacyClustersKey = "clusters.yaml"
LegacyClustersKey is the previous key name ("clusters.yaml") which held only the clusters list. Still honored on read for rolling upgrades.
Variables ¶
This section is empty.
Functions ¶
func SplitSandboxID ¶
SplitSandboxID extracts the cluster ID prefix from a sandbox ID. Input format: "{clusterID}.{uuid}" or just "{uuid}". Returns (clusterID, rawID). If no prefix is present, clusterID is empty.
func WriteClusterConfig ¶
func WriteClusterConfig(ctx context.Context, c client.Client, namespace, name string, cfg ClusterConfig) error
WriteClusterConfig serialises cfg as YAML and upserts the ClusterConfigKey entry of the named ConfigMap.
Behaviour:
- A zero-valued snapshot returns immediately without modifying the ConfigMap (safe-merge guarantee).
- If the ConfigMap does not exist it is created.
- If the ConfigMap exists only the snapshot key is updated; all other keys (including the legacy "clusters.yaml" written by older Managers) are preserved so a Worker reader can continue to fall back during a rolling upgrade.
Types ¶
type ClusterConfig ¶
type ClusterConfig struct {
Clusters []ClusterEntry `json:"clusters"`
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
}
ClusterConfig holds the full configuration snapshot pushed from the Manager to every Worker. It is the single wire + on-disk (ConfigMap) format for all cluster-wide settings delivered via the sync channel.
Fields beyond Clusters (e.g. HostAliases) let the Manager propagate Worker-level operational config that would otherwise need to be baked into each Worker cluster's install YAML.
HostAliases reuses corev1.HostAlias verbatim so operators can copy/paste Pod spec snippets straight into Manager Helm values.
type ClusterEntry ¶
type ClusterEntry struct {
ID string `json:"id"`
Name string `json:"name"`
URL string `json:"url"` // Dashboard-facing address
// Selector is a full PromQL label matcher expression that uniquely identifies
// this cluster's metrics, e.g. `cluster="cluster1"` or
// `cluster="cluster1",region="region1"`. It is passed through verbatim to Prometheus
// queries on the Dashboard; ID is purely an internal business identifier and
// no longer has to match the `cluster` label value.
Selector string `json:"selector,omitempty"`
Headers map[string]string `json:"headers,omitempty"` // Dashboard headers
Visible string `json:"visible,omitempty"` // visibility control
Gateway *GatewayConfig `json:"gateway,omitempty"` // cross-cluster gateway config
}
ClusterEntry describes a single cluster and how to reach it.
type ConfigDiff ¶
type ConfigDiff struct {
AddedClusters []ClusterEntry
RemovedClusters []ClusterEntry
UpdatedClusters []ClusterEntry // holds the new value after update
AddedAliases []corev1.HostAlias
RemovedAliases []corev1.HostAlias
}
ConfigDiff describes what changed between two consecutive ClusterConfig snapshots. An empty ConfigDiff (IsEmpty() == true) means nothing changed.
func (ConfigDiff) IsEmpty ¶
func (d ConfigDiff) IsEmpty() bool
IsEmpty returns true when the diff carries no changes.
type ConfigMapWriter ¶
type ConfigMapWriter struct {
// contains filtered or unexported fields
}
ConfigMapWriter writes a full ClusterConfig snapshot (clusters + host aliases) into a Kubernetes ConfigMap so that Worker-side components — ExtProc, the CrossClusterForwarder, and the in-process DNS resolver — can read cross-cluster routing and host-alias rules.
It implements the ClusterConfigSink interface expected by the apiserver sync service.
func NewConfigMapWriter ¶
func NewConfigMapWriter(c client.Client, namespace, name string) *ConfigMapWriter
NewConfigMapWriter returns a ConfigMapWriter that upserts the given ConfigMap.
func (*ConfigMapWriter) ApplyClusterConfig ¶
func (w *ConfigMapWriter) ApplyClusterConfig(ctx context.Context, cfg ClusterConfig) error
ApplyClusterConfig serialises cfg into the canonical snapshot format and upserts the target ConfigMap. A zero-valued snapshot (no clusters and no host aliases) is treated as a transient empty push and dropped so it cannot accidentally erase populated state on disk.
type GatewayConfig ¶
type GatewayConfig struct {
// Explicit per-plane URLs.
NativeURL string `json:"nativeURL,omitempty"` // Native API (agentbox-control-plane)
E2BURL string `json:"e2bURL,omitempty"` // E2B-compat API (agentbox-e2b-api)
DataURL string `json:"dataURL,omitempty"` // data plane (agentbox-data-plane)
// Headers injected into every forwarded request.
Headers map[string]string `json:"headers,omitempty"`
// Per-plane header overrides. Merged onto Headers; the per-plane value wins
// when a key exists in both.
NativeHeaders map[string]string `json:"nativeHeaders,omitempty"`
E2BHeaders map[string]string `json:"e2bHeaders,omitempty"`
DataHeaders map[string]string `json:"dataHeaders,omitempty"`
}
GatewayConfig describes the internal gateway used for cross-cluster forwarding.
Each plane has its own explicit URL. Header injection is layered:
- Headers applies to every forwarded request (common auth tokens, etc.).
- NativeHeaders / E2BHeaders / DataHeaders are per-plane overrides that are merged on top of Headers — keys present in the per-plane map win on conflict.
Example:
nativeURL: "https://native.cluster-a.internal" e2bURL: "https://e2b.cluster-a.internal" dataURL: "https://data.cluster-a.internal" headers: X-GW-Auth: shared-token dataHeaders: X-GW-Auth: data-only-token # overrides shared-token for data-plane calls
func (*GatewayConfig) DataPlaneBaseURL ¶
func (g *GatewayConfig) DataPlaneBaseURL() string
DataPlaneBaseURL returns the base URL for the data plane (agentbox-data-plane service).
func (*GatewayConfig) E2BAPIBaseURL ¶
func (g *GatewayConfig) E2BAPIBaseURL() string
E2BAPIBaseURL returns the base URL for the E2B-compatible API (agentbox-e2b-api service).
func (*GatewayConfig) MergedHeaders ¶
func (g *GatewayConfig) MergedHeaders(kind URLKind) map[string]string
MergedHeaders returns Headers merged with the per-plane override for the given kind. Keys in the override win over keys in Headers. Returns nil when both maps are empty so callers can range over it safely.
func (*GatewayConfig) NativeAPIBaseURL ¶
func (g *GatewayConfig) NativeAPIBaseURL() string
NativeAPIBaseURL returns the base URL for the Native API (agentbox-control-plane service).
type HostAliasSubscriber ¶
HostAliasSubscriber is invoked with the full host-alias list every time the Manager pushes a new ClusterConfig. Subscribers must treat the slice as read-only and copy it if they need to retain it.
type ParsedPoolRef ¶
type ParsedPoolRef struct {
ClusterID string // empty when no "clusterID::" prefix is present
PoolName string // the K8s resource name of the SandboxPool
ImageOverride string // empty when no "//imageOverride" suffix is present
}
ParsedPoolRef holds the result of parsing a pool reference string.
func ParsePoolRef ¶
func ParsePoolRef(raw string) ParsedPoolRef
ParsePoolRef parses an input string of the form [clusterID::]poolName[//imageOverride].
For the native API, callers pass "[clusterID::]poolName" (no image override). For the E2B API, callers pass "[clusterID::]poolName[//imageOverride]".
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a thread-safe in-memory store of cluster configurations keyed by cluster ID.
func (*Store) All ¶
func (s *Store) All() []ClusterEntry
All returns a snapshot of all cluster entries sorted by ID. The sort is load-bearing: callers serialize the result into ConfigMaps and WS sync frames, and downstream components hash/diff those bytes. Map iteration order would produce a fresh "change" each tick even when nothing actually changed.
func (*Store) ApplyConfig ¶
func (s *Store) ApplyConfig(cfg ClusterConfig) ConfigDiff
ApplyConfig atomically replaces both clusters and host aliases from a full snapshot, notifies host-alias subscribers when the alias list changes, and returns a ConfigDiff describing what changed. An empty diff means nothing changed. Passing a zero-valued ClusterConfig is an explicit reset; callers that want to guard against accidental empty pushes must do so before calling this method (see ConfigMapWriter).
func (*Store) Get ¶
func (s *Store) Get(clusterID string) (ClusterEntry, bool)
Get returns the ClusterEntry for the given cluster ID.
func (*Store) HostAliases ¶
HostAliases returns a copy of the current host-alias list.
func (*Store) LoadFromConfigMapObject ¶
LoadFromConfigMapObject reads the snapshot from a ConfigMap object and replaces the store contents. Prefers the new "config.yaml" key; falls back to the legacy "clusters.yaml" key when the new key is absent so that Workers running a newer build can still read a ConfigMap written by an older Manager during a rolling upgrade. If both keys are missing or empty, the store is cleared.
func (*Store) LoadFromData ¶
LoadFromData parses YAML data (e.g. from a ConfigMap data field) and replaces the store contents. An empty or nil input clears the store (no clusters configured).
func (*Store) LoadFromFile ¶
LoadFromFile reads a clusters.yaml file and replaces the store contents.
func (*Store) Set ¶
func (s *Store) Set(entries []ClusterEntry)
Set replaces all entries in the store.
func (*Store) SubscribeHostAliases ¶
func (s *Store) SubscribeHostAliases(fn HostAliasSubscriber)
SubscribeHostAliases registers fn to be called with the current host-alias list immediately (if any are already loaded) and on every subsequent update. Intended for wiring DNS resolvers at startup; Unsubscribe is intentionally omitted because subscriber lifecycle matches the process.
func (*Store) WatchConfigMap ¶
func (s *Store) WatchConfigMap(ctx context.Context, informerCache cache.Cache, namespace, name string) error
WatchConfigMap registers an informer event handler that reloads the Store whenever the target ConfigMap is created, updated, or deleted. The cache must be started (i.e. mgr.Start called) for events to fire. The initial load happens automatically via the informer's OnAdd callback once the cache syncs.