Documentation
¶
Overview ¶
Package sandboxenv implements the SandboxEnv Reconciler.
Responsibilities:
- Pool materialisation — render each Env.Spec.Clusters[].Members[] entry into a live SandboxPool and propagate drift (labels, annotations, default timeouts, replicas, embedded template). Pool.Spec.Replicas drift is the channel through which the per-Pool autoscaler pushes its scale decisions back onto the live Pool — the autoscaler writes Member.Spec.Replicas on the Env CR, and this reconciler stamps it onto the Pool.
- Status aggregation — mirror idle/running/pending counts and the per-Pool SaturatedUntil from member Pools into Env.Status.Clusters[local].ObservedMembers, plus per-group totals. Cross-member aggregation only; per-Pool autoscaling bookkeeping (LastScale*Time, IdleZeroSince, ...) lives on SandboxPool.Status.AutoScaling, not here.
Every SandboxPool is derived from a SandboxEnv: the Env is the source of truth and this Reconciler materialises member Pools from it. There is no reverse path that creates an Env from a pre-existing Pool.
Multi-cluster prep:
- Spec/status segments are organised by ClusterID; the Reconciler only mutates the segment matching its own LocalClusterID. See ownership.go.
- A Hub-driven Sync (not implemented) will populate foreign segments; this Reconciler ignores them.
Index ¶
Constants ¶
const ( // RequeueAfter is the *base* periodic re-evaluation interval for an // Env that otherwise sees no events. jitteredRequeueAfter spreads // the actual wake times over a ±20 % window so a fleet of Envs that // all reconciled at startup doesn't keep hammering the API server // in lockstep. RequeueAfter = 10 * time.Second // RequeueJitter is the relative jitter applied to RequeueAfter. RequeueJitter = 0.20 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EnvRouterSync ¶
type EnvRouterSync interface {
OnEnvUpsert(env *agentsv1alpha1.SandboxEnv)
}
EnvRouterSync is the minimal contract the SandboxEnv Reconciler uses to keep the in-process Env router's cache in sync with K8s state. The informer event handler covers the steady-state case; this hook fires at the end of every successful Reconcile as a fallback against missed events (rare, but cheap to defend against). Implemented by *envscheduler.Manager.
type FederationReader ¶ added in v0.0.7
type FederationReader interface {
// ForeignMembers returns the fresh member records for the Env from every
// cluster other than the local one.
ForeignMembers(namespace, env string) []federation.Capacity
}
FederationReader is the read side of the cross-cluster capacity registry the reconciler mirrors into status. Implemented by federation.Registry.
type SandboxEnvReconciler ¶
type SandboxEnvReconciler struct {
client.Client
Scheme *runtime.Scheme
// LocalClusterID identifies the cluster this Reconciler runs in. Used to
// decide which spec.clusters[*] / status.clusters[*] segments may be
// mutated. Required; the controller refuses to start when empty.
LocalClusterID string
// Recorder, when non-nil, emits Kubernetes Events on member-Pool
// materialisation / drift outcomes. Initialised in SetupWithManager
// when not pre-set.
Recorder events.EventRecorder
// PluginManager, when non-nil, gates Pool materialisation via
// PreCreatePool / PreUpdatePool admission (scheduler reservation,
// quota, ...). When nil (test mode) every materialisation is
// admitted unconditionally.
PluginManager *plugins.PluginManager
// EnvRouterSync, when non-nil, is invoked at the end of every successful
// Reconcile so the in-process Env router observes the freshest spec
// even if it missed an informer event.
EnvRouterSync EnvRouterSync
// Federation, when non-nil, supplies the cross-cluster capacity view so
// the reconciler can mirror other clusters' members into
// status.clusters[isLocal=false], making the federated decision input
// visible via kubectl. nil in single-cluster mode.
Federation FederationReader
}
SandboxEnvReconciler reconciles a SandboxEnv object.
func (*SandboxEnvReconciler) Reconcile ¶
func (r *SandboxEnvReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)
Reconcile is the entry point of the controller-runtime reconcile loop.
The request always names a SandboxEnv. (Same-name Pool events also enqueue under the Env's name via the secondary Watch; the resolver handles both "Env exists" and "Pool changed, refresh Env status" cases.)
A missing Env is "nothing to do here": the Env is created through the platform API, and member Pools are materialised from it — never the reverse.
func (*SandboxEnvReconciler) SetupWithManager ¶
func (r *SandboxEnvReconciler) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager wires the Reconciler into the controller-runtime manager.
Watches:
- SandboxEnv (primary): generation changes only — status-only updates do not re-enqueue, which prevents a reconcile storm from Status().Patch() re-triggering itself.
- SandboxPool (secondary): enqueues a reconcile under the Pool's name so the Reconciler can refresh status aggregates and propagate spec drift to the live Pool when member fields move. The Pool name equals the Env name when the Env owns exactly one same-named Pool.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package poolrender produces a fully rendered SandboxPool CR from an Env + Member + SandboxTemplate triple.
|
Package poolrender produces a fully rendered SandboxPool CR from an Env + Member + SandboxTemplate triple. |