From 48b6ea879973612d99972387898b7f2493f726b2 Mon Sep 17 00:00:00 2001 From: Willie Sana Date: Wed, 11 Nov 2020 10:30:53 -0800 Subject: [PATCH] fixes review comments - adds .yml to the valid list of chart yamls - default to 1 instead of 0 for source line in the helm_chart resource - TODO: add values.yml support for rancher --- pkg/iac-providers/helm/v3/load-dir.go | 18 +++++++++++++----- pkg/iac-providers/helm/v3/types.go | 1 - 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/iac-providers/helm/v3/load-dir.go b/pkg/iac-providers/helm/v3/load-dir.go index d464ee709..3b8112b98 100644 --- a/pkg/iac-providers/helm/v3/load-dir.go +++ b/pkg/iac-providers/helm/v3/load-dir.go @@ -47,7 +47,7 @@ func (h *HelmV3) LoadIacDir(absRootDir string) (output.AllResourceConfigs, error allResourcesConfig := make(map[string][]output.ResourceConfig) // find all Chart.yaml files within the specified directory structure - fileMap, err := utils.FindFilesBySuffix(absRootDir, []string{helmChartFilename}) + fileMap, err := utils.FindFilesBySuffix(absRootDir, h.getHelmChartFilenames()) if err != nil { zap.S().Error("error while searching for helm charts", zap.String("root dir", absRootDir), zap.Error(err)) return allResourcesConfig, err @@ -91,7 +91,7 @@ func (h *HelmV3) LoadIacDir(absRootDir string) (output.AllResourceConfigs, error // normalize all rendered IaC documents using the kubernetes code for _, iacDocuments := range iacDocumentMap { for _, doc := range iacDocuments { - // @TODO add k8s version check + // helmv3 supports the kubernetes v1 api var k k8sv1.K8sV1 var config *output.ResourceConfig config, err = k.Normalize(doc) @@ -137,7 +137,7 @@ func (h *HelmV3) createHelmChartResource(chartPath string, chartData map[string] config.Type = "helm_chart" config.Name = chartName - config.Line = 0 + config.Line = 1 config.Source = chartPath config.ID = config.Type + "." + config.Name config.Config = configData @@ -225,7 +225,8 @@ func (h *HelmV3) renderChart(chartPath string, chartMap helmChartData, templateD return iacDocuments, nil } -func (h *HelmV3) loadChart(chartPath string) ([]*utils.IacDocument, map[string]interface{}, error) { +// loadChart renders and loads all templates within a chart path +func (h *HelmV3) loadChart(chartPath string) ([]*utils.IacDocument, helmChartData, error) { iacDocuments := make([]*utils.IacDocument, 0) chartMap := make(helmChartData) logger := zap.S().With("chart path", chartPath) @@ -284,6 +285,13 @@ func (h *HelmV3) loadChart(chartPath string) ([]*utils.IacDocument, map[string]i return iacDocuments, chartMap, err } +// getHelmTemplateExtensions returns valid helm template extensions func (h *HelmV3) getHelmTemplateExtensions() []string { - return []string{"yaml", "tpl"} + return []string{"yaml", "yml", "tpl"} +} + +// getHelmFilenames returns valid chart filenames +func (h *HelmV3) getHelmChartFilenames() []string { + // the main filename is chart.yaml, but rancher contains references to chart.yml + return []string{"Chart.yaml", "Chart.yml"} } diff --git a/pkg/iac-providers/helm/v3/types.go b/pkg/iac-providers/helm/v3/types.go index 2004d8329..13ea94905 100644 --- a/pkg/iac-providers/helm/v3/types.go +++ b/pkg/iac-providers/helm/v3/types.go @@ -23,7 +23,6 @@ type helmChartData map[string]interface{} const ( defaultChartName = "terrascan" - helmChartFilename = "Chart.yaml" helmValuesFilename = "values.yaml" helmTemplateDir = "templates" helmTestDir = "tests"