Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update helm default chart name and namespace values #589

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/iac-providers/helm/v3/load-dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func (h *HelmV3) createHelmChartResource(chartPath string, chartData map[string]
// renderChart renders a helm chart with the given template files and values
// returns and IaC document for each rendered file
func (h *HelmV3) renderChart(chartPath string, chartMap helmChartData, templateDir string, templateFiles []*string, valueMap map[string]interface{}) ([]*utils.IacDocument, error) {
const defaultNamespaceName = "default"

iacDocuments := make([]*utils.IacDocument, 0)
logger := zap.S().With("helm chart path", chartPath)

Expand Down Expand Up @@ -195,8 +197,8 @@ func (h *HelmV3) renderChart(chartPath string, chartMap helmChartData, templateD

// create rendered values
options := chartutil.ReleaseOptions{
Name: defaultChartName,
Namespace: chartName + "-namespace",
Name: chartName,
Namespace: defaultNamespaceName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would Namespace always be default? Why did we previously have this value equal to chartName + "-namespace"? I am just trying to understand how is this change affecting terrascan? and what are the repercussions of not having this.

Copy link
Contributor Author

@williepaul williepaul Mar 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. When first adding Helm support, I was not sure where the name field was being pulled from. I remember wanting to use the original chart name, but from the usage in some of their unit tests, it looked arbitrary. While working on some drift mapping fixes, I noticed Helm really was using the Chart name in this field, and hence the name change.

As for the namespace change, "default" is just used by default. However, as you might have wondered, it may be set to something else. Helm takes a namespace command as input, and that namespace specified on the command line is what is fed into this value. We don't currently have a way of passing variables into our provider implementations, but I think we should add some option to do so, for example -Dkey=value, where in this case a user could specify something like -Dnamespace=mynamespace. It's important to us, since without a way to do this, we will not be able to map resources in custom namespaces correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@williepaul , I am wondering, is PR partially fixing the problem? And the complete solution would be to accept options from the user and to exact mappings?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What Willie and I were trying to figure out when looking at this last week: helm by default will use the namespace of the current kubernetes context. So how do we map that into a static scan?

Copy link
Contributor Author

@williepaul williepaul Mar 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kanchwala-yusuf that is correct. A complete solution should take in command line input with data to replace the chart name and namespace as needed. However, these values are suitable defaults, and are currently needed and used by the k8s scan and drift mapping...

Let's put it this way--these defaults are more suitable than the current ones, up until we have implemented the optional overrides from the command line

}

v, err := chartutil.ToRenderValues(c, valueMap, options, nil)
Expand Down
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 @@ -22,7 +22,6 @@ type HelmV3 struct{}
type helmChartData map[string]interface{}

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