Skip to content

Commit 24b47f0

Browse files
committed
introduce helm-dependency-extra-args
addresses #368
1 parent 0a093e4 commit 24b47f0

File tree

5 files changed

+69
-30
lines changed

5 files changed

+69
-30
lines changed

ct/cmd/root.go

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ func addCommonLintAndInstallFlags(flags *pflag.FlagSet) {
9595
specified on a per-repo basis with an equals sign as delimiter
9696
(e.g. 'myrepo=--username test --password secret'). May be specified
9797
multiple times or separate values with commas`))
98+
flags.StringSlice("helm-dependency-extra-args", []string{}, heredoc.Doc(`
99+
Additional arguments for 'helm dependency build' (e.g. ["--skip-refresh"]`))
98100
flags.Bool("debug", false, heredoc.Doc(`
99101
Print CLI calls of external tools to stdout (caution: setting this may
100102
expose sensitive data when helm-repo-extra-args contains passwords)`))

pkg/chart/chart.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ type Git interface {
6767
//
6868
// BuildDependencies builds the chart's dependencies
6969
//
70+
// BuildDependenciesWithArgs allows passing additional arguments to BuildDependencies
71+
//
7072
// LintWithValues runs `helm lint` for the given chart using the specified values file.
7173
// Pass a zero value for valuesFile in order to run lint without specifying a values file.
7274
//
@@ -82,6 +84,7 @@ type Git interface {
8284
type Helm interface {
8385
AddRepo(name string, url string, extraArgs []string) error
8486
BuildDependencies(chart string) error
87+
BuildDependenciesWithArgs(chart string, extraArgs []string) error
8588
LintWithValues(chart string, valuesFile string) error
8689
InstallWithValues(chart string, valuesFile string, namespace string, release string) error
8790
Upgrade(chart string, namespace string, release string) error
@@ -367,15 +370,15 @@ func (t *Testing) processCharts(action func(chart *Chart) TestResult) ([]TestRes
367370
defer t.git.RemoveWorktree(worktreePath)
368371

369372
for _, chart := range charts {
370-
if err := t.helm.BuildDependencies(t.computePreviousRevisionPath(chart.Path())); err != nil {
373+
if err := t.helm.BuildDependenciesWithArgs(t.computePreviousRevisionPath(chart.Path()), t.config.HelmDependencyExtraArgs); err != nil {
371374
// Only print error (don't exit) if building dependencies for previous revision fails.
372375
fmt.Println(errors.Wrapf(err, "Error building dependencies for previous revision of chart '%s'\n", chart))
373376
}
374377
}
375378
}
376379

377380
for _, chart := range charts {
378-
if err := t.helm.BuildDependencies(chart.Path()); err != nil {
381+
if err := t.helm.BuildDependenciesWithArgs(chart.Path(), t.config.HelmDependencyExtraArgs); err != nil {
379382
return nil, errors.Wrapf(err, "Error building dependencies for chart '%s'", chart)
380383
}
381384

pkg/chart/chart_test.go

+32-3
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,16 @@ func (l *fakeLinter) Yamale(yamlFile, schemaFile string) error {
8989
return nil
9090
}
9191

92-
type fakeHelm struct{}
92+
type fakeHelm struct {
93+
mock.Mock
94+
}
9395

94-
func (h fakeHelm) AddRepo(name, url string, extraArgs []string) error { return nil }
95-
func (h fakeHelm) BuildDependencies(chart string) error { return nil }
96+
func (h fakeHelm) AddRepo(name, url string, extraArgs []string) error { return nil }
97+
func (h fakeHelm) BuildDependencies(chart string) error { return nil }
98+
func (h fakeHelm) BuildDependenciesWithArgs(chart string, extraArgs []string) error {
99+
h.Called(chart, extraArgs)
100+
return nil
101+
}
96102
func (h fakeHelm) LintWithValues(chart string, valuesFile string) error { return nil }
97103
func (h fakeHelm) InstallWithValues(chart string, valuesFile string, namespace string, release string) error {
98104
return nil
@@ -320,6 +326,29 @@ func TestLintYamlValidation(t *testing.T) {
320326
runTests(false, 0, 0)
321327
}
322328

329+
func TestLintDependencyExtraArgs(t *testing.T) {
330+
chart := "testdata/test_lints"
331+
args := []string{"--skip-refresh"}
332+
333+
fakeMockHelm := new(fakeHelm)
334+
ct.helm = fakeMockHelm
335+
ct.config.HelmDependencyExtraArgs = args
336+
ct.config.Charts = []string{chart}
337+
338+
t.Run("lint-helm-dependency-extra-args", func(t *testing.T) {
339+
call := fakeMockHelm.On("BuildDependenciesWithArgs", chart, args).Return(nil)
340+
call.Repeatability = 1
341+
342+
results, err := ct.LintCharts()
343+
assert.Nil(t, err)
344+
for _, result := range results {
345+
assert.Nil(t, result.Error)
346+
}
347+
// -1 is set after Repeatability runs out
348+
assert.Equal(t, -1, call.Repeatability)
349+
})
350+
}
351+
323352
func TestGenerateInstallConfig(t *testing.T) {
324353
type testData struct {
325354
name string

pkg/config/config.go

+25-24
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,31 @@ var (
4141
)
4242

4343
type Configuration struct {
44-
Remote string `mapstructure:"remote"`
45-
TargetBranch string `mapstructure:"target-branch"`
46-
Since string `mapstructure:"since"`
47-
BuildId string `mapstructure:"build-id"`
48-
LintConf string `mapstructure:"lint-conf"`
49-
ChartYamlSchema string `mapstructure:"chart-yaml-schema"`
50-
ValidateMaintainers bool `mapstructure:"validate-maintainers"`
51-
ValidateChartSchema bool `mapstructure:"validate-chart-schema"`
52-
ValidateYaml bool `mapstructure:"validate-yaml"`
53-
AdditionalCommands []string `mapstructure:"additional-commands"`
54-
CheckVersionIncrement bool `mapstructure:"check-version-increment"`
55-
ProcessAllCharts bool `mapstructure:"all"`
56-
Charts []string `mapstructure:"charts"`
57-
ChartRepos []string `mapstructure:"chart-repos"`
58-
ChartDirs []string `mapstructure:"chart-dirs"`
59-
ExcludedCharts []string `mapstructure:"excluded-charts"`
60-
HelmExtraArgs string `mapstructure:"helm-extra-args"`
61-
HelmRepoExtraArgs []string `mapstructure:"helm-repo-extra-args"`
62-
Debug bool `mapstructure:"debug"`
63-
Upgrade bool `mapstructure:"upgrade"`
64-
SkipMissingValues bool `mapstructure:"skip-missing-values"`
65-
Namespace string `mapstructure:"namespace"`
66-
ReleaseLabel string `mapstructure:"release-label"`
67-
ExcludeDeprecated bool `mapstructure:"exclude-deprecated"`
44+
Remote string `mapstructure:"remote"`
45+
TargetBranch string `mapstructure:"target-branch"`
46+
Since string `mapstructure:"since"`
47+
BuildId string `mapstructure:"build-id"`
48+
LintConf string `mapstructure:"lint-conf"`
49+
ChartYamlSchema string `mapstructure:"chart-yaml-schema"`
50+
ValidateMaintainers bool `mapstructure:"validate-maintainers"`
51+
ValidateChartSchema bool `mapstructure:"validate-chart-schema"`
52+
ValidateYaml bool `mapstructure:"validate-yaml"`
53+
AdditionalCommands []string `mapstructure:"additional-commands"`
54+
CheckVersionIncrement bool `mapstructure:"check-version-increment"`
55+
ProcessAllCharts bool `mapstructure:"all"`
56+
Charts []string `mapstructure:"charts"`
57+
ChartRepos []string `mapstructure:"chart-repos"`
58+
ChartDirs []string `mapstructure:"chart-dirs"`
59+
ExcludedCharts []string `mapstructure:"excluded-charts"`
60+
HelmExtraArgs string `mapstructure:"helm-extra-args"`
61+
HelmRepoExtraArgs []string `mapstructure:"helm-repo-extra-args"`
62+
HelmDependencyExtraArgs []string `mapstructure:"helm-dependency-extra-args"`
63+
Debug bool `mapstructure:"debug"`
64+
Upgrade bool `mapstructure:"upgrade"`
65+
SkipMissingValues bool `mapstructure:"skip-missing-values"`
66+
Namespace string `mapstructure:"namespace"`
67+
ReleaseLabel string `mapstructure:"release-label"`
68+
ExcludeDeprecated bool `mapstructure:"exclude-deprecated"`
6869
}
6970

7071
func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*Configuration, error) {

pkg/tool/helm.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ func (h Helm) AddRepo(name string, url string, extraArgs []string) error {
3737
}
3838

3939
func (h Helm) BuildDependencies(chart string) error {
40-
return h.exec.RunProcess("helm", "dependency", "build", chart)
40+
return h.BuildDependenciesWithArgs(chart, []string{})
41+
}
42+
43+
func (h Helm) BuildDependenciesWithArgs(chart string, extraArgs []string) error {
44+
return h.exec.RunProcess("helm", "dependency", "build", chart, extraArgs)
4145
}
4246

4347
func (h Helm) LintWithValues(chart string, valuesFile string) error {

0 commit comments

Comments
 (0)