Documentation
¶
Overview ¶
Package template renders an App template on the client (ADR-0217): a directory of App spec fragments plus a values schema becomes one typed, checked App. Only cmd/funcdctl imports it; the server never sees a template.
Index ¶
- func CheckLock(t *Template) error
- func EvalRegistry(t *Template, values []json.RawMessage, lock bool) (string, error)
- func ImageRef(registry, repo string, l LockedImage) (string, error)
- func Lock(ctx context.Context, t *Template, registry string, r ImageResolver) (map[string]LockedImage, error)
- func Moved(ctx context.Context, t *Template, registry string, r ImageResolver) []string
- func ReadLock(dir string) (map[string]LockedImage, error)
- func ReadValues(path string) (json.RawMessage, error)
- func Render(t *Template, in RenderInput) (*v1.App, error)
- func WriteLock(dir string, lock map[string]LockedImage) error
- type Image
- type ImageResolver
- type LockedImage
- type RenderInput
- type Template
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckLock ¶
CheckLock refuses a template without a lock, or with a stale one: a lock whose names differ from the images names, or one of whose requested differs from its images entry. It names the first such image in name order.
func EvalRegistry ¶
EvalRegistry merges and validates the values and evaluates registry over them (ADR-0218 Decision 4). With lock, only the values registry reads are validated, against their subschemas, so app lock needs no other value.
func ImageRef ¶
func ImageRef(registry, repo string, l LockedImage) (string, error)
ImageRef is the value an images entry renders to: <registry>/<repo>:<version>@<digest>.
func Lock ¶
func Lock(ctx context.Context, t *Template, registry string, r ImageResolver) (map[string]LockedImage, error)
Lock resolves every images entry at registry, in name order (ADR-0218 Decision 2): an exact entry to the digest of its tag; a range to the highest tag that StrictNewVersion parses and the range accepts, then its digest. It returns nothing on any failure.
func Moved ¶
Moved resolves each locked <registry>/<repo>:<version> once and returns a warning for each tag that now names another digest, and for each check that failed (ADR-0218 Decision 5). It changes nothing.
func ReadLock ¶
func ReadLock(dir string) (map[string]LockedImage, error)
ReadLock reads <dir>/app.lock strictly; nil, nil when it is absent.
func ReadValues ¶
func ReadValues(path string) (json.RawMessage, error)
ReadValues reads one -f file: one YAML 1.2 document whose top level is a mapping, as JSON; an empty file is {}.
func Render ¶
func Render(t *Template, in RenderInput) (*v1.App, error)
Render renders the template into one App (ADR-0217 Decisions 3-7): it merges and validates the values, evaluates registry and every when, routes the scalars of each included fragment, decodes each fragment strictly, appends their sections in file order and runs App.Validate. Each image is the pinned value of its lock entry (ADR-0218 Decision 4), so a template without a lock or with a stale one is refused. It returns nothing unless every step succeeded.
Types ¶
type Image ¶
type Image struct {
Repo string // passes Reference.ValidateRepository
Exact string // the tag when the spec is a version; "" for a range
Range *semver.Constraints // nil when Exact is set
}
Image is an images entry parsed (ADR-0218 Decision 1): a repository and either an exact tag or a range.
func ParseImage ¶
ParseImage parses an images entry <repo>:<spec>, split at the first ":" (a repo carries no host): the spec is an exact version when StrictNewVersion parses it, else a range when NewConstraint parses it. A v before a version, build metadata and a digest are refused.
type ImageResolver ¶
type ImageResolver interface {
Tags(ctx context.Context, repo string) ([]string, error) // every tag of <registry>/<repo>
Digest(ctx context.Context, ref string) (string, error) // the manifest digest of <registry>/<repo>:<tag>
}
ImageResolver reads an image registry for Lock and Moved.
type LockedImage ¶
type LockedImage struct {
Requested string `json:"requested"` // the images entry as written; a mismatch makes the lock stale
Version string `json:"version"` // the tag it resolved to
Digest string `json:"digest"` // sha256:<64 hex>
}
LockedImage is one image of app.lock (ADR-0218 Decision 3).
type RenderInput ¶
type RenderInput struct {
Name v1.ObjectName // empty ⇒ Template.Name
Namespace v1.NamespaceName // empty ⇒ "default"
ResourceGroup v1.ResourceGroupName // empty ⇒ Name
Values []json.RawMessage // the -f files in order, each from ReadValues
}
RenderInput is what an install gives a template: the App's name, namespace and resource group, and the values.
type Template ¶
type Template struct {
Name v1.ObjectName
Version string // strict semver
Registry string // a literal or one ${{ }} over values
Images map[string]string // name → "<repo>:<version or range>", as written
Parsed map[string]Image // name → ParseImage(Images[name]); Load fills it
Lock map[string]LockedImage // app.lock; nil when the directory has none
ValuesSchema json.RawMessage // empty ⇒ {"type":"object"}
When map[string]string // "resources/<file>.yaml" → ${{ }} condition
Files map[string][]byte // "resources/<file>.yaml" → fragment
}
Template is a loaded template directory (ADR-0217 Decisions 1 and 2, ADR-0218 Decisions 1 and 3).