manifestrenderer

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 4 Imported by: ? 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.

README

manifest-renderer-go

One typed source → a Helm chart and a kustomize overlay and an OpenShift variant — byte-stable — so chart-vs-manifest drift becomes structurally impossible.

What

A single typed Source (name, image, replicas, ports, env, labels) is rendered by three pure functions to three manifest dialects:

Verb Output
Source.RenderHelm() Chart.yaml + values.yaml + templates/ manifests
Source.RenderKustomize() base/ objects + overlays/default/kustomization.yaml
Source.RenderOpenShift() OpenShift manifests (SCC-aware Deployment + Route)

Each returns a Files (path → bytes) map whose Paths() iterate in lexicographic order. The renderers are pure functions of the Source: the same input yields identical bytes on every call (deterministic key ordering, no map-iteration nondeterminism, no timestamps).

Why

Teams maintain a Helm chart, a hand-written kustomize tree, and an OpenShift manifest set for the same service — and they drift. A replica bump lands in the chart but not the overlay; a security-context tweak lands in kustomize but not OpenShift. The cure is one typed source of truth and pure renderers: the three dialects are projections of the same value, so they cannot disagree. Byte-stability makes the rendered artifacts safe to commit and diff in CI.

Install

go get github.com/pleme-io/manifest-renderer-go

Usage

src, err := manifestrenderer.New("api",
    manifestrenderer.WithImage("ghcr.io/acme/api", "1.4.0"),
    manifestrenderer.WithReplicas(3),
    manifestrenderer.WithPort("http", 8080),
    manifestrenderer.WithEnv("LOG_LEVEL", "info"),
    manifestrenderer.WithNamespace("prod"))
if err != nil {
    return errs.Exit(err) // typed code-carrying error (manifest_invalid)
}

helm, _ := src.RenderHelm()
for _, path := range helm.Paths() {
    os.WriteFile(path, helm[path], 0o644)
}

Configuration

None — a pure library. Callers that read the workload shape from config use shikumi-go and pass the fields via the functional options. A FromConfig bridge over a shikumi-loaded Source-shaped struct is the natural extension when a consumer wants config-driven rendering.

Release

Pull-model (Go modules): an annotated vX.Y.Z tag is the release; pkg.go.dev indexes it. See the GSDS module delivery FSM.

Documentation

Overview

Package manifestrenderer is the fleet's one typed source → manifest-dialect renderer — so a workload is declared ONCE as a typed Source and rendered, byte-stable, to a Helm chart, a kustomize overlay, and an OpenShift variant. This kills chart-vs-manifest drift: the three dialects can never disagree because they are projections of the same typed value.

Why

Teams routinely maintain a Helm chart AND a hand-written kustomize tree AND an OpenShift manifest set for the same service. They drift — a replica bump lands in the chart but not the overlay, a security-context tweak lands in kustomize but not OpenShift. The cure is a single typed source of truth and pure, deterministic renderers.

Shape (Law 1, §3.5)

src := manifestrenderer.New("api",
    manifestrenderer.WithImage("ghcr.io/acme/api", "1.4.0"),
    manifestrenderer.WithReplicas(3),
    manifestrenderer.WithPort("http", 8080))
chart, err := src.RenderHelm()       // map[path]bytes — a complete chart
overlay, err := src.RenderKustomize() // map[path]bytes — base + overlay
ocp, err := src.RenderOpenShift()     // OpenShift-flavoured manifests

Every renderer is a pure function of the Source: same input → identical bytes, every time (deterministic key ordering, no maps iterated in render order, no timestamps). That byte-stability is the property that makes the rendered artifacts safe to commit and diff in CI.

Weight (Law 6)

Pure standard library plus errors-go for typed, code-carrying errors. No YAML dependency: the deterministic emitter is internal so the rendered bytes are owned by this package, not by an upstream marshaller's formatting choices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnvVar

type EnvVar struct {
	Name  string
	Value string
}

EnvVar is a literal environment variable. Secret-valued env is intentionally out of scope here — secret materialization is a separate concern.

type Files

type Files map[string][]byte

Files is a rendered artifact set: a path → bytes map. Use Files.Paths for a deterministically-ordered iteration so callers writing the set to disk (and diffing it in CI) get stable ordering.

func (Files) Paths

func (f Files) Paths() []string

Paths returns the file paths sorted lexicographically — deterministic order for writing and diffing.

type Option

type Option func(*Source)

Option configures a Source during New. Options apply in order, so a later option of the same kind overrides an earlier one.

func WithEnv

func WithEnv(name, value string) Option

WithEnv appends a literal environment variable.

func WithImage

func WithImage(image, tag string) Option

WithImage sets the container image repository and tag.

func WithLabel

func WithLabel(key, value string) Option

WithLabel sets one extra label.

func WithNamespace

func WithNamespace(ns string) Option

WithNamespace sets the target namespace.

func WithPort

func WithPort(name string, port int) Option

WithPort appends a named port.

func WithReplicas

func WithReplicas(n int) Option

WithReplicas sets the desired replica count.

func WithServiceAccount

func WithServiceAccount(name string) Option

WithServiceAccount sets the workload service account.

type Port

type Port struct {
	Name string
	Port int
}

Port is a named container/service port.

type Source

type Source struct {
	// Name is the workload name; it seeds resource names, labels, and the Helm
	// chart name. Required.
	Name string
	// Namespace is the target namespace. Empty leaves it unset (rendered into
	// the kustomize overlay / Helm release namespace by the deploy tool).
	Namespace string
	// Image is the container image repository (without the tag). Required.
	Image string
	// Tag is the container image tag. Defaults to "latest".
	Tag string
	// Replicas is the desired replica count. Defaults to 1.
	Replicas int
	// Ports are the named container ports, kept sorted by name for stable
	// output.
	Ports []Port
	// Env are the environment variables, kept sorted by name for stable output.
	Env []EnvVar
	// Labels are extra labels merged onto the standard label set, kept sorted by
	// key for stable output.
	Labels map[string]string
	// ServiceAccount is the workload's service account name. Empty uses the
	// namespace default.
	ServiceAccount string
}

Source is the one typed declaration of a workload. Every dialect renderer is a pure projection of this value, so the dialects can never drift from one another.

Construct a Source with New and functional options rather than building the struct literal directly; the constructor applies defaults and validates the invariants (notably a non-empty name and a non-empty image) in one place.

func New

func New(name string, opts ...Option) (*Source, error)

New builds and validates a Source. It returns a typed, code-carrying error (code "manifest_invalid") when a required field is missing.

func (*Source) RenderHelm

func (s *Source) RenderHelm() (Files, error)

RenderHelm renders the source as a complete, byte-stable Helm chart: a Chart.yaml, a values.yaml, and templated manifests under templates/. The templates render concrete manifests (no Go-template expansion) so the chart's rendered output equals the kustomize/OpenShift output object-for-object — that equality is the drift-killer.

func (*Source) RenderKustomize

func (s *Source) RenderKustomize() (Files, error)

RenderKustomize renders the source as a kustomize base plus an overlay. The base holds the raw objects; the overlay holds a kustomization.yaml that references the base and pins the namespace/image tag — the canonical base+overlay split. Output is byte-stable.

func (*Source) RenderOpenShift

func (s *Source) RenderOpenShift() (Files, error)

RenderOpenShift renders the source as OpenShift-flavoured manifests: the same objects as the K8s base, minus the runAsNonRoot securityContext (the OpenShift SCC assigns the UID), plus a Route for the first port when one exists. Output is byte-stable.

Jump to

Keyboard shortcuts

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