Skip to content
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

Fix YamlToObject file splitting. #1298

Merged
merged 1 commit into from
Jan 24, 2020
Merged

Conversation

porridge
Copy link
Member

What this PR does / why we need it:

I wonder how we got away with splitting on any three dashes for so
long.

Fixes #1297

I wonder how we got away with splitting on *any* three dashes for so
long.
Copy link
Contributor

@alenkacz alenkacz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, nice catch :D

@@ -14,7 +14,7 @@ import (
// If the type is not known in the scheme, it tries to parse it as Unstructured
// TODO(av) could we use something else than a global scheme here? Should we somehow inject it?
func YamlToObject(yaml string) (objs []runtime.Object, err error) {
sepYamlfiles := strings.Split(yaml, "---")
sepYamlfiles := strings.Split(yaml, "\n---\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why we have to split the file here. Isn't this something the YAML decoder should take care of? Looking at the documentation of the decoder it looks like this is a supported use case. The Decode functions unmarshals the "next object from the underlying stream". I didn't test this though, but maybe a for-loop that calls Decode would do the splitting?

Not yours, but also wondering why we're using a YAMLOrJSONDecoder when there's a YAMLDecoder?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What Jan said ^^ There is a splitYamlDocument method that should handle multiple YAML documents. Funny enough, the separator it uses is defined as const yamlSeparator = "\n---" so only one \n.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we're using a YAMLOrJSONDecoder when there's a YAMLDecoder?

Turns out YAMLDecoder is not a decoder, it's a ReadCloser 😆
Or at least not in the sense that YAMLOrJSONDecoder provides a Decode function.

@porridge
Copy link
Member Author

Since I'll be away next week, let me merge this now, and I'll investigate the suggested improvements in a subsequent PR.
This way we'll at least already have some fix, in case I don't manage to get this working without an explicit Split before EOD.

@porridge porridge merged commit e57a7b1 into master Jan 24, 2020
@porridge porridge deleted the fix-yaml-to-object-splitting branch January 24, 2020 08:00
ANeumann82 pushed a commit that referenced this pull request Feb 13, 2020
I wonder how we got away with splitting on *any* three dashes for so
long.

Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
runyontr pushed a commit that referenced this pull request Mar 11, 2020
I wonder how we got away with splitting on *any* three dashes for so
long.

Signed-off-by: Thomas Runyon <runyontr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Template parsing fails with --- in multi-line fields
4 participants