Skip to content

fix: split YAML documents with the Kubernetes YAML reader - #56

Merged
MPV merged 1 commit into
masterfrom
claude/robust-yaml-splitting
Aug 9, 2026
Merged

fix: split YAML documents with the Kubernetes YAML reader#56
MPV merged 1 commit into
masterfrom
claude/robust-yaml-splitting

Conversation

@MPV

@MPV MPV commented Jul 23, 2026

Copy link
Copy Markdown
Owner

What

Split YAML documents with apimachinery's YAMLReader (via a new streaming yamlparser.ProcessReader) instead of bytes.Split on the literal "\n---\n".

Before → After

A two-document manifest whose separator has trailing whitespace — --- followed by spaces, common in hand-edited and templated YAML:

$ kir pods.yaml

# before
img-a:1                    # second document silently dropped: "\n---   \n" != "\n---\n"

# after
img-a:1
img-b:2

Verified against master. CRLF (\r\n) line endings are the other real case — bytes.Split misses that separator too and drops everything after the first document. (Leading --- and a missing final newline are not affected; they're kept in the unit test only as general correctness checks.)

Why

bytes.Split on the literal separator is fragile: any variation glues documents together so every one after the first is lost. Both the file and stdin paths now stream through one ProcessReader, so their splitting behaves identically and matches how Kubernetes itself parses manifests.

Note on error text

Returning ProcessData's error directly also drops the redundant error processing document: wrapper, so a genuine parse failure now reads error: <cause> instead of error: error processing document: <cause>.

Release

Based on master. fix: → patch.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Pc6NAURAqjU4LYJx93tgSC

@MPV
MPV force-pushed the claude/robust-yaml-splitting branch from 9941ad2 to 1fb8717 Compare July 23, 2026 07:09
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch 2 times, most recently from 7d70b66 to dd5529b Compare July 23, 2026 08:24
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch from dd5529b to 324f980 Compare July 24, 2026 06:45
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch from 324f980 to 129d31d Compare August 2, 2026 08:01
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch from 129d31d to 986d4be Compare August 6, 2026 21:06
@MPV MPV changed the title Split YAML documents with the Kubernetes YAML reader fix: split YAML documents with the Kubernetes YAML reader Aug 6, 2026
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch from 986d4be to d33fb0d Compare August 6, 2026 21:52
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch from d33fb0d to d4aabb8 Compare August 8, 2026 21:47
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch from d4aabb8 to b88998a Compare August 8, 2026 22:05
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch from b88998a to 346897e Compare August 8, 2026 22:19
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch from 346897e to 87b97ff Compare August 8, 2026 22:21
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch 2 times, most recently from d961e96 to f90c1f0 Compare August 8, 2026 22:58
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch from f90c1f0 to dfc4134 Compare August 8, 2026 23:02
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch from dfc4134 to 22dd423 Compare August 9, 2026 12:55
Base automatically changed from claude/skip-non-workloads to master August 9, 2026 12:56
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch 3 times, most recently from 937ea8c to 00b8d06 Compare August 9, 2026 20:14
Document splitting used bytes.Split on the literal "\n---\n", which drops
every document after the first when the separator isn't exactly that: a
separator with trailing whitespace ("---   ") or CRLF line endings both
glue the documents together.

Before (two Pods separated by "---" with trailing spaces):
  $ kir pods.yaml
  img-a:1
  # img-b:2 from the second document is silently dropped

After:
  $ kir pods.yaml
  img-a:1
  img-b:2

Replace it with apimachinery's YAMLReader via a new yamlparser.ProcessReader
that streams documents from an io.Reader. Both the file and stdin paths read
through it, so their splitting behaves identically and matches how Kubernetes
itself parses manifests.

Returning ProcessData's error directly also drops the redundant
"error processing document:" wrapper (e.g. malformed YAML now reads
"error: <cause>" instead of "error: error processing document: <cause>"); the
TestFailure/BadYAML golden is updated to match.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pc6NAURAqjU4LYJx93tgSC
@MPV
MPV force-pushed the claude/robust-yaml-splitting branch from 00b8d06 to dae5df2 Compare August 9, 2026 20:15
@MPV
MPV merged commit d487e61 into master Aug 9, 2026
1 check passed
@MPV
MPV deleted the claude/robust-yaml-splitting branch August 9, 2026 20:21
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.

2 participants