Skip to content

fix: preserve hash lines in block scalars as content - #6287

Draft
somaz94 wants to merge 2 commits into
kubernetes-sigs:masterfrom
somaz94:fix/edit-block-scalar-comments
Draft

somaz94 wants to merge 2 commits into
kubernetes-sigs:masterfrom
somaz94:fix/edit-block-scalar-comments

Conversation

@somaz94

@somaz94 somaz94 commented Sep 22, 2026

Copy link
Copy Markdown

Summary

kustomize edit previously collected all lines starting with # as field comments, regardless of indentation, causing lines inside YAML block scalars (|, >) to be misinterpreted as comments. This caused those lines to be duplicated on each run and inserted before the following field. This PR introduces indentation tracking for block scalar headers so lines inside a block scalar are recognized as content rather than field comments.

Rationale

Editing a kustomization.yaml that contains multiline scripts or configs inside block scalars should be idempotent. Previously, running kustomize edit multiple times duplicated # lines exponentially, changing unrelated transformer content and growing the file without limit.

Related issue

Fixes #6225

While #4481 addresses the broader problem of comment placement and movement across fields, this fix specifically addresses content corruption caused by mistaking block scalar content for field comments.

Assignment and coordination

Assigned via /assign on 2026-09-22 in #6225 (comment) prior to starting the implementation.

Testing

  • Commit 1: Added a regression test in kustomizationfile_test.go that pins the current incorrect output, where # lines inside a block scalar are moved above the field and duplicated.
  • Commit 2: Implemented indentation-aware block scalar handling in kustomizationfile.go and updated the test to expect the input unchanged after a write, which also makes repeated edits idempotent.
  • Ran unit tests locally:
    go test ./kustomize/commands/internal/kustfile/... -v (all tests passed).
  • golangci-lint with the repo config reports 0 issues, and the reproduction script from the issue keeps the marker count at 1 across 5 runs.

AI disclosure

I used Anthropic Claude Code (Claude Opus 5) to trace the root cause, write the fix and the regression test, and run the local checks. It also helped with light edits to this description. I reviewed the full diff and the test results, and wrote the commit messages and this description myself.

@kubernetes-prow

Copy link
Copy Markdown
Contributor

This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

Details

Instructions 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.

@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: somaz94
Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @somaz94!

It looks like this is your first PR to kubernetes-sigs/kustomize 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kustomize has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow kubernetes-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 22, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @somaz94. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@kubernetes-prow kubernetes-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 22, 2026
@somaz94
somaz94 marked this pull request as draft September 22, 2026 07:52
@kubernetes-prow kubernetes-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 22, 2026
@somaz94 somaz94 changed the title Fix/edit block scalar comments fix: preserve hash lines in block scalars as content Sep 22, 2026
somaz94 added a commit to somaz94/somaz94 that referenced this pull request Sep 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kustomize edit set image exponentially duplicates block-scalar content

1 participant