support for more helm template args (#4926)

* support for more helm template args

* move templateArgs and unit tests to api/types

* undo package name change

* use our own simple helm chart instead of forking one

* add argument to AsHelmArgs

* code review

* lint errors
This commit is contained in:
Natasha Sarkar
2023-02-01 12:19:05 -06:00
committed by GitHub
parent 236166097e
commit 1957d5c746
21 changed files with 432 additions and 85 deletions

View File

@@ -3,6 +3,8 @@
package types
import "path/filepath"
const HelmDefaultHome = "charts"
type HelmGlobals struct {
@@ -57,7 +59,11 @@ type HelmChart struct {
// in the helm template
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
// ValuesFile is local file path to a values file to use _instead of_
// AdditionalValuesFiles are local file paths to values files to be used in
// addition to either the default values file or the values specified in ValuesFile.
AdditionalValuesFiles []string `json:"additionalValuesFiles,omitempty" yaml:"additionalValuesFiles,omitempty"`
// ValuesFile is a local file path to a values file to use _instead of_
// the default values that accompanied the chart.
// The default values are in '{ChartHome}/{Name}/values.yaml'.
ValuesFile string `json:"valuesFile,omitempty" yaml:"valuesFile,omitempty"`
@@ -78,6 +84,15 @@ type HelmChart struct {
// SkipHooks sets the --no-hooks flag when calling helm template. This prevents
// helm from erroneously rendering test templates.
SkipHooks bool `json:"skipHooks,omitempty" yaml:"skipHooks,omitempty"`
// ApiVersions is the kubernetes apiversions used for Capabilities.APIVersions
ApiVersions []string `json:"apiVersions,omitempty" yaml:"apiVersions,omitempty"`
// NameTemplate is for specifying the name template used to name the release.
NameTemplate string `json:"nameTemplate,omitempty" yaml:"nameTemplate,omitempty"`
// SkipTests skips tests from templated output.
SkipTests bool `json:"skipTests,omitempty" yaml:"skipTests,omitempty"`
}
// HelmChartArgs contains arguments to helm.
@@ -126,3 +141,45 @@ func makeHelmChartFromHca(old *HelmChartArgs) (c HelmChart) {
c.ReleaseName = old.ReleaseName
return
}
func (h HelmChart) AsHelmArgs(absChartHome string) []string {
args := []string{"template"}
if h.ReleaseName != "" {
args = append(args, h.ReleaseName)
} else {
// AFAICT, this doesn't work as intended due to a bug in helm.
// See https://github.com/helm/helm/issues/6019
// I've tried placing the flag before and after the name argument.
args = append(args, "--generate-name")
}
if h.Name != "" {
args = append(args, filepath.Join(absChartHome, h.Name))
}
if h.Namespace != "" {
args = append(args, "--namespace", h.Namespace)
}
if h.NameTemplate != "" {
args = append(args, "--name-template", h.NameTemplate)
}
if h.ValuesFile != "" {
args = append(args, "-f", h.ValuesFile)
}
for _, valuesFile := range h.AdditionalValuesFiles {
args = append(args, "-f", valuesFile)
}
for _, apiVer := range h.ApiVersions {
args = append(args, "--api-versions", apiVer)
}
if h.IncludeCRDs {
args = append(args, "--include-crds")
}
if h.SkipTests {
args = append(args, "--skip-tests")
}
if h.SkipHooks {
args = append(args, "--no-hooks")
}
return args
}