-
-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle multi-document YAML streams #534
base: main
Are you sure you want to change the base?
Conversation
641bcb5
to
c9eb790
Compare
Some updates and random thoughts on this... I've explored another interesting way of handling this in gomplate, which is to have a function ( The problem with this approach, of course, is that you lose chainability - you can't just do I could just return an array, which would make it less flexible, but more predictable. The other challenge is what to do with multi-document YAML stream datasources? A common use-case (for me, at least) is to use a Kubernetes resource YAML file as a datasource, which often contains multiple documents. Right now, gomplate will simply read the first document and ignore the rest. Sometimes this is good enough, sometimes not. Sometimes I'll strip out the One way to do it would be to add a new bogus MIME type like A perhaps more user-friendly way to approach this is to detect whether the stream contains more than one document, and return an array if so, else return the single document. There's a downside here though, with situations where the datasource has an unpredictable number of documents - like a log file, or an arbitrary collection of Kubernetes resources, which could have a single document. Another way to handle this could be to use a fragment in the URL (like 🤔 More thinking probably necessary on this... |
40d5f34
to
5dc0d77
Compare
5dc0d77
to
2ac0dce
Compare
This pull request is stale because it has been open for 60 days with no activity. Remove |
ah, good reminder - thanks bot 😉 it's probably obvious that this has gone nowhere - mostly because I'm stuck figuring out a good API for this |
This pull request is stale because it has been open for 60 days with If it's still relevant, one of the following will remove the stale
|
Note: This probably won't work for a while - I just want to park this here so I don't forget about it 😉
YAML files (or "streams") can contain multiple documents, where the
---
sequence denotes the start of a document. Currentlygomplate
will only parse the first document in the stream, ignoring others.Usually this isn't a big deal, because most YAML files only contain one document, but multi-document streams are becoming more common (like with Kubernetes).
Consider:
I think the behaviour should be:
data.YAML
(MIMEapplication/yaml
), the value should be the first non-empty documentdata.YAMLArray
, the value should be an array of maps (empty ones should benull
)Signed-off-by: Dave Henderson [email protected]