From 6c568f09eac40de90874ad35dcf10fe2811325bb Mon Sep 17 00:00:00 2001 From: manslaughter03 Date: Sun, 2 Feb 2025 12:24:53 +0100 Subject: [PATCH] Iterate over dependencies in a chart tarball during lint action Signed-off-by: manslaughter03 --- cmd/helm/lint.go | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/cmd/helm/lint.go b/cmd/helm/lint.go index 9a3f7a2fc..cec850b38 100644 --- a/cmd/helm/lint.go +++ b/cmd/helm/lint.go @@ -27,6 +27,7 @@ import ( "github.com/spf13/cobra" "helm.sh/helm/v4/pkg/action" + "helm.sh/helm/v4/pkg/chart/loader" "helm.sh/helm/v4/pkg/chartutil" "helm.sh/helm/v4/pkg/cli/values" "helm.sh/helm/v4/pkg/getter" @@ -67,16 +68,35 @@ func newLintCmd(out io.Writer) *cobra.Command { if client.WithSubcharts { for _, p := range paths { - filepath.Walk(filepath.Join(p, "charts"), func(path string, info os.FileInfo, _ error) error { - if info != nil { - if info.Name() == "Chart.yaml" { - paths = append(paths, filepath.Dir(path)) - } else if strings.HasSuffix(path, ".tgz") || strings.HasSuffix(path, ".tar.gz") { - paths = append(paths, path) + if strings.HasSuffix(p, ".tgz") || strings.HasSuffix(p, ".tar.gz") { + c, err := loader.Load(p) + if err != nil { + return err + } + for _, d := range c.Dependencies() { + tempDir, err := os.MkdirTemp("", "helm-lint") + if err != nil { + return errors.Wrap(err, "unable to create temp dir to extract tarball") + } + defer os.RemoveAll(tempDir) + archive, err := chartutil.Save(d, tempDir) + if err != nil { + return err } + paths = append(paths, archive) } - return nil - }) + } else { + filepath.Walk(filepath.Join(p, "charts"), func(path string, info os.FileInfo, _ error) error { + if info != nil { + if info.Name() == "Chart.yaml" { + paths = append(paths, filepath.Dir(path)) + } else if strings.HasSuffix(path, ".tgz") || strings.HasSuffix(path, ".tar.gz") { + paths = append(paths, path) + } + } + return nil + }) + } } }