Repository navigation
Conversation
kyaml drops a leading "---" when it round-trips a file: the reader consumes the marker and the encoder only writes a separator ahead of the second and later documents in a stream. Files that begin with an explicit document start therefore come back without one, which shows up as spurious diffs in tools that patch manifests in place, and as failures in repositories whose YAML linters require the marker. Add PreserveDocStart to ByteReader and LocalPackageReader, mirroring PreserveSeqIndent: the reader records the marker in an internal annotation, and ByteWriter re-emits it for the first document. Off by default, so existing output is unchanged.
|
|
|
Welcome @aausch! |
|
Hi @aausch. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: aausch The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
What this does
Adds
PreserveDocStarttokio.ByteReaderandkio.LocalPackageReader, mirroring the existingPreserveSeqIndentoption. When set, a leading---is recorded in theinternal.config.kubernetes.io/docstartannotation at read time and re-emitted byByteWriterfor the first document of the stream. It is off by default, so no existing output changes.Why
kyaml drops a leading
---on round trip. The reader consumes the marker, and the encoder only writes a separator ahead of the second and later documents, so a file that began with an explicit document start comes back without one.This is visible to anyone who patches manifests in place with kyaml. The case I hit is Flux's image-automation-controller, which rewrites an image tag in a manifest and commits the result: every such commit also silently strips the
---, which then fails YAML linters that require the marker. It 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" — correct as of today, hence this option. The companion change is fluxcd/image-automation-controller#1093, which sets the flag and is blocked on a kyaml release carrying this.Implementation notes
splitDocumentssplits on a separator preceded by a newline, so a marker only survives in the original text of the first document; every later document is written with a separator regardless.List/ResourceListare a single document and carry no marker of their own, so the wrapping path is untouched.kioutil.DocStartAnnotationis added toapi/resource.BuildAnnotationsalongsideSeqIndentAnnotation.Tests
TestByteReadWriter_PreserveDocStart— marker preserved, no marker invented, marker dropped when the option is off, and both multi-document orderings round-trip unchanged.TestByteReadWriter_PreserveDocStartOmitReaderAnnotations— the option conflicts withOmitReaderAnnotations, matching howPreserveSeqIndentbehaves.TestLocalPackageReader_Read_PreserveDocStart— the annotation reaches only the resource that was preceded by a marker.go test ./...passes inkyamland inapi.This PR was written in part with the assistance of generative AI.
/kind feature