yamlstyle

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package yamlstyle owns the one YAML serialization style this product writes to Git.

It exists because the product's entire output is a Git diff, and two encoders producing two styles makes that diff unreadable. A resource created by the writer used to render its sequences at the parent key's indentation (JSON→YAML, via sigs.k8s.io/yaml), while the same resource EDITED IN PLACE re-encoded them two columns deeper (gopkg.in/yaml.v3). Both are valid YAML and both round-trip, so nothing failed — but the first update after a create rewrote every list line in the file to carry one changed field, which defeats the point of mirroring into Git at all.

This package is deliberately tiny and deliberately dependency-free: it holds the style, not the projection. What is clean enough to write is internal/sanitize's decision; the node tree of an edited document is internal/git/manifestedit's. Both encode through here.

Why sigs.k8s.io/yaml is still in the tree

Because it is not a second renderer of manifests, and consolidating it into this one would be a bug rather than a cleanup. Every remaining call to it either PARSES (a decoder imposes no style) or serializes a Go struct whose fields carry only JSON tags: the analyzer's report, whose contract is that its YAML and its JSON name every field identically, and the in-memory kustomization copies handed to kustomize during a render. Encoding those through yaml.v3 would emit Go field names instead of the API's, and none of those bytes are ever committed.

One style authority for what reaches Git; the JSON-tag round-trip stays where it belongs. TestGitWritePathHasNoSecondEncoder holds the line.

Index

Constants

View Source
const Indent = 2

Indent is the indentation every document this product writes uses. It matches common manifest style rather than yaml.v3's 4-space default.

Two columns is also the only choice available: yaml.v3 always indents a sequence under its mapping key, so the style a create used to emit (sequence dashes at the key's own column, which is what yaml.v2 and therefore sigs.k8s.io/yaml produce) cannot be expressed by the encoder that edits documents in place. Aligning on this direction was forced by that, and it is the better direction anyway: it is what every file in a repository the operator has updated once already looks like.

Variables

This section is empty.

Functions

func Encode

func Encode(v any) ([]byte, error)

Encode serializes any value in the house style.

func NodeFor

func NodeFor(v any) (*yaml.Node, error)

NodeFor builds the node for one value, so a caller assembling a document in a chosen key order encodes each value with the same encoder that will write the result.

Types

This section is empty.

Jump to

Keyboard shortcuts

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