From 7975d8d87f3811c18314e91723fdbb4f18a8aa06 Mon Sep 17 00:00:00 2001 From: Andrzej Stencel Date: Fri, 20 Jan 2023 11:34:41 +0100 Subject: [PATCH] fix(update-collection-v3): fix multiline property rendering Fixes #433 --- src/go/cmd/update-collection-v3/README.md | 2 +- src/go/cmd/update-collection-v3/main.go | 2 +- .../testdata/containerd-multiline.input.yaml | 170 ++++++++++++++++++ .../testdata/containerd-multiline.output.yaml | 168 +++++++++++++++++ .../testdata/multiline.input.yaml | 9 + .../testdata/multiline.output.yaml | 9 + 6 files changed, 358 insertions(+), 2 deletions(-) create mode 100644 src/go/cmd/update-collection-v3/testdata/containerd-multiline.input.yaml create mode 100644 src/go/cmd/update-collection-v3/testdata/containerd-multiline.output.yaml create mode 100644 src/go/cmd/update-collection-v3/testdata/multiline.input.yaml create mode 100644 src/go/cmd/update-collection-v3/testdata/multiline.output.yaml diff --git a/src/go/cmd/update-collection-v3/README.md b/src/go/cmd/update-collection-v3/README.md index 3f317c5e..a1ed014e 100644 --- a/src/go/cmd/update-collection-v3/README.md +++ b/src/go/cmd/update-collection-v3/README.md @@ -48,7 +48,7 @@ make build ## Known issues 1. This package is using github.com/go-yaml/yaml which unfortunately doesn't allow - to maintain `yaml` comments and order when using user defined structutres. + to maintain `yaml` comments and order when using user defined structures. This could be done when we'd use [`yaml.Node`][yaml_node] instead of customized structs which reflect the schema of `values.yaml` used in `sumologic-kubernetes-collection` diff --git a/src/go/cmd/update-collection-v3/main.go b/src/go/cmd/update-collection-v3/main.go index d942e5a6..b3894c94 100644 --- a/src/go/cmd/update-collection-v3/main.go +++ b/src/go/cmd/update-collection-v3/main.go @@ -181,7 +181,7 @@ func reorderYaml(input string, original string) (string, error) { sortByBlueprint(outputMapSlice, originalMapSlice) - outputBytes, err := yaml.MarshalWithOptions(outputMapSlice, yaml.Indent(2)) + outputBytes, err := yaml.MarshalWithOptions(outputMapSlice, yaml.Indent(2), yaml.UseLiteralStyleIfMultiline(true)) return string(outputBytes), err } diff --git a/src/go/cmd/update-collection-v3/testdata/containerd-multiline.input.yaml b/src/go/cmd/update-collection-v3/testdata/containerd-multiline.input.yaml new file mode 100644 index 00000000..1371ea12 --- /dev/null +++ b/src/go/cmd/update-collection-v3/testdata/containerd-multiline.input.yaml @@ -0,0 +1,170 @@ +sumologic: + accessId: xxx + accessKey: yyy + clusterName: containerd-multiline + +fluent-bit: + config: + customParsers: | + [PARSER] + Name containerd_multiline_pattern + Format regex + Regex (?