From 5de95f8d826a32afebd42290f2511b79260b8c71 Mon Sep 17 00:00:00 2001 From: wawa0210 Date: Tue, 28 Jul 2020 17:01:32 +0800 Subject: [PATCH] fix helm lint --with-subcharts errot Signed-off-by: wawa0210 --- cmd/helm/lint.go | 26 +++++++++++++++++-- ...hart-with-bad-subcharts-with-subcharts.txt | 21 +-------------- .../output/lint-chart-with-bad-subcharts.txt | 8 +----- pkg/action/lint.go | 1 + 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/cmd/helm/lint.go b/cmd/helm/lint.go index a7aac172a..6eb1daae8 100644 --- a/cmd/helm/lint.go +++ b/cmd/helm/lint.go @@ -27,6 +27,8 @@ import ( "github.com/spf13/cobra" "helm.sh/helm/v3/pkg/action" + "helm.sh/helm/v3/pkg/chart/loader" + "helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/cli/values" "helm.sh/helm/v3/pkg/getter" ) @@ -53,6 +55,27 @@ func newLintCmd(out io.Writer) *cobra.Command { if len(args) > 0 { paths = args } + vals, err := valueOpts.MergeValues(getter.All(settings)) + if err != nil { + return err + } + + cp, err := client.ChartPathOptions.LocateChart(paths[0], settings) + if err != nil { + return err + } + + // Check chart dependencies to make sure all are present in /charts + chartRequested, err := loader.Load(cp) + if err != nil { + return err + } + + cvals, err := chartutil.CoalesceValues(chartRequested, vals) + if err != nil { + return nil + } + if client.WithSubcharts { for _, p := range paths { filepath.Walk(filepath.Join(p, "charts"), func(path string, info os.FileInfo, err error) error { @@ -69,7 +92,6 @@ func newLintCmd(out io.Writer) *cobra.Command { } client.Namespace = settings.Namespace() - vals, err := valueOpts.MergeValues(getter.All(settings)) if err != nil { return err } @@ -80,7 +102,7 @@ func newLintCmd(out io.Writer) *cobra.Command { for _, path := range paths { fmt.Fprintf(&message, "==> Linting %s\n", path) - result := client.Run([]string{path}, vals) + result := client.Run([]string{path}, cvals) // All the Errors that are generated by a chart // that failed a lint will be included in the diff --git a/cmd/helm/testdata/output/lint-chart-with-bad-subcharts-with-subcharts.txt b/cmd/helm/testdata/output/lint-chart-with-bad-subcharts-with-subcharts.txt index e77aa387f..dc7373596 100644 --- a/cmd/helm/testdata/output/lint-chart-with-bad-subcharts-with-subcharts.txt +++ b/cmd/helm/testdata/output/lint-chart-with-bad-subcharts-with-subcharts.txt @@ -1,20 +1 @@ -==> Linting testdata/testcharts/chart-with-bad-subcharts -[INFO] Chart.yaml: icon is recommended -[WARNING] templates/: directory not found -[ERROR] : unable to load chart - error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required - -==> Linting testdata/testcharts/chart-with-bad-subcharts/charts/bad-subchart -[ERROR] Chart.yaml: name is required -[ERROR] Chart.yaml: apiVersion is required. The value must be either "v1" or "v2" -[ERROR] Chart.yaml: version is required -[INFO] Chart.yaml: icon is recommended -[WARNING] templates/: directory not found -[ERROR] : unable to load chart - validation: chart.metadata.name is required - -==> Linting testdata/testcharts/chart-with-bad-subcharts/charts/good-subchart -[INFO] Chart.yaml: icon is recommended -[WARNING] templates/: directory not found - -Error: 3 chart(s) linted, 2 chart(s) failed +Error: error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required diff --git a/cmd/helm/testdata/output/lint-chart-with-bad-subcharts.txt b/cmd/helm/testdata/output/lint-chart-with-bad-subcharts.txt index 265e555f7..dc7373596 100644 --- a/cmd/helm/testdata/output/lint-chart-with-bad-subcharts.txt +++ b/cmd/helm/testdata/output/lint-chart-with-bad-subcharts.txt @@ -1,7 +1 @@ -==> Linting testdata/testcharts/chart-with-bad-subcharts -[INFO] Chart.yaml: icon is recommended -[WARNING] templates/: directory not found -[ERROR] : unable to load chart - error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required - -Error: 1 chart(s) linted, 1 chart(s) failed +Error: error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required diff --git a/pkg/action/lint.go b/pkg/action/lint.go index 2292c14bf..0e5d32d18 100644 --- a/pkg/action/lint.go +++ b/pkg/action/lint.go @@ -33,6 +33,7 @@ import ( // // It provides the implementation of 'helm lint'. type Lint struct { + ChartPathOptions Strict bool Namespace string WithSubcharts bool