Skip to content

Preserve explicit YAML document start markers - #1093

Draft
aausch wants to merge 1 commit into
fluxcd:mainfrom
aausch:preserve-doc-start
Draft

aausch wants to merge 1 commit into
fluxcd:mainfrom
aausch:preserve-doc-start

Conversation

@aausch

@aausch aausch commented Sep 25, 2026 •

Copy link
Copy Markdown

Draft: blocked on a kyaml release. The option this sets does not exist in the vendored sigs.k8s.io/kustomize/kyaml yet, so the build fails until kubernetes-sigs/kustomize#6294 merges and ships. I will rebase and bump the dependency then.

Fixes #1094.

What this does

Sets PreserveDocStart: true on the screening reader in internal/update/filereader.go, so a manifest whose first line is --- keeps it after the setter pipeline rewrites the file.

Why

kyaml's reader consumes a leading --- and its writer only separates the second and later documents in a stream, so the marker is lost on round trip. Every automated commit that touches such a file therefore carries an unrelated formatting change, and repositories whose YAML linters require the marker fail on the controller's own commits.

This was reported as fluxcd/flux2#4435 and closed with "That's what kustomize kyaml does when it patches the YAML, nothing we can do about it". That was accurate — kyaml had no way to preserve it. kubernetes-sigs/kustomize#6294 adds one, off by default, mirroring the existing PreserveSeqIndent option this reader already sets; this change opts in.

Tests

internal/update/testdata/setters/{original,expected}/marked.yaml now begin with ---, so TestUpdateWithSetters covers the round trip through UpdateWithSetters and kio.LocalPackageWriter.

Verified locally against the kyaml branch with a temporary replace directive (not committed):

  • with the change: go test ./internal/update/... passes.
  • without it, keeping the fixtures: the test fails on marked.yaml, expecting --- and getting apiVer.... The fixture change is not self-satisfying.

make tidy fmt vet && make test cannot pass until the dependency is available; that gate will be run on the rebase.

Files whose first line is "---" lose the marker when the setter
pipeline rewrites them, because kyaml's reader consumes it and its
writer only separates the second and later documents in a stream. The
result is a formatting change in every automated commit that touches
such a file, and a lint failure in repositories that require the
marker.

Set PreserveDocStart on the screening reader so the marker survives the
round trip. The option is new in kyaml and off by default; no other
formatting behaviour changes.

Signed-off-by: Alex Ausch <alex@ausch.name>
Assisted-by: claude-code/claude-opus-5[1m]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image update strips the explicit YAML document start marker

1 participant