fix helm lint --with-subcharts errot

Signed-off-by: wawa0210 <xiaozhang0210@hotmail.com>
pull/8514/head
wawa0210 5 years ago
parent 0498f0e5a2
commit 5de95f8d82
No known key found for this signature in database
GPG Key ID: 900C83A2C098B3B1

@ -27,6 +27,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/action" "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/cli/values"
"helm.sh/helm/v3/pkg/getter" "helm.sh/helm/v3/pkg/getter"
) )
@ -53,6 +55,27 @@ func newLintCmd(out io.Writer) *cobra.Command {
if len(args) > 0 { if len(args) > 0 {
paths = args 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 { if client.WithSubcharts {
for _, p := range paths { for _, p := range paths {
filepath.Walk(filepath.Join(p, "charts"), func(path string, info os.FileInfo, err error) error { 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() client.Namespace = settings.Namespace()
vals, err := valueOpts.MergeValues(getter.All(settings))
if err != nil { if err != nil {
return err return err
} }
@ -80,7 +102,7 @@ func newLintCmd(out io.Writer) *cobra.Command {
for _, path := range paths { for _, path := range paths {
fmt.Fprintf(&message, "==> Linting %s\n", path) 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 // All the Errors that are generated by a chart
// that failed a lint will be included in the // that failed a lint will be included in the

@ -1,20 +1 @@
==> Linting testdata/testcharts/chart-with-bad-subcharts Error: error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required
[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

@ -1,7 +1 @@
==> Linting testdata/testcharts/chart-with-bad-subcharts Error: error unpacking bad-subchart in chart-with-bad-subcharts: validation: chart.metadata.name is required
[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

@ -33,6 +33,7 @@ import (
// //
// It provides the implementation of 'helm lint'. // It provides the implementation of 'helm lint'.
type Lint struct { type Lint struct {
ChartPathOptions
Strict bool Strict bool
Namespace string Namespace string
WithSubcharts bool WithSubcharts bool

Loading…
Cancel
Save