Documentation
¶
Overview ¶
Package runctl is the run-controller (adoption 3a): it reconciles maku.ogenki.io AgentRuns into the pod, ServiceAccount, ConfigMaps and CiliumNetworkPolicy that cloud-native-ref's Crossplane composition builds, minus the gateway, octo-sts, Kueue and suspend.
Index ¶
- Constants
- func Branch(r *v1alpha1.AgentRun, runID string) string
- func CAConfigMap(r *v1alpha1.AgentRun, ca []byte) *corev1.ConfigMap
- func Egress(r *v1alpha1.AgentRun, c Config, m Model) []string
- func KubeNetworkPolicy(r *v1alpha1.AgentRun, c Config, m Model, runID string) *networkingv1.NetworkPolicy
- func Labels(r *v1alpha1.AgentRun, runID string) map[string]string
- func NetworkPolicy(r *v1alpha1.AgentRun, c Config, m Model, runID string) *unstructured.Unstructured
- func Observe(prev v1alpha1.AgentRunStatus, revoked string, pod *corev1.Pod, podGone bool, ...) v1alpha1.AgentRunStatus
- func Pod(r *v1alpha1.AgentRun, c Config, m Model, runID string) *corev1.Pod
- func ProbeName(c Config, suffix string) string
- func ProbeNetworkPolicy(c Config, pod *corev1.Pod) *networkingv1.NetworkPolicy
- func ProbePod(c Config, suffix string) *corev1.Pod
- func RevokeEnds(revoked string) bool
- func Rules(r *v1alpha1.AgentRun, runID string) string
- func RuntimeClassRefusal(ctx context.Context, c client.Reader, name string) (refusal string, soon bool, err error)
- func ServiceAccount(r *v1alpha1.AgentRun) *corev1.ServiceAccount
- func TaskConfigMap(r *v1alpha1.AgentRun, runID string) (*corev1.ConfigMap, error)
- type Broker
- type Collector
- type Config
- func (c Config) FQDNs(r *v1alpha1.AgentRun) []string
- func (c Config) Gateway() bool
- func (c Config) GatewayModel(r *v1alpha1.AgentRun) Model
- func (c Config) GitSecretFor(r *v1alpha1.AgentRun) string
- func (c Config) Invalid(r *v1alpha1.AgentRun) string
- func (c Config) PerRun() bool
- func (c Config) RunID(r *v1alpha1.AgentRun) string
- type DNS
- type EgressProxy
- type Gateway
- type GatewayAliases
- type GatewayPorts
- type Images
- type Model
- type ModelConfig
- type PodRef
- type Preflight
- type Reconciler
- type Result
- type ServiceAccountRef
- type Tracing
Constants ¶
const ( NetworkPolicyCilium = "cilium" NetworkPolicyNone = "none" // NetworkPolicyKubernetes: each run gets a networking.k8s.io/v1 NetworkPolicy, and its harness // reaches the web only through the egress proxy, which holds it to its own hosts (v4 D6). NetworkPolicyKubernetes = "kubernetes" )
The values of Config.NetworkPolicy.
const ( // ModelModeSecret: the harness calls the provider named by modelSecret with its key (3a R4). ModelModeSecret = "secret" // ModelModeGateway: the harness calls the model gateway with the run's own projected token, on its // data class's listener and its claim's alias (v4 step 4, GW3). No provider key enters the pod. ModelModeGateway = "gateway" )
The values of ModelConfig.Mode.
const ( EnvCoordinationManifest = "COORDINATION_MANIFEST" EnvCoordinationManifestHash = "COORDINATION_MANIFEST_SHA256" )
The integration manifest's claim annotations (v4 MR10), as the factory writes them at CREATE (runs.AnnCoordinationManifest and its hash), and the harness variables that carry them. The harness verifies the hash again, writes the bytes to a read-only file and exports its path as MAKU_COORDINATION_MANIFEST: the variables here are its input, never what a check reads.
const ( LabelRunID = "agents.ogenki.io/run-id" LabelRole = "agents.ogenki.io/role" LabelManagedBy = "app.kubernetes.io/managed-by" LabelTask = "agents.ogenki.io/task" )
Label keys the composition sets; the CNP selects the pod by run-id.
const ( BridgeHealthPort = 8085 HarnessPort = 8000 )
The composition's constants (crossplane-configuration v0.9.15).
const ( PreflightUnknown = "Unknown" // no check has finished yet: new runs wait PreflightPassed = "Passed" PreflightFailed = "Failed" // new runs are refused with the check's message // PreflightWaiting: a check that waits, rather than refuses, did not pass (a git Secret not yet // filled): new runs stay Pending with its message. PreflightWaiting = "Waiting" )
The states of a preflight Result.
const DefaultPreflightEvery = 10 * time.Minute
DefaultPreflightEvery is how often the preflight checks again after its first run.
const EgressAnnotation = "maku.ogenki.io/egress"
EgressAnnotation is a kubernetes-mode run pod's allow-list, host:port joined by commas. The egress proxy trusts it: the run-pod policy lets only the run-controller create pods in the runs namespace, and refuses any change to it after create.
const ForgeAPIHost = "api.github.com"
ForgeAPIHost is GitHub's API, which a run annotated forge-api: deny never reaches (HR36): it reads forge text through forge_read, and git keeps github.com.
const ProbeRunID = "preflight"
ProbeRunID is the run-id label of every preflight probe pod: its NetworkPolicy selects it, and the preflight finds leftovers by it.
Variables ¶
This section is empty.
Functions ¶
func CAConfigMap ¶
CAConfigMap is <run>-ca: the broker's CA, which the bridge verifies :8443 against.
func Egress ¶ added in v0.46.0
Egress is a run's allow-list as host:port, the same set its CNP opens on the web: webHosts on 443, then a model outside the cluster on another port. An in-cluster model is not in it: it is reached directly, by NetworkPolicy, never through the egress proxy. It is the pod's EgressAnnotation.
func KubeNetworkPolicy ¶ added in v0.46.0
func KubeNetworkPolicy(r *v1alpha1.AgentRun, c Config, m Model, runID string) *networkingv1.NetworkPolicy
KubeNetworkPolicy is a kubernetes-mode run's policy (plan PR6): DNS to the cluster DNS, the egress proxy on its port, the broker on 8443 (and roomToolsURL's port) when the run has a room, the model's namespace on its port when the model is in-cluster, the OTLP collector's pods on its port when tracing is configured. No ingress at all. The web is reached only through the proxy, which holds the run to Egress; DNS stays open, so DNS tunnelling is this mode's residual risk (docs/security.md).
func Labels ¶
Labels are every owned object's; runID "" (the ServiceAccount, the CA ConfigMap) omits run-id.
func NetworkPolicy ¶
func NetworkPolicy(r *v1alpha1.AgentRun, c Config, m Model, runID string) *unstructured.Unstructured
NetworkPolicy is the run's default-deny CNP: DNS for its names only, the broker on 8443 (and roomToolsURL's port when set), github and its profiles on 443, the model host on its port, the OTLP collector's pods on its port when tracing is configured. Nothing dials in except the kubelet's probe of the bridge (C4).
func Observe ¶
func Observe(prev v1alpha1.AgentRunStatus, revoked string, pod *corev1.Pod, podGone bool, now time.Time) v1alpha1.AgentRunStatus
Observe is the composition's _phaseOf and _reasonOf over a plain pod: a terminal status is final; then revocation; then the harness's exit; then the pod's failure; then a pod lost that the reconciler had created (podGone), whether or not it ever left Pending. finishedAt is always set at a terminal phase, so runwatch never falls back to the Ready condition.
func Pod ¶
Pod is the run's pod: the composition's Sandbox pod template without identity-proxy, octo-sts, traces, Kueue and suspend. The model key and the PAT are files the harness reads (3a R4). It is named like the run, as the Sandbox's pod is.
func ProbeNetworkPolicy ¶ added in v0.46.0
func ProbeNetworkPolicy(c Config, pod *corev1.Pod) *networkingv1.NetworkPolicy
ProbeNetworkPolicy is the probe pod's own policy, built as a run's, owned by the pod (not as its controller: no blockOwnerDeletion), so it goes when the pod does.
func ProbePod ¶ added in v0.46.0
ProbePod is the network preflight's pod (plan PR7): it runs `netprobe` from the run-controller's image, under the sandbox class, with run labels and the egress annotation github.com:443, and passes the run-pod policy. Its positive controls are the broker's 8443 and CONNECT github.com:443 through the proxy. Its negative controls, each always listening:
- the broker's 9090, which both its own policy and the broker's deny;
- the apiserver (kubernetes.default.svc) on 443 and github.com:443 dialled directly, past the proxy, which only the run's egress policy denies: a CNI that enforces ingress alone fails here.
func RevokeEnds ¶
RevokeEnds reports whether the revoke annotation's value ends the run.
func Rules ¶
Rules is the run's rules.md: the composition's _rulesFor without the lines that name room_* tools or the model gateway, neither of which this runtime has (3a R8). A run whose claim names safe outputs (hardening H2) requests those writes from the factory; any other run's rules are unchanged.
func RuntimeClassRefusal ¶ added in v0.47.0
func RuntimeClassRefusal(ctx context.Context, c client.Reader, name string) (refusal string, soon bool, err error)
RuntimeClassRefusal is the run-controller's RuntimeClass check, shared with the install's preflight pod so the two cannot disagree (v4 D18): a refusal naming the fix when the class is absent, a refusal with soon when the reader may not get it (an RBAC denial, which a fresh binding may yet fix), or an error when the API cannot answer.
func ServiceAccount ¶
func ServiceAccount(r *v1alpha1.AgentRun) *corev1.ServiceAccount
ServiceAccount is named exactly like the run: the broker's run issuer maps system:serviceaccount:<ns>:<run name> to the run (C2). It holds no RBAC.
Types ¶
type Broker ¶
type Broker struct {
URL string `json:"url"`
Namespace string `json:"namespace"`
Labels map[string]string `json:"labels"`
CASecret string `json:"caSecret"`
}
Broker is where the bridge connects, and what the CNP lets it reach.
type Collector ¶ added in v0.47.0
type Collector struct {
Namespace string `json:"namespace,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
Collector is the OTLP collector's namespace and pod labels.
type Config ¶
type Config struct {
Namespace string `json:"namespace"`
NamePrefix string `json:"namePrefix"`
RuntimeClassName string `json:"runtimeClassName,omitempty"`
// AllowUnsandboxed places pods without a RuntimeClass; each run then carries condition
// Unsandboxed, so the room can say so (3a R5).
AllowUnsandboxed bool `json:"allowUnsandboxed,omitempty"`
// NetworkPolicy is "cilium" (default: each run gets a CiliumNetworkPolicy), "kubernetes" (a
// NetworkPolicy, and the harness behind EgressProxy) or "none", for a cluster that enforces
// neither: no policy is created, so nothing confines a run's network.
NetworkPolicy string `json:"networkPolicy,omitempty"`
// EgressProxy is the in-cluster CONNECT proxy, required in kubernetes mode.
EgressProxy EgressProxy `json:"egressProxy,omitempty"`
// DNS selects the cluster DNS pods a kubernetes-mode run's NetworkPolicy opens on 53.
DNS DNS `json:"dns,omitempty"`
// ModelSecret holds the provider key and model the harness calls directly (model.mode secret, the
// default). It is refused in gateway mode, where the gateway holds the keys.
ModelSecret string `json:"modelSecret,omitempty"`
// Model is how runs reach a model: secret (ModelSecret) or gateway (v4 step 4, D7).
Model ModelConfig `json:"model,omitzero"`
// GitSecret is a laptop's one PAT, which every role mounts (the chart admits it only with
// demoValues, v4 step 8 Q14). Empty, the product path: each run mounts its own Secret,
// <run name>-git, which the factory mints for its repository and role (D10).
GitSecret string `json:"gitSecret,omitempty"`
Broker Broker `json:"broker"`
Images Images `json:"images"`
EgressProfiles map[string][]string `json:"egressProfiles,omitempty"`
// RoomToolsURL is the broker's :8090 room tools, by broker.url's host, for a broker serving
// roomTools.auth tokenreview. Set, a run with a room gets MCP_URL and a projected token of audience
// room-tools for the harness alone. Unset, the harness wires no MCP server.
RoomToolsURL string `json:"roomToolsURL,omitempty"`
// Tracing hands each run's harness the OTLP/HTTP endpoint it exports its span to, under the
// task's trace (v4 D21). Unset, runs export nothing and their policies are unchanged.
Tracing Tracing `json:"tracing,omitzero"`
}
Config is the run-controller's file, from the chart.
func LoadConfig ¶
LoadConfig reads, strictly decodes, defaults and validates the file at path.
func (Config) FQDNs ¶
FQDNs are the hosts the run may reach on 443: github, then its profiles, deduplicated, without ForgeAPIHost for a run annotated forge-api: deny. Both the CNP and the egress proxy's allow-list derive from it.
func (Config) GatewayModel ¶ added in v0.46.0
GatewayModel is a gateway-mode run's model: the gateway's listener for the run's data class, under /m/<alias>/v1 for the run's alias, its judge's and the light alias's (GW5, CP12). Host and Port are the listener's, so the run's policies admit the gateway's namespace on it as for any in-cluster model.
func (Config) GitSecretFor ¶ added in v0.46.0
GitSecretFor is the git Secret run mounts: the run's own, <run name>-git, whatever the role (the factory minted it for that role), or the laptop's one PAT, gitSecret, which every role shares.
func (Config) Invalid ¶
Invalid says why the controller refuses r, or "" when it accepts it (3a R6, R7).
type EgressProxy ¶ added in v0.46.0
type EgressProxy struct {
URL string `json:"url"`
Namespace string `json:"namespace"`
Labels map[string]string `json:"labels"`
DenyCIDRs []string `json:"denyCIDRs,omitempty"`
}
EgressProxy is where a kubernetes-mode harness sends HTTPS, and what its NetworkPolicy lets it reach. DenyCIDRs are the proxy's own: addresses it never dials, beyond the non-public ones.
func (EgressProxy) Port ¶ added in v0.46.0
func (p EgressProxy) Port() int
Port is URL's port (validated at load).
type Gateway ¶ added in v0.46.0
type Gateway struct {
// URL is http://<service>.<namespace>.svc.<cluster-domain>, with no port or path: the port is the
// run's data class's listener, the path its alias.
URL string `json:"url,omitempty"`
Ports GatewayPorts `json:"ports,omitzero"`
// AudiencePrefix starts every token audience: <prefix>.<dataClass>.<alias>.
AudiencePrefix string `json:"audiencePrefix,omitempty"`
// Aliases are the aliases each listener serves (maku-gateway aliases.<class>'s keys): a run whose
// alias its listener does not serve is refused before its pod exists.
Aliases GatewayAliases `json:"aliases,omitzero"`
// LightAlias is the alias the light jobs run on (CP12): an internal run's condenser summary
// and a search implementer's child. Every non-empty listener must serve it, so no pod is
// created with a dead LIGHT_BASE_URL.
LightAlias string `json:"lightAlias,omitempty"`
// ServiceAccount is the run-controller's own, which the gateway-token-ttl preflight requests a
// token for, at the longest run's lifetime (GW9).
ServiceAccount ServiceAccountRef `json:"serviceAccount,omitzero"`
}
Gateway is the model gateway (agentgateway, maku-gateway) that gateway-mode runs call.
type GatewayAliases ¶ added in v0.46.0
type GatewayAliases struct {
Public []string `json:"public,omitempty"`
Internal []string `json:"internal,omitempty"`
}
GatewayAliases are the aliases served per data class.
type GatewayPorts ¶ added in v0.46.0
type GatewayPorts struct {
Public int `json:"public,omitempty"`
Internal int `json:"internal,omitempty"`
}
GatewayPorts are the listeners' ports, one per data class.
type Images ¶
type Images struct {
Harness string `json:"harness"`
Bridge string `json:"bridge"`
// Probe runs the preflight's netprobe pod: the run-controller's own image, required in
// kubernetes mode.
Probe string `json:"probe,omitempty"`
}
Images are the run pod's two images, pinned by the chart.
type Model ¶
type Model struct {
BaseURL, Name, Host, Judge string
JudgeBaseURL string
Light, LightBaseURL string
Port int
}
Model is the provider the harness calls directly (3a R4), from modelSecret. Judge is the optional judge_model: the completion judge's model on the same endpoint, "" for the run's own. In gateway mode (GatewayModel), Name and Judge are the run's aliases, and JudgeBaseURL the judge alias's path on the same listener. Model is the run's model: its endpoint, name, the gateway listener's host and port, the judge's endpoint when a judge runs, and the light alias's when the run can use it (CP12).
type ModelConfig ¶ added in v0.46.0
type ModelConfig struct {
Mode string `json:"mode,omitempty"`
Gateway Gateway `json:"gateway,omitzero"`
}
ModelConfig is the run-controller's model mode.
type PodRef ¶ added in v0.46.0
type PodRef struct{ Name, UID string }
PodRef is the run-controller's own pod, from the downward API (POD_NAME, POD_UID).
type Preflight ¶ added in v0.46.0
type Preflight struct {
Client client.Reader // uncached: one get by name, never a cluster-wide list or watch
Cfg Config
Every time.Duration
Log *slog.Logger
// Passed reports each check's outcome, for the maku_run_controller_preflight_passed gauge.
Passed func(check string, ok bool)
Now func() time.Time
// Kube creates and deletes the network check's probe pod and its NetworkPolicy (kubernetes mode).
Kube client.Client
// ProbeStart is how long the probe pod may stay Pending (default 2 minutes); ProbePoll how often
// its phase is read (default 2 s).
ProbeStart, ProbePoll time.Duration
// ProbeSuffix names the probe pod (default 8 random characters of [a-z2-7]).
ProbeSuffix func() string
// Self is the run-controller's own pod, which the gateway-token-ttl check binds its token to.
Self PodRef
// contains filtered or unexported fields
}
Preflight proves, at start and every Every, that the cluster can run a sandboxed run (v4 D18): the RuntimeClass exists, and so do the git Secrets runs mount, each with a token key. The reconciler consults Result before it creates a run's first pod; a run that already has a pod is never refused by it (plan PR7). It is a manager.Runnable.
func (*Preflight) NeedLeaderElection ¶ added in v0.46.0
NeedLeaderElection is true: only the leader creates pods, so only it needs the result.
func (*Preflight) Result ¶ added in v0.46.0
Result is the latest outcome; Unknown before the first check finishes.
func (*Preflight) Start ¶ added in v0.46.0
Start checks at once, then every Every, until ctx ends. An undecided tick (the API server unreachable right after install), or one refused for a Forbidden read (the ClusterRole binding not yet propagated), is retried sooner, from 10 s with backoff, up to Every.
func (*Preflight) Tick ¶ added in v0.46.0
Tick runs every check once. The first refusal fails the preflight; a check that cannot decide keeps the last result (Unknown before any, carrying the error), so an API server blip refuses no run. It reports whether to check again soon: a check was undecided, or refused with soon.
type Reconciler ¶
type Reconciler struct {
Client client.Client
APIReader client.Reader // uncached: Secrets are never listed or watched, and a cached pod NotFound is never trusted
Cfg Config
Now func() time.Time
Log *slog.Logger
// Preflight, when set, is consulted before a run's first pod: Unknown and Waiting wait, Failed refuses.
Preflight interface{ Result() Result }
}
Reconciler turns an AgentRun into its owned objects and reports the pod back as status. Owned objects are created once: a run's spec is immutable, so there is nothing to patch.
func (*Reconciler) Reconcile ¶
Reconcile is idempotent: a restart reconciles every non-terminal run from scratch.
func (*Reconciler) SetupWithManager ¶
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager watches runs and the pods they own.
type Result ¶ added in v0.46.0
Result is the preflight's latest outcome. Check and Message name the first failed check.
type ServiceAccountRef ¶ added in v0.46.0
type ServiceAccountRef struct {
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`
}
ServiceAccountRef names a ServiceAccount.
type Tracing ¶ added in v0.47.0
type Tracing struct {
// OTLPEndpoint is the OTLP/HTTP base URL, http(s)://<service>.<namespace>.svc.<cluster-domain>:<port>:
// the harness posts to <endpoint>/v1/traces.
OTLPEndpoint string `json:"otlpEndpoint,omitempty"`
// Collector selects the collector's pods, in the endpoint's namespace.
Collector Collector `json:"collector,omitzero"`
}
Tracing is where runs export their span, and the collector pods their policy opens its port to: the one addition to D6's run egress, made only when configured (step 6 R1).