Documentation
¶
Overview ¶
Package manifest is the shared machinery the manifest.* CD Functions use to mutate Kubernetes GitOps manifests by editing a structured YAML document model, never by splicing strings into manifest text.
The manifest.* Functions all follow the same shape: split a multi-document file into documents, find the one whose kind/metadata.name identifies a target workload, edit the yaml.Node model of just that document, and reassemble the file so every sibling document is preserved byte-for-byte. This package owns the pieces of that shape that aren't specific to any one Function: document splitting/classification (Classify), workload matching (FindDocument), reassembly (Rebuild), node navigation (Navigate, MapValue), safe mutation (SetStringScalar, SetMapValue), and indentation-matched re-serialization (Encode).
It is deliberately free of any dependency on step-runner or the Function domain types — it operates on manifest text and yaml.Node values alone — so each Function can layer its own inputs, validation, and matching policy on top.
Index ¶
- func Encode(doc *yaml.Node) (string, error)
- func FindDocument(spansByFile [][]DocSpan, kinds map[string]bool, name string) (fileIdx, segIdx, count int)
- func MapValue(m *yaml.Node, key string) *yaml.Node
- func Navigate(node *yaml.Node, keys ...string) *yaml.Node
- func Rebuild(content string, spans []DocSpan, edits map[int]string) string
- func SetMapValue(m *yaml.Node, key string, value *yaml.Node)
- func SetStringScalar(m *yaml.Node, key, value string)
- type DocSpan
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Encode ¶
Encode serializes a single-document yaml.Node with indentation matched to the source document's (see detectIndent) so a manifest that isn't 2-space indented doesn't produce a large formatting-only diff. yaml.v3 may still normalize some cosmetic formatting (blank lines, scalar quoting) on the edited document; the byte-for-byte guarantee is for sibling documents, which are never re-encoded.
func FindDocument ¶
func FindDocument(spansByFile [][]DocSpan, kinds map[string]bool, name string) (fileIdx, segIdx, count int)
FindDocument locates the single document across a file set whose kind is in kinds and whose metadata.name equals name. spansByFile[i] holds the documents of file i (as returned by Classify). It returns the matched file and segment indices and the number of documents that matched: the count lets the caller distinguish a missing workload (0) from an ambiguous one (>1) and wrap its own sentinel errors. When count != 1 the indices are unspecified and must not be used.
func MapValue ¶
MapValue returns the value node for key in a mapping node, or nil. A mapping node stores keys and values as alternating Content entries.
func Navigate ¶
Navigate walks a chain of mapping keys from node, returning the value node at the end or nil if any hop is missing or isn't a mapping.
func Rebuild ¶
Rebuild reassembles a file from its original content, replacing only the documents named in edits and copying everything else — separators and untouched documents alike — verbatim.
func SetMapValue ¶
SetMapValue sets key in mapping m to the given value node, replacing the existing value node when key is present and appending a new key/value pair otherwise. Unlike SetStringScalar (which edits a scalar in place), this replaces the whole value node, so it's the way to set or replace a nested subtree such as spec.strategy.
func SetStringScalar ¶
SetStringScalar sets key in mapping m to a literal string scalar, adding the key if it's absent. Resetting Kind/Tag/Style (and clearing any anchor/alias/children) on an existing value node guarantees the value is emitted as data, never as a structural node — so a value containing YAML metacharacters or newlines can't introduce new keys. An existing value node is reset in place (preserving its position and line info) rather than replaced, so re-serialization stays byte-stable.
Types ¶
type DocSpan ¶
DocSpan locates one YAML document within a file's content by byte offset, and carries the kind/name read from a cheap probe unmarshal. Offsets (rather than copies) let a caller rewrite only the matched document and splice every other document back verbatim, so siblings are preserved byte-for-byte.