diff --git a/ct/cmd/root.go b/ct/cmd/root.go index 56c8609d..c792c819 100644 --- a/ct/cmd/root.go +++ b/ct/cmd/root.go @@ -95,6 +95,8 @@ func addCommonLintAndInstallFlags(flags *pflag.FlagSet) { specified on a per-repo basis with an equals sign as delimiter (e.g. 'myrepo=--username test --password secret'). May be specified multiple times or separate values with commas`)) + flags.StringSlice("helm-dependency-extra-args", []string{}, heredoc.Doc(` + Additional arguments for 'helm dependency build' (e.g. ["--skip-refresh"]`)) flags.Bool("debug", false, heredoc.Doc(` Print CLI calls of external tools to stdout (caution: setting this may expose sensitive data when helm-repo-extra-args contains passwords)`)) diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index 96b1b7da..ff5e4d1f 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -67,6 +67,8 @@ type Git interface { // // BuildDependencies builds the chart's dependencies // +// BuildDependenciesWithArgs allows passing additional arguments to BuildDependencies +// // LintWithValues runs `helm lint` for the given chart using the specified values file. // Pass a zero value for valuesFile in order to run lint without specifying a values file. // @@ -82,6 +84,7 @@ type Git interface { type Helm interface { AddRepo(name string, url string, extraArgs []string) error BuildDependencies(chart string) error + BuildDependenciesWithArgs(chart string, extraArgs []string) error LintWithValues(chart string, valuesFile string) error InstallWithValues(chart string, valuesFile string, namespace string, release string) error Upgrade(chart string, namespace string, release string) error @@ -367,7 +370,7 @@ func (t *Testing) processCharts(action func(chart *Chart) TestResult) ([]TestRes defer t.git.RemoveWorktree(worktreePath) for _, chart := range charts { - if err := t.helm.BuildDependencies(t.computePreviousRevisionPath(chart.Path())); err != nil { + if err := t.helm.BuildDependenciesWithArgs(t.computePreviousRevisionPath(chart.Path()), t.config.HelmDependencyExtraArgs); err != nil { // Only print error (don't exit) if building dependencies for previous revision fails. fmt.Println(errors.Wrapf(err, "Error building dependencies for previous revision of chart '%s'\n", chart)) } @@ -375,7 +378,7 @@ func (t *Testing) processCharts(action func(chart *Chart) TestResult) ([]TestRes } for _, chart := range charts { - if err := t.helm.BuildDependencies(chart.Path()); err != nil { + if err := t.helm.BuildDependenciesWithArgs(chart.Path(), t.config.HelmDependencyExtraArgs); err != nil { return nil, errors.Wrapf(err, "Error building dependencies for chart '%s'", chart) } diff --git a/pkg/chart/chart_test.go b/pkg/chart/chart_test.go index 829ccf80..024c093f 100644 --- a/pkg/chart/chart_test.go +++ b/pkg/chart/chart_test.go @@ -89,10 +89,16 @@ func (l *fakeLinter) Yamale(yamlFile, schemaFile string) error { return nil } -type fakeHelm struct{} +type fakeHelm struct { + *mock.Mock +} -func (h fakeHelm) AddRepo(name, url string, extraArgs []string) error { return nil } -func (h fakeHelm) BuildDependencies(chart string) error { return nil } +func (h fakeHelm) AddRepo(name, url string, extraArgs []string) error { return nil } +func (h fakeHelm) BuildDependencies(chart string) error { return nil } +func (h fakeHelm) BuildDependenciesWithArgs(chart string, extraArgs []string) error { + h.Called(chart, extraArgs) + return nil +} func (h fakeHelm) LintWithValues(chart string, valuesFile string) error { return nil } func (h fakeHelm) InstallWithValues(chart string, valuesFile string, namespace string, release string) error { return nil @@ -320,6 +326,29 @@ func TestLintYamlValidation(t *testing.T) { runTests(false, 0, 0) } +func TestLintDependencyExtraArgs(t *testing.T) { + chart := "testdata/test_lints" + args := []string{"--skip-refresh"} + + fakeMockHelm := new(fakeHelm) + ct.helm = fakeMockHelm + ct.config.HelmDependencyExtraArgs = args + ct.config.Charts = []string{chart} + + t.Run("lint-helm-dependency-extra-args", func(t *testing.T) { + call := fakeMockHelm.On("BuildDependenciesWithArgs", chart, args).Return(nil) + call.Repeatability = 1 + + results, err := ct.LintCharts() + assert.Nil(t, err) + for _, result := range results { + assert.Nil(t, result.Error) + } + // -1 is set after Repeatability runs out + assert.Equal(t, -1, call.Repeatability) + }) +} + func TestGenerateInstallConfig(t *testing.T) { type testData struct { name string diff --git a/pkg/config/config.go b/pkg/config/config.go index 466534c8..33f2acee 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -41,30 +41,31 @@ var ( ) type Configuration struct { - Remote string `mapstructure:"remote"` - TargetBranch string `mapstructure:"target-branch"` - Since string `mapstructure:"since"` - BuildId string `mapstructure:"build-id"` - LintConf string `mapstructure:"lint-conf"` - ChartYamlSchema string `mapstructure:"chart-yaml-schema"` - ValidateMaintainers bool `mapstructure:"validate-maintainers"` - ValidateChartSchema bool `mapstructure:"validate-chart-schema"` - ValidateYaml bool `mapstructure:"validate-yaml"` - AdditionalCommands []string `mapstructure:"additional-commands"` - CheckVersionIncrement bool `mapstructure:"check-version-increment"` - ProcessAllCharts bool `mapstructure:"all"` - Charts []string `mapstructure:"charts"` - ChartRepos []string `mapstructure:"chart-repos"` - ChartDirs []string `mapstructure:"chart-dirs"` - ExcludedCharts []string `mapstructure:"excluded-charts"` - HelmExtraArgs string `mapstructure:"helm-extra-args"` - HelmRepoExtraArgs []string `mapstructure:"helm-repo-extra-args"` - Debug bool `mapstructure:"debug"` - Upgrade bool `mapstructure:"upgrade"` - SkipMissingValues bool `mapstructure:"skip-missing-values"` - Namespace string `mapstructure:"namespace"` - ReleaseLabel string `mapstructure:"release-label"` - ExcludeDeprecated bool `mapstructure:"exclude-deprecated"` + Remote string `mapstructure:"remote"` + TargetBranch string `mapstructure:"target-branch"` + Since string `mapstructure:"since"` + BuildId string `mapstructure:"build-id"` + LintConf string `mapstructure:"lint-conf"` + ChartYamlSchema string `mapstructure:"chart-yaml-schema"` + ValidateMaintainers bool `mapstructure:"validate-maintainers"` + ValidateChartSchema bool `mapstructure:"validate-chart-schema"` + ValidateYaml bool `mapstructure:"validate-yaml"` + AdditionalCommands []string `mapstructure:"additional-commands"` + CheckVersionIncrement bool `mapstructure:"check-version-increment"` + ProcessAllCharts bool `mapstructure:"all"` + Charts []string `mapstructure:"charts"` + ChartRepos []string `mapstructure:"chart-repos"` + ChartDirs []string `mapstructure:"chart-dirs"` + ExcludedCharts []string `mapstructure:"excluded-charts"` + HelmExtraArgs string `mapstructure:"helm-extra-args"` + HelmRepoExtraArgs []string `mapstructure:"helm-repo-extra-args"` + HelmDependencyExtraArgs []string `mapstructure:"helm-dependency-extra-args"` + Debug bool `mapstructure:"debug"` + Upgrade bool `mapstructure:"upgrade"` + SkipMissingValues bool `mapstructure:"skip-missing-values"` + Namespace string `mapstructure:"namespace"` + ReleaseLabel string `mapstructure:"release-label"` + ExcludeDeprecated bool `mapstructure:"exclude-deprecated"` } func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*Configuration, error) { diff --git a/pkg/tool/helm.go b/pkg/tool/helm.go index ffea48ab..db895759 100644 --- a/pkg/tool/helm.go +++ b/pkg/tool/helm.go @@ -37,7 +37,11 @@ func (h Helm) AddRepo(name string, url string, extraArgs []string) error { } func (h Helm) BuildDependencies(chart string) error { - return h.exec.RunProcess("helm", "dependency", "build", chart) + return h.BuildDependenciesWithArgs(chart, []string{}) +} + +func (h Helm) BuildDependenciesWithArgs(chart string, extraArgs []string) error { + return h.exec.RunProcess("helm", "dependency", "build", chart, extraArgs) } func (h Helm) LintWithValues(chart string, valuesFile string) error {