diff --git a/README.md b/README.md index 6dc5f21..2d0cab1 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,23 @@ build-id: pr-42 Notice that if no config file is specified, then `ct.yaml` (or any of the supported formats) is loaded from the current directory, `$HOME/.ct`, or `/etc/ct`, in that order, if found. +#### Using private chart repositories + +When adding chart-repos you can specify additional arguments for the `helm repo add` command using `helm-repo-extra-args` on a per-repo basis. This could for example be used to authenticate a private chart repository. + +`config.yaml`: + +```yaml +chart-repos: + - incubator=https://incubator.io + - basic-auth=https://private.com + - ssl-repo=https://self-signed.ca +helm-repo-extra-args: + - ssl-repo=--ca-file ./my-ca.crt +``` + + ct install --config config.yaml --helm-repo-extra-args "basic-auth=--username user --password secret" + ## Building from Source `ct` is built using Go 1.11. Older versions may work but have not been tested. diff --git a/app/cmd/root.go b/app/cmd/root.go index 8029d5a..65ac86f 100644 --- a/app/cmd/root.go +++ b/app/cmd/root.go @@ -77,6 +77,11 @@ func addCommonLintAndInstallFlags(flags *pflag.FlagSet) { flags.StringSlice("chart-repos", []string{}, heredoc.Doc(` Additional chart repos to add so dependencies can be resolved. May be specified multiple times or separate values with commas`)) + 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 + (e.g. 'myrepo=--username test --password secret'). May be specified + multiple times or separate values with commas`)) flags.StringSlice("excluded-charts", []string{}, heredoc.Doc(` Charts that should be skipped. May be specified multiple times or separate values with commas`)) @@ -95,6 +100,6 @@ func bindFlags(options []string, flagSet *flag.FlagSet, v *viper.Viper) error { } func bindRootFlags(flagSet *flag.FlagSet, v *viper.Viper) error { - options := []string{"remote", "target-branch", "all", "charts", "chart-dirs", "chart-repos", "excluded-charts", "debug"} + options := []string{"remote", "target-branch", "all", "charts", "chart-dirs", "chart-repos", "helm-repo-extra-args", "excluded-charts", "debug"} return bindFlags(options, flagSet, v) } diff --git a/doc/ct.md b/doc/ct.md index 9ba72c6..a21dff8 100644 --- a/doc/ct.md +++ b/doc/ct.md @@ -25,4 +25,4 @@ in given chart directories. * [ct lint-and-install](ct_lint-and-install.md) - Lint, install, and test a chart * [ct version](ct_version.md) - Print version information -###### Auto generated by spf13/cobra on 19-Dec-2018 +###### Auto generated by spf13/cobra on 22-Dec-2018 diff --git a/doc/ct_install.md b/doc/ct_install.md index f265286..49e6a1d 100644 --- a/doc/ct_install.md +++ b/doc/ct_install.md @@ -25,36 +25,40 @@ ct install [flags] ### Options ``` - --all Process all charts except those explicitly excluded. - Disables changed charts detection and version increment checking - --build-id string An optional, arbitrary identifier that is added to the name of the namespace a - chart is installed into. In a CI environment, this could be the build number or - the ID of a pull request. If not specified, the name of the chart is used - --chart-dirs strings Directories containing Helm charts. May be specified multiple times - or separate values with commas (default [charts]) - --chart-repos strings Additional chart repos to add so dependencies can be resolved. May be - specified multiple times or separate values with commas - --charts strings Specific charts to test. Disables changed charts detection and - version increment checking. May be specified multiple times - or separate values with commas - --config string Config file - --debug Print CLI calls of external tools to stdout (Note: depending on helm-extra-args - passed, this may reveal sensitive data) - --excluded-charts strings Charts that should be skipped. May be specified multiple times - or separate values with commas - --helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string - (e.g. "--timeout 500 --tiller-namespace tiller" - -h, --help help for install - --namespace string Namespace to install the release(s) into. If not specified, each release will be - installed in its own randomly generated namespace. - --release-label string The label to be used as a selector when inspecting resources created by charts. - This is only used if namespace is specified. (default "app.kubernetes.io/instance") - --remote string The name of the Git remote used to identify changed charts (default "origin") - --target-branch string The name of the target branch used to identify changed charts (default "master") + --all Process all charts except those explicitly excluded. + Disables changed charts detection and version increment checking + --build-id string An optional, arbitrary identifier that is added to the name of the namespace a + chart is installed into. In a CI environment, this could be the build number or + the ID of a pull request. If not specified, the name of the chart is used + --chart-dirs strings Directories containing Helm charts. May be specified multiple times + or separate values with commas (default [charts]) + --chart-repos strings Additional chart repos to add so dependencies can be resolved. May be + specified multiple times or separate values with commas + --charts strings Specific charts to test. Disables changed charts detection and + version increment checking. May be specified multiple times + or separate values with commas + --config string Config file + --debug Print CLI calls of external tools to stdout (Note: depending on helm-extra-args + passed, this may reveal sensitive data) + --excluded-charts strings Charts that should be skipped. May be specified multiple times + or separate values with commas + --helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string + (e.g. "--timeout 500 --tiller-namespace tiller" + --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 + multiple times or separate values with commas + -h, --help help for install + --namespace string Namespace to install the release(s) into. If not specified, each release will be + installed in its own randomly generated namespace. + --release-label string The label to be used as a selector when inspecting resources created by charts. + This is only used if namespace is specified. (default "app.kubernetes.io/instance") + --remote string The name of the Git remote used to identify changed charts (default "origin") + --target-branch string The name of the target branch used to identify changed charts (default "master") ``` ### SEE ALSO * [ct](ct.md) - The Helm chart testing tool -###### Auto generated by spf13/cobra on 19-Dec-2018 +###### Auto generated by spf13/cobra on 22-Dec-2018 diff --git a/doc/ct_lint-and-install.md b/doc/ct_lint-and-install.md index ececce6..dc6d581 100644 --- a/doc/ct_lint-and-install.md +++ b/doc/ct_lint-and-install.md @@ -13,47 +13,51 @@ ct lint-and-install [flags] ### Options ``` - --all Process all charts except those explicitly excluded. - Disables changed charts detection and version increment checking - --build-id string An optional, arbitrary identifier that is added to the name of the namespace a - chart is installed into. In a CI environment, this could be the build number or - the ID of a pull request. If not specified, the name of the chart is used - --chart-dirs strings Directories containing Helm charts. May be specified multiple times - or separate values with commas (default [charts]) - --chart-repos strings Additional chart repos to add so dependencies can be resolved. May be - specified multiple times or separate values with commas - --chart-yaml-schema string The schema for chart.yml validation. If not specified, 'chart_schema.yaml' - is searched in the current directory, '$HOME/.ct', and '/etc/ct', in - that order. - --charts strings Specific charts to test. Disables changed charts detection and - version increment checking. May be specified multiple times - or separate values with commas - --check-version-increment Activates a check for chart version increments (default: true) (default true) - --config string Config file - --debug Print CLI calls of external tools to stdout (Note: depending on helm-extra-args - passed, this may reveal sensitive data) - --excluded-charts strings Charts that should be skipped. May be specified multiple times - or separate values with commas - --helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string - (e.g. "--timeout 500 --tiller-namespace tiller" - -h, --help help for lint-and-install - --lint-conf string The config file for YAML linting. If not specified, 'lintconf.yaml' - is searched in the current directory, '$HOME/.ct', and '/etc/ct', in - that order - --namespace string Namespace to install the release(s) into. If not specified, each release will be - installed in its own randomly generated namespace. - --release-label string The label to be used as a selector when inspecting resources created by charts. - This is only used if namespace is specified. (default "app.kubernetes.io/instance") - --remote string The name of the Git remote used to identify changed charts (default "origin") - --target-branch string The name of the target branch used to identify changed charts (default "master") - --validate-chart-schema Enable schema validation of 'Chart.yaml' using Yamale (default: true) (default true) - --validate-maintainers Enable validation of maintainer account names in chart.yml (default: true). - Works for GitHub, GitLab, and Bitbucket (default true) - --validate-yaml Enable linting of 'Chart.yaml' and values files (default: true) (default true) + --all Process all charts except those explicitly excluded. + Disables changed charts detection and version increment checking + --build-id string An optional, arbitrary identifier that is added to the name of the namespace a + chart is installed into. In a CI environment, this could be the build number or + the ID of a pull request. If not specified, the name of the chart is used + --chart-dirs strings Directories containing Helm charts. May be specified multiple times + or separate values with commas (default [charts]) + --chart-repos strings Additional chart repos to add so dependencies can be resolved. May be + specified multiple times or separate values with commas + --chart-yaml-schema string The schema for chart.yml validation. If not specified, 'chart_schema.yaml' + is searched in the current directory, '$HOME/.ct', and '/etc/ct', in + that order. + --charts strings Specific charts to test. Disables changed charts detection and + version increment checking. May be specified multiple times + or separate values with commas + --check-version-increment Activates a check for chart version increments (default: true) (default true) + --config string Config file + --debug Print CLI calls of external tools to stdout (Note: depending on helm-extra-args + passed, this may reveal sensitive data) + --excluded-charts strings Charts that should be skipped. May be specified multiple times + or separate values with commas + --helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string + (e.g. "--timeout 500 --tiller-namespace tiller" + --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 + multiple times or separate values with commas + -h, --help help for lint-and-install + --lint-conf string The config file for YAML linting. If not specified, 'lintconf.yaml' + is searched in the current directory, '$HOME/.ct', and '/etc/ct', in + that order + --namespace string Namespace to install the release(s) into. If not specified, each release will be + installed in its own randomly generated namespace. + --release-label string The label to be used as a selector when inspecting resources created by charts. + This is only used if namespace is specified. (default "app.kubernetes.io/instance") + --remote string The name of the Git remote used to identify changed charts (default "origin") + --target-branch string The name of the target branch used to identify changed charts (default "master") + --validate-chart-schema Enable schema validation of 'Chart.yaml' using Yamale (default: true) (default true) + --validate-maintainers Enable validation of maintainer account names in chart.yml (default: true). + Works for GitHub, GitLab, and Bitbucket (default true) + --validate-yaml Enable linting of 'Chart.yaml' and values files (default: true) (default true) ``` ### SEE ALSO * [ct](ct.md) - The Helm chart testing tool -###### Auto generated by spf13/cobra on 19-Dec-2018 +###### Auto generated by spf13/cobra on 22-Dec-2018 diff --git a/doc/ct_lint.md b/doc/ct_lint.md index 97d7153..08d46ef 100644 --- a/doc/ct_lint.md +++ b/doc/ct_lint.md @@ -26,38 +26,42 @@ ct lint [flags] ### Options ``` - --all Process all charts except those explicitly excluded. - Disables changed charts detection and version increment checking - --chart-dirs strings Directories containing Helm charts. May be specified multiple times - or separate values with commas (default [charts]) - --chart-repos strings Additional chart repos to add so dependencies can be resolved. May be - specified multiple times or separate values with commas - --chart-yaml-schema string The schema for chart.yml validation. If not specified, 'chart_schema.yaml' - is searched in the current directory, '$HOME/.ct', and '/etc/ct', in - that order. - --charts strings Specific charts to test. Disables changed charts detection and - version increment checking. May be specified multiple times - or separate values with commas - --check-version-increment Activates a check for chart version increments (default: true) (default true) - --config string Config file - --debug Print CLI calls of external tools to stdout (Note: depending on helm-extra-args - passed, this may reveal sensitive data) - --excluded-charts strings Charts that should be skipped. May be specified multiple times - or separate values with commas - -h, --help help for lint - --lint-conf string The config file for YAML linting. If not specified, 'lintconf.yaml' - is searched in the current directory, '$HOME/.ct', and '/etc/ct', in - that order - --remote string The name of the Git remote used to identify changed charts (default "origin") - --target-branch string The name of the target branch used to identify changed charts (default "master") - --validate-chart-schema Enable schema validation of 'Chart.yaml' using Yamale (default: true) (default true) - --validate-maintainers Enable validation of maintainer account names in chart.yml (default: true). - Works for GitHub, GitLab, and Bitbucket (default true) - --validate-yaml Enable linting of 'Chart.yaml' and values files (default: true) (default true) + --all Process all charts except those explicitly excluded. + Disables changed charts detection and version increment checking + --chart-dirs strings Directories containing Helm charts. May be specified multiple times + or separate values with commas (default [charts]) + --chart-repos strings Additional chart repos to add so dependencies can be resolved. May be + specified multiple times or separate values with commas + --chart-yaml-schema string The schema for chart.yml validation. If not specified, 'chart_schema.yaml' + is searched in the current directory, '$HOME/.ct', and '/etc/ct', in + that order. + --charts strings Specific charts to test. Disables changed charts detection and + version increment checking. May be specified multiple times + or separate values with commas + --check-version-increment Activates a check for chart version increments (default: true) (default true) + --config string Config file + --debug Print CLI calls of external tools to stdout (Note: depending on helm-extra-args + passed, this may reveal sensitive data) + --excluded-charts strings Charts that should be skipped. May be specified multiple times + or separate values with commas + --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 + multiple times or separate values with commas + -h, --help help for lint + --lint-conf string The config file for YAML linting. If not specified, 'lintconf.yaml' + is searched in the current directory, '$HOME/.ct', and '/etc/ct', in + that order + --remote string The name of the Git remote used to identify changed charts (default "origin") + --target-branch string The name of the target branch used to identify changed charts (default "master") + --validate-chart-schema Enable schema validation of 'Chart.yaml' using Yamale (default: true) (default true) + --validate-maintainers Enable validation of maintainer account names in chart.yml (default: true). + Works for GitHub, GitLab, and Bitbucket (default true) + --validate-yaml Enable linting of 'Chart.yaml' and values files (default: true) (default true) ``` ### SEE ALSO * [ct](ct.md) - The Helm chart testing tool -###### Auto generated by spf13/cobra on 19-Dec-2018 +###### Auto generated by spf13/cobra on 22-Dec-2018 diff --git a/doc/ct_version.md b/doc/ct_version.md index e8a2f1b..b1bcd34 100644 --- a/doc/ct_version.md +++ b/doc/ct_version.md @@ -20,4 +20,4 @@ ct version [flags] * [ct](ct.md) - The Helm chart testing tool -###### Auto generated by spf13/cobra on 19-Dec-2018 +###### Auto generated by spf13/cobra on 22-Dec-2018 diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index d8d25f2..155406c 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -64,7 +64,7 @@ type Git interface { // DeleteRelease purges the specified Helm release. type Helm interface { Init() error - AddRepo(name string, url string) error + AddRepo(name string, url string, extraArgs []string) error BuildDependencies(chart string) error LintWithValues(chart string, valuesFile string) error InstallWithValues(chart string, valuesFile string, namespace string, release string) error @@ -197,11 +197,22 @@ func (t *Testing) processCharts(action func(chart string, valuesFiles []string) return nil, errors.Wrap(err, "Error initializing Helm") } + repoArgs := map[string][]string{} + + for _, repo := range t.config.HelmRepoExtraArgs { + repoSlice := strings.SplitN(repo, "=", 2) + name := repoSlice[0] + repoExtraArgs := strings.Fields(repoSlice[1]) + repoArgs[name] = repoExtraArgs + } + for _, repo := range t.config.ChartRepos { repoSlice := strings.SplitN(repo, "=", 2) name := repoSlice[0] url := repoSlice[1] - if err := t.helm.AddRepo(name, url); err != nil { + + repoExtraArgs := repoArgs[name] + if err := t.helm.AddRepo(name, url, repoExtraArgs); err != nil { return nil, errors.Wrapf(err, "Error adding repo: %s=%s", name, url) } } diff --git a/pkg/chart/chart_test.go b/pkg/chart/chart_test.go index dafc784..333c953 100644 --- a/pkg/chart/chart_test.go +++ b/pkg/chart/chart_test.go @@ -110,7 +110,7 @@ func (l *fakeLinter) Yamale(yamlFile, schemaFile string) error { type fakeHelm struct{} func (h fakeHelm) Init() error { return nil } -func (h fakeHelm) AddRepo(name, url 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) LintWithValues(chart string, valuesFile string) error { return nil } func (h fakeHelm) InstallWithValues(chart string, valuesFile string, namespace string, release string) error { diff --git a/pkg/config/config.go b/pkg/config/config.go index 01506c5..9229739 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -54,6 +54,7 @@ type Configuration struct { 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"` Namespace string `mapstructure:"namespace"` ReleaseLabel string `mapstructure:"release-label"` diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 77d1ee8..fd813b7 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -43,6 +43,7 @@ func loadAndAssertConfigFromFile(t *testing.T, configFile string) { require.Equal(t, true, cfg.CheckVersionIncrement) require.Equal(t, false, cfg.ProcessAllCharts) require.Equal(t, []string{"incubator=https://incubator"}, cfg.ChartRepos) + 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) diff --git a/pkg/config/test_config.json b/pkg/config/test_config.json index fb685ed..ded1516 100644 --- a/pkg/config/test_config.json +++ b/pkg/config/test_config.json @@ -13,6 +13,9 @@ "chart-repos": [ "incubator=https://incubator" ], + "helm-repo-extra-args": [ + "incubator=--username test" + ], "chart-dirs": [ "stable", "incubator" diff --git a/pkg/config/test_config.yaml b/pkg/config/test_config.yaml index 5e51c53..00c298c 100644 --- a/pkg/config/test_config.yaml +++ b/pkg/config/test_config.yaml @@ -11,6 +11,8 @@ check-version-increment: true all: false chart-repos: - incubator=https://incubator +helm-repo-extra-args: + - incubator=--username test chart-dirs: - stable - incubator diff --git a/pkg/tool/helm.go b/pkg/tool/helm.go index 9b15537..970a7b8 100644 --- a/pkg/tool/helm.go +++ b/pkg/tool/helm.go @@ -36,8 +36,8 @@ func (h Helm) Init() error { return h.exec.RunProcess("helm", "init", "--client-only") } -func (h Helm) AddRepo(name string, url string) error { - return h.exec.RunProcess("helm", "repo", "add", name, url) +func (h Helm) AddRepo(name string, url string, extraArgs []string) error { + return h.exec.RunProcess("helm", "repo", "add", name, url, extraArgs) } func (h Helm) BuildDependencies(chart string) error {