controller

package
v1.22.10 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package controller implements the TMIComponent reconciler for the TMI Component Platform.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsumerConfigFor

func ConsumerConfigFor(c *platformv1alpha1.TMIComponent) *nats.ConsumerConfig

ConsumerConfigFor returns the durable consumer the controller pre-creates on a component's stream. The name MUST equal consumerNameFor(c) because that is exactly the consumer the KEDA ScaledObject (render_scaledobject.go) watches for queue depth — KEDA cannot scale a worker from zero unless this consumer already exists under that name. The worker (cmd/extractor, cmd/chunkembed) binds this same durable rather than creating its own.

The consumer carries NO FilterSubject: each per-component stream is single-purpose, so the durable consumes every subject the stream binds. This keeps the config identical regardless of how many jobSubjects a component declares and avoids a filter-subject conflict when the worker binds it.

func RenderDeployment

func RenderDeployment(c *platformv1alpha1.TMIComponent) *appsv1.Deployment

RenderDeployment builds the worker Deployment for a TMIComponent. Pod hardening (readOnlyRootFilesystem, runAsNonRoot, all caps dropped, RuntimeDefault seccomp) is applied unconditionally — it is a hard platform invariant, not a per-component option.

func RenderNetworkPolicy

RenderNetworkPolicy builds the NetworkPolicy for a component from its egress posture. The Egress policy type is always set so a limited egress list is an enforced deny. Every egress rule carries an explicit To peer selector — a rule with ports but no To matches all destinations, so scoping the peers is what makes "egress: none" mean "NATS only". The controller always renders this as a cluster-layer backstop, independent of any in-code egress guarding.

func RenderScaledObject

RenderScaledObject builds the KEDA ScaledObject for a component as an unstructured object, avoiding a KEDA Go-module dependency. KEDA scales the worker Deployment on JetStream pending-message depth.

func StreamConfigFor

func StreamConfigFor(c *platformv1alpha1.TMIComponent) *nats.StreamConfig

StreamConfigFor returns the JetStream stream configuration that binds all of a component's job subjects.

func ValidateComponent

func ValidateComponent(c *platformv1alpha1.TMIComponent) error

ValidateComponent checks a TMIComponent spec for internal consistency beyond what the CRD OpenAPI schema can express.

Types

type NATSProvisioner

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

NATSProvisioner is the live StreamProvisioner backed by a NATS JetStream connection. In the current out-of-cluster e2e flow the controller reaches NATS through the host port-forward (nats://127.0.0.1:4222); once the controller ships as an in-cluster Deployment it will use the in-cluster service DNS (tls://nats.tmi-platform.svc:4222). Either way the URL is supplied via the TMI_NATS_URL env var.

func NewNATSProvisioner

func NewNATSProvisioner(url string) (*NATSProvisioner, error)

NewNATSProvisioner dials NATS and opens a JetStream context. It uses RetryOnFailedConnect so the controller can start before the port-forward (or the NATS pod) is reachable: JetStream calls then fail until the connection establishes, which surfaces as a reconcile error and a requeue.

func (*NATSProvisioner) Close

func (p *NATSProvisioner) Close()

Close closes the underlying NATS connection.

func (*NATSProvisioner) EnsureStreamAndConsumer

func (p *NATSProvisioner) EnsureStreamAndConsumer(ctx context.Context, c *platformv1alpha1.TMIComponent) error

EnsureStreamAndConsumer creates the component's stream and durable consumer if they do not already exist. It is idempotent: an existing stream/consumer is left untouched (the config is stable across reconciles), so it is safe to call on every reconcile. Creation is gated on a NotFound lookup rather than blind AddStream/AddConsumer so a transient connectivity error is returned as an error (triggering requeue) instead of being mistaken for "already exists".

type StreamProvisioner

type StreamProvisioner interface {
	EnsureStreamAndConsumer(ctx context.Context, c *platformv1alpha1.TMIComponent) error
}

StreamProvisioner ensures the JetStream stream and durable consumer a component needs exist before any worker pod runs. It is the missing half of reconciliation: rendering the KEDA ScaledObject is pointless unless the stream and consumer it watches already exist, because KEDA scales a worker from zero by reading that consumer's pending-message depth.

The reconciler holds this as an interface so envtest unit tests (which have no NATS) can leave it nil and skip provisioning.

type TMIComponentReconciler

type TMIComponentReconciler struct {
	client.Client
	Scheme *runtime.Scheme
	// Streams provisions the JetStream stream and durable consumer for each
	// component. It is optional: envtest unit tests have no NATS and leave it
	// nil, which skips provisioning.
	Streams StreamProvisioner
}

TMIComponentReconciler reconciles a TMIComponent into its child objects: a Deployment, a NetworkPolicy, a KEDA ScaledObject, and (when Streams is set) the JetStream stream + durable consumer the ScaledObject watches. Pre-creating the stream and consumer is required for KEDA scale-from-zero: KEDA reads the consumer's pending depth to decide when to scale the worker up from zero, so the consumer must exist before any worker pod runs.

func (*TMIComponentReconciler) Reconcile

func (r *TMIComponentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile is the controller-runtime entrypoint.

func (*TMIComponentReconciler) ReconcileComponent

func (r *TMIComponentReconciler) ReconcileComponent(ctx context.Context, key types.NamespacedName) (ctrl.Result, error)

ReconcileComponent renders and applies the child objects for one component. Split out from Reconcile so tests can drive it directly.

func (*TMIComponentReconciler) SetupWithManager

func (r *TMIComponentReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager registers the reconciler and its owned child types.

Jump to

Keyboard shortcuts

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