From d592aff9096ffbcbf1898d5daf9f4f02dba4b4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Mon, 13 Sep 2021 17:21:25 +0200 Subject: [PATCH] feat(values): support YAML streams in values files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RaphaĆ«l Pinson --- pkg/cli/values/options.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pkg/cli/values/options.go b/pkg/cli/values/options.go index e6ad71767..ece0c48d4 100644 --- a/pkg/cli/values/options.go +++ b/pkg/cli/values/options.go @@ -17,13 +17,14 @@ limitations under the License. package values import ( + "io" "io/ioutil" "net/url" "os" "strings" "github.com/pkg/errors" - "sigs.k8s.io/yaml" + "k8s.io/apimachinery/pkg/util/yaml" "helm.sh/helm/v3/pkg/getter" "helm.sh/helm/v3/pkg/strvals" @@ -43,18 +44,25 @@ func (opts *Options) MergeValues(p getter.Providers) (map[string]interface{}, er // User specified a values files via -f/--values for _, filePath := range opts.ValueFiles { - currentMap := map[string]interface{}{} - bytes, err := readFile(filePath, p) if err != nil { return nil, err } - if err := yaml.Unmarshal(bytes, ¤tMap); err != nil { - return nil, errors.Wrapf(err, "failed to parse %s", filePath) + decoder := yaml.NewYAMLOrJSONDecoder(strings.NewReader(string(bytes)), 4096) + for { + currentMap := map[string]interface{}{} + + err := decoder.Decode(¤tMap) + if err == io.EOF { + break + } else if err != nil { + return nil, errors.Wrapf(err, "failed to parse %s", filePath) + } + + // Merge with the previous map + base = mergeMaps(base, currentMap) } - // Merge with the previous map - base = mergeMaps(base, currentMap) } // User specified a value via --set