Repository navigation
Accept a string for overlay/match by= on documents - #1022
Merged
joaopapereira merged 1 commit intoOct 26, 2026
Merged
joaopapereira merged 1 commit into
joaopapereira merged 1 commit into
Conversation
The overlay reference describes @overlay/match by= as Function|String
on documents, map items and array items, a string being short-hand for
overlay.map_key() with the same argument. Map items and array items
turn a string into that matcher in MatchNodes, but
DocumentMatchAnnotation.MatchNodes passed by= straight to its type
switch. So this overlay
#@overlay/match by="kind"
---
kind: Deployment
failed with "Expected 'overlay/match' annotation keyword argument 'by'
to be function, but was starlark.String", while
by=overlay.map_key("kind") worked.
DocumentMatchAnnotation.MatchNodes now makes the same conversion as
ArrayItemMatchAnnotation.MatchNodes, and its error for any other type
of by= names both accepted kinds, as the array item error does. A new
filetest checks that by="kind" and by=overlay.map_key("kind") give the
same result when matching documents.
Fixes #303
Signed-off-by: Max Freedom Pollard <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #303.
The
@overlay/matchreference documentsby=asFunction|Stringon documents, map items and array items. A string is short-hand foroverlay.map_key()with the same argument. On a document, the string form fails:by=overlay.map_key("kind")works on the same document.ArrayItemMatchAnnotation.MatchNodes(pkg/yttlibrary/overlay/array_item_match_annotation.go:96) andMapItemMatchAnnotation.MatchNodes(map_item_match_annotation.go:84) turn a stringby=intooverlay.map_key(<string>)before calling it.DocumentMatchAnnotation.MatchNodes(document_match_annotation.go:88) passedby=straight to its type switch, which only accepts a callable.DocumentMatchAnnotation.MatchNodesnow does the same conversion, copied from the array item version.by="kind"on a document now builds the sameoverlay.map_key_matcherthatby=overlay.map_key("kind")builds. For any other type ofby=, the error now readsto be either string (for map key) or function, but was ..., the same text the array item version uses. Exact matching, used when merging data values and data values schema documents, is unchanged because it returns beforeby=is read.Testing
pkg/yamltemplate/filetests/ytt-library/overlay/doc-by-key.tpltestis the document counterpart ofarray-by-key.tpltestandmap-by-key.tpltest. It overlays two left documents twice, once withby="kind"and once withby=overlay.map_key("kind"), and expects both to update only theServicedocument.I have not compiled this change or run the tests: there was no Go toolchain where I made it, so CI will be the first build. What I checked by hand:
mergeDocument,mergeMapItemand the YAML printer, using a small Python model of those paths. No existing test or example asserts the old document error text.line-length-limit(80 columns, tabs counted as 4), and the wrapped lines follow gofmt's continuation style.git diff --checkis clean.Branched from
developatc9dc038.🤖 Generated with Claude Code