Documentation
¶
Overview ¶
Package seed loads a directory of manifest YAMLs into Postgres at boot.
It is app/apply driven from a directory: the same parse → mint → translate → diff → upsert path the control plane's POST /apply runs, with no authorizer (boot has no actor) and no prune (a catalog tree is additive). ClearDirty maps to apply's Force. Everything else — bucket order, id minting, the dirty-row skip, the change vocabulary — lives in app/apply. The one step of its own is DetachDropped: it marks the catalog rows a new catalog release no longer ships instead of deleting them.
Index ¶
- Constants
- func Channel() string
- func CreateMissingSystemRateLimits(ctx context.Context, store systemRateLimitStore, defs []*ratelimit.RateLimit) ([]string, error)
- func DirVersion(dir string) string
- func FetchCatalog(ctx context.Context, urlTemplate, version, destDir string) (string, error)
- func IsLatestAlias(v string) bool
- func ResolveLatest(ctx context.Context, indexURL, channel string) (string, error)
- type Options
- type Result
- type SystemRateLimits
Constants ¶
const DefaultCatalogIndexURL = "https://raw.githubusercontent.com/wyolet/relay-catalog/main/index.yaml"
DefaultCatalogIndexURL is where the channel index is fetched from when RELAY_CATALOG_INDEX_URL is unset. The index maps schema channels to the newest catalog release published for them, so a relay only ever resolves "latest" within the apiVersion it can parse.
const DefaultCatalogURLTemplate = "https://github.com/wyolet/relay-catalog/archive/{version}.tar.gz"
DefaultCatalogURLTemplate is where versioned catalog trees are fetched from when RELAY_CATALOG_URL is unset. "{version}" is replaced with the requested ref; GitHub serves source archives for any tag/branch/sha.
Variables ¶
This section is empty.
Functions ¶
func Channel ¶ added in v0.9.9
func Channel() string
Channel is the schema channel key this binary resolves "latest" against: the version segment of the manifest apiVersion ("v1alpha2").
func CreateMissingSystemRateLimits ¶ added in v0.10.3
func CreateMissingSystemRateLimits(ctx context.Context, store systemRateLimitStore, defs []*ratelimit.RateLimit) ([]string, error)
CreateMissingSystemRateLimits writes each definition whose name has no row and returns the names it created. A row that exists is never written, whoever owns it and whatever it holds, so an operator's edit or disable survives every boot.
func DirVersion ¶ added in v0.9.9
DirVersion returns the release stamp of a local catalog tree (the .version file next to the data), or "" when the tree is unstamped.
func FetchCatalog ¶ added in v0.5.0
FetchCatalog downloads the catalog source archive for version from urlTemplate ("{version}" substituted; empty = DefaultCatalogURLTemplate), extracts it under destDir, and returns the directory holding the catalog data tree. Only regular files and directories are extracted — symlinks and entries escaping destDir are rejected.
The returned root follows the source-archive convention: a top-level `data/` dir wins (directly under destDir, or inside a single wrapping directory the way GitHub archives unpack); otherwise destDir itself is assumed to be the data tree.
func IsLatestAlias ¶ added in v0.9.9
IsLatestAlias reports whether v selects channel-latest resolution instead of naming a concrete catalog release.
func ResolveLatest ¶ added in v0.9.9
ResolveLatest fetches the channel index (indexURL, empty = DefaultCatalogIndexURL) and returns the newest catalog release for channel. A channel absent from the index is an error — it means no catalog release exists for this binary's schema version.
Types ¶
type Options ¶
type Options struct {
Pool *pgxpool.Pool
YAMLDir string
MasterKey []byte // for stored-mode HostKey rows; nil disables them
// ClearDirty re-seeds (overwrites) rows an operator has edited, resetting
// them to the catalog version and clearing their dirty flag. Default false:
// dirty rows are skipped so re-seeding never clobbers operator changes.
ClearDirty bool
// CatalogKindsOnly refuses the non-catalog kinds. The boot paths set it: a
// catalog tree is fetched by tag from a public repository and must not be
// able to mint a Key, a HostKey, a ServiceAccount or a RoleBinding on the
// way in. Those kinds reach Postgres through `relay seed --apply`,
// `relay apply` or the control API, all of which have an actor to authorize.
CatalogKindsOnly bool
// DetachDropped marks the catalog rows the tree no longer declares with
// CatalogDetachedAt, and clears the mark on clean rows it declares again.
// Only the versioned catalog reseed sets it: there the tree is the whole
// catalog release, so a row it omits is one the release dropped.
DetachDropped bool
}
Options configures a seed run.
type Result ¶
type Result struct {
Teams int
Projects int
Providers int
Hosts int
RateLimits int
HostKeys int
Models int
Pricings int
HostBindings int
Policies int
ServiceAccounts int
Groups int
Roles int
RoleBindings int
PolicyBindings int
Keys int
Overlays int
Users int
Skipped int // dirty rows preserved (operator-edited; not re-seeded)
Detached int // catalog rows the tree no longer declares, marked this run
Reattached int // detached rows the tree declares again, unmarked this run
}
Result summarises a seed run. Per-kind counts are the rows the run reconciled — created, updated, or already matching the manifest.
type SystemRateLimits ¶ added in v0.10.3
type SystemRateLimits struct {
Rows []*ratelimit.RateLimit
// FromDir names the definitions taken from the directory instead of the shipped ones.
FromDir []string
// Ignored lists the directory documents that are not a system rate limit the binary ships, as "Kind/name".
Ignored []string
}
SystemRateLimits is the set of system rate limit definitions a boot seeds.
func LoadSystemRateLimits ¶ added in v0.10.3
func LoadSystemRateLimits(shipped []byte, dir string) (*SystemRateLimits, error)
LoadSystemRateLimits parses the definitions shipped in the binary, then replaces each one a YAML file under dir also defines. Only shipped names are taken from dir: it changes what a built-in row starts as, it does not add rows. A missing dir is not an error.