fix: report the real file and index in kyaml input errors - #6264
fix: report the real file and index in kyaml input errors#6264PragalvaXFREZ wants to merge 1 commit into
Conversation
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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: PragalvaXFREZ 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 |
|
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 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. |
inpututil.WrapErrorWithFileis supposed to decorate a KRM function errorwith the file and document index the resource came from. It currently
produces
[]: <error>for every input.Two things go wrong in the same statement:
pathandindexalready hold the annotation values (deployment.yaml,3), but they are then used as keys in a secondmeta.Annotationslookup.That lookup misses, so both format arguments are empty strings.
indexreadsLegacyPathAnnotationinstead ofLegacyIndexAnnotation, so a resource carrying only the legacy annotationsresolves 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 resolutionkioutil.GetFileAnnotationsalready performs correctly for the identical pair of annotations.
Anything built on
inpututil.MapInputs/MapInputsEis affected: the error afunction author surfaces cannot name the offending file or document, which is
the whole purpose of the wrapper.
Before
After
The
kyaml/inpututilpackage had no tests; this adds one covering both theinternal and legacy annotation forms. All 34 packages in the
kyamlmodulestill pass.