model

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 8 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 model resolves a validated spec against the catalog into the resolved model: every default applied, edges derived from uses, listeners chosen, and private segments computed for plaintext edges. Every output is generated from this model.

Index

Constants

View Source
const (
	DefaultAppMemory = "256m"
	DefaultAppCPUs   = "0.5"
	// Used when an app opts into an HTTP health check with `health`.
	DefaultAppHealthPath = "/healthz"
	DefaultAppHealthPort = spec.DefaultHealthPort
)

Defaults for app services.

View Source
const (
	DiscoveryRegistry = "registry"
	DiscoveryRoute    = "route"
)

Discovery values.

Variables

This section is empty.

Functions

func HostName

func HostName(label, experiment string) string

HostName is a host name for a target or instance label: <label>.<experiment>.localhost.

func SegmentFQDN

func SegmentFQDN(service, domain string) string

SegmentFQDN is a service's alias on its private segment.

Types

type Edge

type Edge struct {
	From     string
	To       string
	Listener string
	Port     int
	TLS      bool
	Reason   string // why the edge is plaintext
	// Via is the name (within the app) of the Envoy sidecar whose outbound
	// listener carries the edge; empty for an edge from uses.
	Via string
	// ToApp marks an edge whose target is an app (all its replicas).
	ToApp bool
	// Mode is set on a proxy's upstream edges: spec.TLSOn (re-encrypt),
	// spec.TLSOff (terminate) or spec.TLSPassthrough. From is the proxy.
	Mode string
	// Discovery is set on the edges of a proxy that discovers routes in a
	// service registry (D-225): DiscoveryRegistry to the registry, and
	// DiscoveryRoute to each app registered there for the proxy.
	Discovery string
}

Edge is a directed connection from an app (by its name in experiment.yaml) to an infra listener, through an Envoy sidecar to another app or an infra service, or from a proxy to one of its upstreams, to the registry it discovers routes in, or to an app it finds there.

type Kind

type Kind string

Kind separates catalog infrastructure from user code.

const (
	// Infra is a service from the infrastructure catalog.
	Infra Kind = "infra"
	// App is the user's own program.
	App Kind = "app"
	// Sidecar runs in an app instance's network namespace and uses its
	// certificate: a type from the sidecar catalog, or the agent that
	// registers the app with a service registry (consul-agent).
	Sidecar Kind = "sidecar"
)

type Model

type Model struct {
	Name     string
	Domain   string
	Project  string // compose project name: bb-<name>
	Services []*Service
	Edges    []Edge
	Segments []Segment
}

Model is a fully resolved experiment.

func Resolve

func Resolve(s *spec.Spec, domain string) (*Model, error)

Resolve builds the model from a spec that already passed spec.Validate.

func (*Model) EdgesFrom

func (m *Model) EdgesFrom(name string) []Edge

EdgesFrom lists an app's edges: uses order, then Envoy outbound targets.

func (*Model) HostRouter

func (m *Model) HostRouter() (*Service, bool)

HostRouter returns the lab's host router, if it has one.

func (*Model) Instances

func (m *Model) Instances(app string) []*Service

Instances lists an app's instances in order.

func (*Model) PlaintextEdges

func (m *Model) PlaintextEdges() []Edge

PlaintextEdges lists edges that deliberately skip TLS.

func (*Model) Segment

func (m *Model) Segment(target string) (Segment, bool)

Segment returns the private segment of a target service.

func (*Model) SegmentsOf

func (m *Model) SegmentsOf(name string) []Segment

SegmentsOf lists the segments a service belongs to, as target or client.

func (*Model) Service

func (m *Model) Service(name string) (*Service, bool)

Service returns a service by name.

type Segment

type Segment struct {
	Name    string // compose network name, e.g. plain-postgres
	Target  string // an infra service, or an app (every replica joins)
	Clients []string
	Reasons []string
	// Port is the plaintext port an app target listens on (it receives
	// BB_PLAIN_LISTEN_ADDR); zero for an infra target, whose catalog
	// entry binds its own plaintext listener.
	Port int
}

Segment is a private network shared by a plaintext listener and its clients.

type Service

type Service struct {
	Name      string
	Kind      Kind
	FQDN      string
	Identity  string
	Resources catalog.Resources
	// Image is the container image: the exact pin for infra and sidecars;
	// empty for apps, which are built from their directory.
	Image string
	// Aliases are the DNS names on the default network and on the
	// service's certificate (infra and apps): the FQDN, plus the app's
	// shared name for a replica.
	Aliases []string

	// Infra only.
	Entry  *catalog.Entry
	Config map[string]string
	// Upstreams are a proxy's resolved backends, in spec order.
	Upstreams []catalog.Upstream
	// File is a proxy's user-owned config, relative to experiment.yaml.
	File string
	// StaticFile is a proxy's user-owned static configuration, relative
	// to experiment.yaml, merged into its generated one.
	StaticFile string
	// HostRouter marks the engine-owned host router (spec.HostRouterName),
	// an infra service of type traefik; HostTargets are what it serves,
	// in route order (ADR-0017).
	HostRouter  bool
	HostTargets []catalog.HostTarget

	// App only.
	App *spec.App
	// Health is the app's HTTP health check, or nil for the default check
	// that the container's main process is running. Apps need no health code.
	Health *spec.Health
	// AppName is the app in experiment.yaml this instance belongs to; it
	// equals Name for an app with one replica.
	AppName string
	// Instance is 1…N for a replica, 0 for an app with one replica.
	Instance int
	// SharedFQDN is <app>.<domain>, an alias on every replica.
	SharedFQDN string
	// Pod is the service name of the instance's namespace holder, or empty
	// when the app keeps its own namespace (no sidecars).
	Pod string
	// Netinit is the service name of the pod's init container, which
	// installs its traffic rules (transparent mode, the plaintext guard of
	// a terminate target), or empty.
	Netinit string
	// Transparent is set when an Envoy sidecar captures the instance's
	// traffic.
	Transparent bool
	// PlainGuard is set when the instance is the target of a terminating
	// proxy: it runs as a pod, and its netinit confines the plaintext port
	// to the instance's segment address.
	PlainGuard bool
	// Sidecars are the instance's sidecar service names, in spec order
	// (the registration agent last).
	Sidecars []string

	// Sidecar only. For consul-agent, Entry is the registry's catalog entry.
	Parent      string           // the app instance whose namespace it shares
	SidecarType *sidecar.Type    // its sidecar catalog type
	Sidecar     *spec.Sidecar    // the declared entry, defaults applied; nil for consul-agent
	Targets     []sidecar.Target // Envoy outbound targets
	Registry    string           // consul-agent: the registry service it joins
	Register    *spec.Register   // consul-agent: what it registers, defaults applied
}

Service is an infra or app service with everything defaulted.

func (*Service) Group

func (s *Service) Group() string

Group is the app a service belongs to: AppName for an app instance, the name itself otherwise.

Jump to

Keyboard shortcuts

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