sandboxenv

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package sandboxenv implements the SandboxEnv Reconciler.

Responsibilities:

  1. 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.
  2. 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.

Adoption (Pool → same-named Env) is handled by an independent transitional reconciler in poolmigration/ — see that package for migration semantics.

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

View Source
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 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
}

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.)

Adoption — creating the Env in the first place — is owned by the PoolAdoptionReconciler in poolmigration/. This Reconciler treats a missing Env as "nothing to do here yet".

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.

Directories

Path Synopsis
Package poolmigration owns the steady-state sync that keeps legacy (same-name) SandboxPool ↔ SandboxEnv pairs aligned.
Package poolmigration owns the steady-state sync that keeps legacy (same-name) SandboxPool ↔ SandboxEnv pairs aligned.
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.

Jump to

Keyboard shortcuts

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