From a9c20a2eb7375218f6be63f36c1231b9ed0188c2 Mon Sep 17 00:00:00 2001 From: Donny Xia Date: Tue, 16 Mar 2021 13:09:04 -0700 Subject: [PATCH] handle helm output properly --- api/builtins/HelmChartInflationGenerator.go | 12 +++++++++++- .../HelmChartInflationGenerator.go | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/api/builtins/HelmChartInflationGenerator.go b/api/builtins/HelmChartInflationGenerator.go index 673a8d3fc..65d8d45f5 100644 --- a/api/builtins/HelmChartInflationGenerator.go +++ b/api/builtins/HelmChartInflationGenerator.go @@ -218,7 +218,17 @@ func (p *HelmChartInflationGeneratorPlugin) Generate() (resmap.ResMap, error) { return nil, err } - return p.h.ResmapFactory().NewResMapFromBytes(stdout) + rm, rmfErr := p.h.ResmapFactory().NewResMapFromBytes(stdout) + if rmfErr == nil { + return rm, nil + } + // try to remove the contents before first "---" because + // helm may produce messages to stdout before it + stdoutStr := string(stdout) + if idx := strings.Index(stdoutStr, "---"); idx != -1 { + return p.h.ResmapFactory().NewResMapFromBytes([]byte(stdoutStr[idx:])) + } + return nil, rmfErr } func (p *HelmChartInflationGeneratorPlugin) getTemplateCommandArgs() []string { diff --git a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go index 7c0af7ca7..14f457152 100644 --- a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go +++ b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go @@ -226,7 +226,17 @@ func (p *HelmChartInflationGeneratorPlugin) Generate() (resmap.ResMap, error) { return nil, err } - return p.h.ResmapFactory().NewResMapFromBytes(stdout) + rm, rmfErr := p.h.ResmapFactory().NewResMapFromBytes(stdout) + if rmfErr == nil { + return rm, nil + } + // try to remove the contents before first "---" because + // helm may produce messages to stdout before it + stdoutStr := string(stdout) + if idx := strings.Index(stdoutStr, "---"); idx != -1 { + return p.h.ResmapFactory().NewResMapFromBytes([]byte(stdoutStr[idx:])) + } + return nil, rmfErr } func (p *HelmChartInflationGeneratorPlugin) getTemplateCommandArgs() []string {