Skip to content

Commit

Permalink
Fix YamlToObject file splitting. (#1298)
Browse files Browse the repository at this point in the history
I wonder how we got away with splitting on *any* three dashes for so
long.

Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
  • Loading branch information
porridge authored and ANeumann82 committed Feb 13, 2020
1 parent 14e4471 commit 91aa301
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/engine/renderer/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
for _, f := range sepYamlfiles {
if f == "\n" || f == "" {
// ignore empty cases
Expand Down
7 changes: 6 additions & 1 deletion pkg/engine/renderer/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import (
)

func TestParseKubernetesObjects_UnknownType(t *testing.T) {
_, err := YamlToObject(`apiVersion: monitoring.coreos.com/v1
objects, err := YamlToObject(`apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app: prometheus-operator
release: prometheus-kubeaddons
name: spark-cluster-monitor
annotations:
foo: |-
---
multiline
spec:
endpoints:
- interval: 5s
Expand All @@ -25,6 +29,7 @@ spec:
if err != nil {
t.Errorf("Expecting no error but got %s", err)
}
assert.Equal(t, 1, len(objects))
}

func TestParseKubernetesObjects_KnownType(t *testing.T) {
Expand Down

0 comments on commit 91aa301

Please sign in to comment.