Skip to content

Commit

Permalink
fixes review comments
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Willie Sana committed Nov 12, 2020
1 parent 83473ea commit 48b6ea8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 13 additions & 5 deletions pkg/iac-providers/helm/v3/load-dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"}
}
1 change: 0 additions & 1 deletion pkg/iac-providers/helm/v3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type helmChartData map[string]interface{}

const (
defaultChartName = "terrascan"
helmChartFilename = "Chart.yaml"
helmValuesFilename = "values.yaml"
helmTemplateDir = "templates"
helmTestDir = "tests"
Expand Down

0 comments on commit 48b6ea8

Please sign in to comment.