From a3c5eb57f2855747799ff44c4542e6c026a73481 Mon Sep 17 00:00:00 2001 From: cpanato Date: Wed, 1 Nov 2023 10:05:20 +0100 Subject: [PATCH] add helm lint extra args Signed-off-by: cpanato --- .github/workflows/ci.yaml | 2 +- ct/cmd/root.go | 5 ++++- doc/ct_install.md | 4 +++- doc/ct_lint-and-install.md | 4 +++- doc/ct_lint.md | 4 +++- pkg/chart/chart.go | 5 +++-- pkg/config/config.go | 1 + pkg/config/config_test.go | 3 ++- pkg/config/test_config.json | 3 ++- pkg/config/test_config.yaml | 3 ++- pkg/tool/helm.go | 18 ++++++++++-------- 11 files changed, 34 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2608aa27..6259efd2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -111,4 +111,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3 with: - version: v1.53 + version: v1.55 diff --git a/ct/cmd/root.go b/ct/cmd/root.go index de8223b4..c5db25fd 100644 --- a/ct/cmd/root.go +++ b/ct/cmd/root.go @@ -97,7 +97,10 @@ func addCommonLintAndInstallFlags(flags *pflag.FlagSet) { May be specified multiple times or separate values with commas`)) flags.String("helm-extra-args", "", heredoc.Doc(` Additional arguments for Helm. Must be passed as a single quoted string - (e.g. "--timeout 500s")`)) + (e.g. '--timeout 500s')`)) + flags.String("helm-lint-extra-args", "", heredoc.Doc(` + Additional arguments for Helm lint subcommand. Must be passed as a single quoted string + (e.g. '--quiet')`)) flags.StringSlice("helm-repo-extra-args", []string{}, heredoc.Doc(` Additional arguments for the 'helm repo add' command to be specified on a per-repo basis with an equals sign as delimiter diff --git a/doc/ct_install.md b/doc/ct_install.md index 79517855..8554d5eb 100644 --- a/doc/ct_install.md +++ b/doc/ct_install.md @@ -52,9 +52,11 @@ ct install [flags] for command output --helm-dependency-extra-args strings Additional arguments for 'helm dependency build' (e.g. ["--skip-refresh"] --helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string - (e.g. "--timeout 500s") + (e.g. '--timeout 500s') --helm-extra-set-args string Additional arguments for Helm. Must be passed as a single quoted string (e.g. "--set=name=value" + --helm-lint-extra-args string Additional arguments for Helm lint subcommand. Must be passed as a single quoted string + (e.g. '--quiet') --helm-repo-extra-args strings Additional arguments for the 'helm repo add' command to be specified on a per-repo basis with an equals sign as delimiter (e.g. 'myrepo=--username test --password secret'). May be specified diff --git a/doc/ct_lint-and-install.md b/doc/ct_lint-and-install.md index 73d13fe0..ea74b539 100644 --- a/doc/ct_lint-and-install.md +++ b/doc/ct_lint-and-install.md @@ -44,9 +44,11 @@ ct lint-and-install [flags] for command output --helm-dependency-extra-args strings Additional arguments for 'helm dependency build' (e.g. ["--skip-refresh"] --helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string - (e.g. "--timeout 500s") + (e.g. '--timeout 500s') --helm-extra-set-args string Additional arguments for Helm. Must be passed as a single quoted string (e.g. "--set=name=value" + --helm-lint-extra-args string Additional arguments for Helm lint subcommand. Must be passed as a single quoted string + (e.g. '--quiet') --helm-repo-extra-args strings Additional arguments for the 'helm repo add' command to be specified on a per-repo basis with an equals sign as delimiter (e.g. 'myrepo=--username test --password secret'). May be specified diff --git a/doc/ct_lint.md b/doc/ct_lint.md index f35ee02a..43135855 100644 --- a/doc/ct_lint.md +++ b/doc/ct_lint.md @@ -54,7 +54,9 @@ ct lint [flags] for command output --helm-dependency-extra-args strings Additional arguments for 'helm dependency build' (e.g. ["--skip-refresh"] --helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string - (e.g. "--timeout 500s") + (e.g. '--timeout 500s') + --helm-lint-extra-args string Additional arguments for Helm lint subcommand. Must be passed as a single quoted string + (e.g. '--quiet') --helm-repo-extra-args strings Additional arguments for the 'helm repo add' command to be specified on a per-repo basis with an equals sign as delimiter (e.g. 'myrepo=--username test --password secret'). May be specified diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index 5f2907bf..0f1e1f92 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -259,11 +259,12 @@ type TestResult struct { // NewTesting creates a new Testing struct with the given config. func NewTesting(config config.Configuration, extraSetArgs string) (Testing, error) { procExec := exec.NewProcessExecutor(config.Debug) - extraArgs := strings.Fields(config.HelmExtraArgs) + helmExtraArgs := strings.Fields(config.HelmExtraArgs) + helmLintExtraArgs := strings.Fields(config.HelmLintExtraArgs) testing := Testing{ config: config, - helm: tool.NewHelm(procExec, extraArgs, strings.Fields(extraSetArgs)), + helm: tool.NewHelm(procExec, helmExtraArgs, helmLintExtraArgs, strings.Fields(extraSetArgs)), git: tool.NewGit(procExec), kubectl: tool.NewKubectl(procExec, config.KubectlTimeout), linter: tool.NewLinter(procExec), diff --git a/pkg/config/config.go b/pkg/config/config.go index 114e2596..c6b82874 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -60,6 +60,7 @@ type Configuration struct { ChartDirs []string `mapstructure:"chart-dirs"` ExcludedCharts []string `mapstructure:"excluded-charts"` HelmExtraArgs string `mapstructure:"helm-extra-args"` + HelmLintExtraArgs string `mapstructure:"helm-lint-extra-args"` HelmRepoExtraArgs []string `mapstructure:"helm-repo-extra-args"` HelmDependencyExtraArgs []string `mapstructure:"helm-dependency-extra-args"` Debug bool `mapstructure:"debug"` diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index bc641315..80b33f0e 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -52,7 +52,8 @@ func loadAndAssertConfigFromFile(t *testing.T, configFile string) { require.Equal(t, []string{"incubator=--username test"}, cfg.HelmRepoExtraArgs) require.Equal(t, []string{"stable", "incubator"}, cfg.ChartDirs) require.Equal(t, []string{"common"}, cfg.ExcludedCharts) - require.Equal(t, "--timeout 300", cfg.HelmExtraArgs) + require.Equal(t, "--timeout 300s", cfg.HelmExtraArgs) + require.Equal(t, "--quiet", cfg.HelmLintExtraArgs) require.Equal(t, true, cfg.Upgrade) require.Equal(t, true, cfg.SkipMissingValues) require.Equal(t, "default", cfg.Namespace) diff --git a/pkg/config/test_config.json b/pkg/config/test_config.json index df0b1009..4dc445a8 100644 --- a/pkg/config/test_config.json +++ b/pkg/config/test_config.json @@ -24,7 +24,8 @@ "excluded-charts": [ "common" ], - "helm-extra-args": "--timeout 300", + "helm-extra-args": "--timeout 300s", + "helm-lint-extra-args": "--quiet", "upgrade": true, "skip-missing-values": true, "namespace": "default", diff --git a/pkg/config/test_config.yaml b/pkg/config/test_config.yaml index 1381b96b..6fe391de 100644 --- a/pkg/config/test_config.yaml +++ b/pkg/config/test_config.yaml @@ -19,7 +19,8 @@ chart-dirs: - incubator excluded-charts: - common -helm-extra-args: --timeout 300 +helm-extra-args: --timeout 300s +helm-lint-extra-args: --quiet upgrade: true skip-missing-values: true namespace: default diff --git a/pkg/tool/helm.go b/pkg/tool/helm.go index 2f22986d..42724b04 100644 --- a/pkg/tool/helm.go +++ b/pkg/tool/helm.go @@ -22,16 +22,18 @@ import ( ) type Helm struct { - exec exec.ProcessExecutor - extraArgs []string - extraSetArgs []string + exec exec.ProcessExecutor + extraArgs []string + lintExtraArgs []string + extraSetArgs []string } -func NewHelm(exec exec.ProcessExecutor, extraArgs []string, extraSetArgs []string) Helm { +func NewHelm(exec exec.ProcessExecutor, extraArgs, lintExtraArgs, extraSetArgs []string) Helm { return Helm{ - exec: exec, - extraArgs: extraArgs, - extraSetArgs: extraSetArgs, + exec: exec, + extraArgs: extraArgs, + lintExtraArgs: lintExtraArgs, + extraSetArgs: extraSetArgs, } } @@ -60,7 +62,7 @@ func (h Helm) LintWithValues(chart string, valuesFile string) error { values = []string{"--values", valuesFile} } - return h.exec.RunProcess("helm", "lint", chart, values, h.extraArgs) + return h.exec.RunProcess("helm", "lint", chart, values, h.lintExtraArgs) } func (h Helm) InstallWithValues(chart string, valuesFile string, namespace string, release string) error {