router

package
v0.13.0 Latest Latest
Warning

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

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

Documentation

Overview

Package router is the edge request matcher (ADR-0110, F79): it compiles the Ready Route set into a host/path/method table and resolves a public data-plane request to a target (namespace, function). It RESOLVES, it does not proxy — the data-plane handler then runs the existing activator hop, so scale-to-zero is preserved. It is an internal component (interface + one table impl); no external driver is anticipated (the external gateway is the gateway.Gateway port's V2 concern, not this invoke-path matcher).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregator

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

Aggregator is the sole writer of a Router's replace-all edge table and the one arbiter of its claims (ADR-0138, ADR-0176): it stores each source's entries, rules on every entry, and programs the winners. Safe for concurrent use.

func NewAggregator

func NewAggregator(p Programmer, modes ModeFunc, notify NotifyFunc, log *slog.Logger) *Aggregator

NewAggregator builds an Aggregator over the edge Router's replace-all Program. A nil modes treats every namespace as implicit; a nil notify notifies no one; a nil log is slog.Default.

func (*Aggregator) Set

func (a *Aggregator) Set(ctx context.Context, source string, entries []Entry) ([]Verdict, error)

Set replaces source's entries, arbitrates every stored entry, and programs the winners in one Router.Program call under the lock. It returns the verdicts of source's entries in their order, then notifies every owner of another source whose verdict changed.

type CompiledRule

type CompiledRule struct {
	Path     string          // the rule prefix, e.g. "/orders"
	Exact    bool            // pathType == Exact
	Methods  map[string]bool // nil/empty ⇒ all methods
	Function v1.ObjectName
	// Static, when non-nil, is a static Bucket-prefix backend (ADR-0120, F82); Function is then unused
	// and the data-plane serves it via internal/edge/static (no activator hop).
	Static *v1.StaticBackend
	// Upstream, when non-empty, is a NODE-PRIVATE in-daemon reverse-proxy target (ADR-0138): the
	// data-plane reverse-proxies a match here instead of resolving a Function/Static. It is set ONLY
	// by trusted in-daemon reconcilers (the CatalogService reconciler → its catalog::query PEP proxy),
	// never from a user-authored Route — a user backend has no Upstream arm, so the edge cannot be
	// pointed at an arbitrary in-daemon address (no SSRF). Function/Static are then unused.
	Upstream string
}

CompiledRule is one path rule ready to match.

type Entry

type Entry struct {
	Namespace v1.NamespaceName
	Host      string      // exact; "" matches any host
	Auth      v1.AuthMode // the Route's edge auth stance (ADR-0113); "" ⇒ inherit the namespace default
	Rules     []CompiledRule
	// Owner is the object the entry belongs to; required by the Aggregator, Owner.Namespace equal to Namespace.
	Owner Owner
}

Entry is one Route's compiled contribution: its host + its rules + its auth stance (F77).

type EntrySetter

type EntrySetter interface {
	Set(ctx context.Context, source string, entries []Entry) ([]Verdict, error)
}

EntrySetter contributes ONE named source's edge entries to a shared edge table (ADR-0138). Set replaces this source's slice (nil/empty clears it); the implementation arbitrates the claims of every source and programs the winners exactly once (ADR-0176). A validation or ModeFunc error returns (nil, err) with nothing committed. A Program error returns (nil, err) with the source map committed, so the next Set re-programs it.

type Match

type Match struct {
	Namespace   v1.NamespaceName
	Function    v1.ObjectName
	StripPrefix string
	Auth        v1.AuthMode // the matched Route's auth stance (ADR-0113); "" ⇒ namespace default
	// Static is non-nil for a static backend (ADR-0120, F82): serve via internal/edge/static, no wake.
	Static *v1.StaticBackend
	// Upstream is non-empty for a node-private reverse-proxy backend (ADR-0138): the data-plane
	// reverse-proxies to it (no activator hop, no Function resolve). Trusted in-daemon target only.
	Upstream string
}

Match is the resolved target. StripPrefix is the matched rule's prefix the handler strips from the request path (empty for an Exact rule) to get the function-relative remainder.

type ModeFunc added in v0.4.0

type ModeFunc func(ctx context.Context, ns v1.NamespaceName) (v1.ExposureMode, error)

ModeFunc reads a namespace's exposure mode; a NotFound error means implicit.

type NotifyFunc added in v0.4.0

type NotifyFunc func(Owner)

NotifyFunc asks the owner's reconciler to run again. It must not block: the aggregator calls it after releasing its lock, once per owner whose verdict another source's Set changed.

type Owner added in v0.4.0

type Owner struct {
	Kind      v1.Kind
	Namespace v1.NamespaceName
	Name      v1.ObjectName
}

Owner names the object an Entry belongs to (ADR-0176): claims are arbitrated and verdicts reported per owner.

type Programmer

type Programmer interface {
	Program(ctx context.Context, entries []Entry) error
}

Programmer is the replace-all sink the Aggregator drives — the edge Router's Program. Router satisfies it; the aggregator depends only on this narrow method.

type Router

type Router interface {
	// Program replaces the live table with the compiled Ready-route entries (mirrors the
	// gateway's replace-all ProgramRoutes).
	Program(ctx context.Context, entries []Entry) error
	// Resolve returns the matched target for (host, path, method), or ok=false ⇒ the caller 404s
	// (no activator wake). The matched entry carries its namespace, so no namespace input is needed.
	Resolve(host, path, method string) (Match, bool)
	// Hosts returns the distinct non-empty hosts currently programmed (F74 reads this for SNI).
	Hosts() []string
}

Router holds the compiled, replace-all Route table and resolves a request to a Match. Concurrency-safe.

func New

func New() Router

New returns an empty edge Router.

type Verdict added in v0.4.0

type Verdict struct {
	Owner   Owner
	Reason  string
	Message string
}

Verdict is the aggregator's ruling on one Entry: Reason "" means the entry is programmed (ADR-0176).

Jump to

Keyboard shortcuts

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