Skip to content

fix: report the real file and index in kyaml input errors - #6264

Open
PragalvaXFREZ wants to merge 1 commit into
kubernetes-sigs:masterfrom
PragalvaXFREZ:fix-inpututil-wrap-error-with-file
Open

fix: report the real file and index in kyaml input errors#6264
PragalvaXFREZ wants to merge 1 commit into
kubernetes-sigs:masterfrom
PragalvaXFREZ:fix-inpututil-wrap-error-with-file

Conversation

@PragalvaXFREZ

Copy link
Copy Markdown

inpututil.WrapErrorWithFile is supposed to decorate a KRM function error
with the file and document index the resource came from. It currently
produces []: <error> for every input.

Two things go wrong in the same statement:

path := meta.Annotations[kioutil.PathAnnotation]
index := meta.Annotations[kioutil.IndexAnnotation]
if path == "" {
	path = meta.Annotations[kioutil.LegacyPathAnnotation]
}
if index == "" {
	index = meta.Annotations[kioutil.LegacyPathAnnotation]
}
return errors.WrapPrefixf(err, "%s [%s]",
	meta.Annotations[path],
	meta.Annotations[index])
  1. path and index already hold the annotation values (deployment.yaml,
    3), but they are then used as keys in a second meta.Annotations lookup.
    That lookup misses, so both format arguments are empty strings.
  2. The legacy fallback for index reads LegacyPathAnnotation instead of
    LegacyIndexAnnotation, so a resource carrying only the legacy annotations
    resolves its index to the file path.

The fix uses the values that were already resolved and reads the index from
LegacyIndexAnnotation. This is the same resolution kioutil.GetFileAnnotations
already performs correctly for the identical pair of annotations.

Anything built on inpututil.MapInputs / MapInputsE is affected: the error a
function author surfaces cannot name the offending file or document, which is
the whole purpose of the wrapper.

Before

--- FAIL: TestMapInputsEWrapsErrorWithFileAndIndex/internal_annotations
    Error: Error message not equal:
           expected: "deployment.yaml [3]: boom"
           actual  : " []: boom"

After

--- PASS: TestMapInputsEWrapsErrorWithFileAndIndex/internal_annotations
--- PASS: TestMapInputsEWrapsErrorWithFileAndIndex/legacy_annotations
ok  	sigs.k8s.io/kustomize/kyaml/inpututil	0.041s

The kyaml/inpututil package had no tests; this adds one covering both the
internal and legacy annotation forms. All 34 packages in the kyaml module
still pass.

WrapErrorWithFile reads the path and index annotations into local
variables, then passes those values back through meta.Annotations as if
they were keys. The second lookup almost always misses, so every error
returned by inpututil.MapInputs and MapInputsE is prefixed with " []: "
instead of naming the file and document that failed.

The legacy fallback for the index also read LegacyPathAnnotation rather
than LegacyIndexAnnotation, so resources carrying only the legacy
annotations resolved the index to the file path.

Use the values that were already resolved, and read the index from
LegacyIndexAnnotation. This matches kioutil.GetFileAnnotations, which
resolves the same pair of annotations correctly.

Adds a test for the internal and legacy annotation forms; the package
previously had none.

Signed-off-by: Pragalva Sapkota <sapkotapragalva@gmail.com>
@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 9, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: PragalvaXFREZ
Once this PR has been reviewed and has the lgtm label, please assign koba1t 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 kubernetes-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 9, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @PragalvaXFREZ. 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.

Regular contributors should join the org to skip this step.

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 9, 2026
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. 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.

1 participant