provision

package
v0.4.41 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package provision installs the Tiny Systems runtime and capability modules onto a cluster by embedding the Helm Go SDK (via mittwald's go-helm-client) — no shelling out to a `helm` binary, no hosted platform.

A full runtime is four helm releases from the public chart repo https://tiny-systems.github.io/module/:

tinysystems-crd              CRDs (TinyModule/TinyNode/TinyFlow/…)
tinysystems-nats             NATS/JetStream broker — durable transport + run ledger
tinysystems-otel-collector   trace collector
tinysystems-operator         the module itself (one release per module, image-parameterised)

The sequence and module values mirror the platform's install job so a `tiny`-provisioned cluster behaves identically to a hosted one — minus the multi-tenant machinery (no DB, no job locks, one namespace, one owner).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseValues

func BaseValues(image, release, version, namespace, natsURL string) map[string]any

BaseValues builds the harness (operator-chart) values that every module install needs regardless of the module — the plumbing `moduleValues` constructs today, re-expressed as a nested values map derived from the install plan instead of the old catalog. The module's own values.yaml overlay (rbac / ingress / storage) is merged on top of this by the caller.

`release` doubles as the operator's identity (`--name`): it is the coexistence-safe `<module>-v<major>` release name, so two majors of a module register as distinct operators in one namespace and their TinyNodes bind to the right one. (This replaces today's workspace-qualified `tinysystems/http-module-v0` identity.)

func BrokerURL

func BrokerURL(ctx context.Context, cfg *rest.Config, namespace string) string

BrokerURL returns the authenticated broker URL clients connect with — nats://<token>@tinysystems-nats.<ns>.svc:4222 — reading the token the nats chart generated into its auth secret. Falls back to the tokenless URL (never errors) when the secret is absent: a pre-auth broker or a transient read still connects, so auth degrades gracefully instead of hard-failing.

func EnsureNamespace

func EnsureNamespace(ctx context.Context, cfg *rest.Config, namespace string) error

EnsureNamespace creates the target namespace if absent and labels it tinysystems.io/managed=true — the dedication marker the operator chart's pre-install hook requires. Must run before any module install. Idempotent: on an already-labeled namespace it's a single read.

func SanitizeResourceName

func SanitizeResourceName(s string) string

SanitizeResourceName lowercases and reduces an arbitrary name to a valid RFC-1123 helm release / resource name: [a-z0-9-], no leading/trailing dash, capped at 53 chars. "tinysystems/http-module-v0" → "tinysystems-http-module-v0".

func SaveSettings

func SaveSettings(ctx context.Context, cfg *rest.Config, namespace string, s Settings) error

SaveSettings persists the non-empty settings as namespace annotations (a merge patch — it never clears an existing annotation).

Types

type Client

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

Client wraps a helm client bound to one cluster + namespace, with the tinysystems chart repo already added.

func NewClient

func NewClient(cfg *rest.Config, namespace string, debug io.Writer) (*Client, error)

NewClient builds a helm client against cfg/namespace and registers the public chart repo. Pass a non-nil debug writer to surface helm's own (verbose) log; nil keeps installs quiet.

func (*Client) InstallBroker

func (c *Client) InstallBroker(ctx context.Context) error

InstallBroker installs the NATS/JetStream broker. Deliberately no Force: the broker is a StatefulSet holding the durable run ledger, and forcing a replace would risk its persistent state.

func (*Client) InstallCRDs

func (c *Client) InstallCRDs(ctx context.Context) error

InstallCRDs installs the CRD chart. Cluster-scoped resources, but the release lives in the target namespace (single-owner cluster — none of the multi-tenant CRD-ownership dance the platform needs).

func (*Client) InstallModule

func (c *Client) InstallModule(ctx context.Context, m *catalog.Module, natsURL string, settings Settings) (string, error)

InstallModule installs one capability module as a tinysystems-operator release parameterised by the module's image. Returns the helm release name. natsURL wires the broker so durable execution is on out of the box; pass "" to leave the module in blocking-only mode.

func (*Client) InstallOTEL

func (c *Client) InstallOTEL(ctx context.Context) error

InstallOTEL installs the trace collector.

func (*Client) Lookup added in v0.4.41

func (c *Client) Lookup(_ context.Context, _, release string) (string, bool, error)

Lookup reports the module image ref of whatever occupies a helm release name, or found=false when the release isn't installed.

It satisfies repo.InstalledModules structurally — primitives only, so this package still does not import internal/repo, matching how BaseValues and UpgradeInstall are wired.

The image is the authoritative identity of an installed release: it is literally what the pod runs, so it distinguishes two publishers shipping the same module name without needing any extra bookkeeping.

A release that isn't installed is not an error — that is the normal case on a fresh cluster, and helm reports it as one.

func (*Client) UpgradeInstall

func (c *Client) UpgradeInstall(ctx context.Context, release, namespace, chart, version string, vals map[string]any) error

UpgradeInstall installs or upgrades an arbitrary chart with a full values map — the generic helm primitive the repo-model installer drives. It makes *Client structurally satisfy repo.Helm (no import of the repo package needed; Go interfaces are structural). Mirrors the install flags used elsewhere (create-namespace, wait, atomic, cleanup-on-fail). Nothing calls it until the install/up cutover; adding it is non-breaking.

type Settings

type Settings struct {
	IngressClass string
	DomainSuffix string
	StorageClass string
	StorageSize  string // default 1Gi when a module needs storage
	// Issuer is the cert-manager (Cluster)Issuer name to annotate ingresses
	// with for TLS; ClusterIssuer selects cluster-issuer vs namespace issuer.
	Issuer        string
	ClusterIssuer bool
}

Settings are cluster-wide install values — properties of YOUR cluster, not of any one module: which ingress controller, the base domain, the storage class. They're persisted as annotations on the tinysystems namespace, so they travel with the cluster and every module install reads them. Set them once (flags on `tiny up`/`tiny install`); modules that need them pick them up.

func LoadSettings

func LoadSettings(ctx context.Context, cfg *rest.Config, namespace string) (Settings, error)

LoadSettings reads the saved cluster settings off the namespace annotations.

func (Settings) Empty

func (s Settings) Empty() bool

Empty reports whether no setting is present.

func (Settings) Merge

func (s Settings) Merge(o Settings) Settings

Merge overlays o's non-empty fields onto s (o wins). Used to layer this-invocation flags over the cluster's saved settings.

Jump to

Keyboard shortcuts

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