From 39a6e97e77763bb091d23ff22d77a3660f27fc6c Mon Sep 17 00:00:00 2001 From: cpanato Date: Wed, 19 Dec 2018 18:20:28 +0100 Subject: [PATCH] update per feedback Signed-off-by: cpanato --- app/cmd/lint.go | 8 ++-- doc/ct.md | 2 +- doc/ct_install.md | 2 +- doc/ct_lint-and-install.md | 76 ++++++++++++++++++------------------- doc/ct_lint.md | 58 ++++++++++++++-------------- doc/ct_version.md | 2 +- pkg/chart/chart.go | 4 +- pkg/chart/chart_test.go | 36 ++++++++---------- pkg/config/config.go | 36 +++++++++--------- pkg/config/config_test.go | 4 +- pkg/config/test_config.json | 4 +- pkg/config/test_config.yaml | 4 +- 12 files changed, 117 insertions(+), 119 deletions(-) diff --git a/app/cmd/lint.go b/app/cmd/lint.go index 6675e39d..d7fe5117 100644 --- a/app/cmd/lint.go +++ b/app/cmd/lint.go @@ -68,8 +68,10 @@ func addLintFlags(flags *flag.FlagSet) { Enabled validation of maintainer account names in chart.yml (default: true). Works for GitHub, GitLab, and Bitbucket`)) flags.Bool("check-version-increment", true, "Activates a check for chart version increments (default: true)") - flags.Bool("no-chart-schema-validation", false, "Disable schema validation (default: false)") - flags.Bool("no-yaml-lint", false, "Disable lint validation (default: false)") + flags.Bool("validate-schema", true, heredoc.Doc(` + Enabled validation of the schema (default: true)`)) + flags.Bool("validate-yaml-lint", true, heredoc.Doc(` + Enabled validation to lint the yaml files (default: true)`)) } func lint(cmd *cobra.Command, args []string) { @@ -97,6 +99,6 @@ func lint(cmd *cobra.Command, args []string) { } func bindLintFlags(flagSet *flag.FlagSet, v *viper.Viper) error { - options := []string{"lint-conf", "chart-yaml-schema", "validate-maintainers", "check-version-increment", "no-chart-schema-validation", "no-yaml-lint"} + options := []string{"lint-conf", "chart-yaml-schema", "validate-maintainers", "check-version-increment", "validate-schema", "validate-yaml-lint"} return bindFlags(options, flagSet, v) } diff --git a/doc/ct.md b/doc/ct.md index 4de1db1f..9ba72c6e 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 17-Nov-2018 +###### Auto generated by spf13/cobra on 19-Dec-2018 diff --git a/doc/ct_install.md b/doc/ct_install.md index 36557115..f2652861 100644 --- a/doc/ct_install.md +++ b/doc/ct_install.md @@ -57,4 +57,4 @@ ct install [flags] * [ct](ct.md) - The Helm chart testing tool -###### Auto generated by spf13/cobra on 17-Nov-2018 +###### Auto generated by spf13/cobra on 19-Dec-2018 diff --git a/doc/ct_lint-and-install.md b/doc/ct_lint-and-install.md index 5a27473b..6d1b41ee 100644 --- a/doc/ct_lint-and-install.md +++ b/doc/ct_lint-and-install.md @@ -13,47 +13,47 @@ 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-maintainers Enabled validation of maintainer account names in chart.yml (default: true). - Works for GitHub, GitLab, and Bitbucket (default true) - --no-chart-schema-validation Disable schema validation (default: false). - --no-yaml-lint Disable lint validation (default: false). + --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-maintainers Enabled validation of maintainer account names in chart.yml (default: true). + Works for GitHub, GitLab, and Bitbucket (default true) + --validate-schema Enabled validation of the schema (default: true) (default true) + --validate-yaml-lint Enabled validation to lint the yaml files (default: true) (default true) ``` ### SEE ALSO * [ct](ct.md) - The Helm chart testing tool -###### Auto generated by spf13/cobra on 17-Nov-2018 +###### Auto generated by spf13/cobra on 19-Dec-2018 diff --git a/doc/ct_lint.md b/doc/ct_lint.md index 683d6ec4..22a57bb2 100644 --- a/doc/ct_lint.md +++ b/doc/ct_lint.md @@ -26,38 +26,38 @@ 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-maintainers Enabled validation of maintainer account names in chart.yml (default: true). - Works for GitHub, GitLab, and Bitbucket (default: true) - --no-chart-schema-validation Disable schema validation (default: false). - --no-yaml-lint Disable lint validation (default: false). + --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-maintainers Enabled validation of maintainer account names in chart.yml (default: true). + Works for GitHub, GitLab, and Bitbucket (default true) + --validate-schema Enabled validation of the schema (default: true) (default true) + --validate-yaml-lint Enabled validation to lint the yaml files (default: true) (default true) ``` ### SEE ALSO * [ct](ct.md) - The Helm chart testing tool -###### Auto generated by spf13/cobra on 17-Nov-2018 +###### Auto generated by spf13/cobra on 19-Dec-2018 diff --git a/doc/ct_version.md b/doc/ct_version.md index a8c6f68e..e8a2f1b5 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 17-Nov-2018 +###### Auto generated by spf13/cobra on 19-Dec-2018 diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index e767827b..590e8885 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -280,14 +280,14 @@ func (t *Testing) LintChart(chart string, valuesFiles []string) TestResult { chartYaml := path.Join(chart, "Chart.yaml") valuesYaml := path.Join(chart, "values.yaml") - if !t.config.NoChartSchemaValidation { + if t.config.ValidateSchema { if err := t.linter.Yamale(chartYaml, t.config.ChartYamlSchema); err != nil { result.Error = err return result } } - if !t.config.NoYamlLint { + if t.config.ValidateYamlLint { yamlFiles := append([]string{chartYaml, valuesYaml}, valuesFiles...) for _, yamlFile := range yamlFiles { if err := t.linter.YamlLint(yamlFile, t.config.LintConf); err != nil { diff --git a/pkg/chart/chart_test.go b/pkg/chart/chart_test.go index 1b25a8d2..91fc7692 100644 --- a/pkg/chart/chart_test.go +++ b/pkg/chart/chart_test.go @@ -222,22 +222,22 @@ func TestLintNoChartSchemaValidation(t *testing.T) { expected bool } - runTests := func(noValidation bool, callsYamlLint, callsYamale int) { + runTests := func(validate bool, callsYamlLint, callsYamale int) { var fakeMockLinter = new(fakeLinter2) fakeMockLinter.On("Yamale", mock.Anything, mock.Anything).Return(true) fakeMockLinter.On("YamlLint", mock.Anything, mock.Anything).Return(true) ct.linter = fakeMockLinter - ct.config.NoChartSchemaValidation = noValidation + ct.config.ValidateSchema = validate ct.config.ValidateMaintainers = false - ct.config.NoYamlLint = false + ct.config.ValidateYamlLint = false var suffix string - if noValidation { - suffix = "without-validation" - } else { + if validate { suffix = "with-validation" + } else { + suffix = "without-validation" } testCases := []testData{ @@ -254,10 +254,8 @@ func TestLintNoChartSchemaValidation(t *testing.T) { } } - // will run the schema validation - runTests(false, 2, 1) - // will not run the schema validation - runTests(true, 2, 0) + runTests(true, 0, 1) + runTests(false, 0, 0) } @@ -268,7 +266,7 @@ func TestLintNoYamlLintValidation(t *testing.T) { expected bool } - runTests := func(noValidation bool, callsYamlLint, callsYamale int) { + runTests := func(validate bool, callsYamlLint, callsYamale int) { var fakeMockLinter = new(fakeLinter2) @@ -276,15 +274,15 @@ func TestLintNoYamlLintValidation(t *testing.T) { fakeMockLinter.On("YamlLint", mock.Anything, mock.Anything).Return(true) ct.linter = fakeMockLinter - ct.config.NoYamlLint = noValidation - ct.config.NoChartSchemaValidation = false + ct.config.ValidateYamlLint = validate + ct.config.ValidateSchema = false ct.config.ValidateMaintainers = false var suffix string - if noValidation { - suffix = "without-yaml-validation" + if validate { + suffix = "with-validation" } else { - suffix = "with-yaml-validation" + suffix = "without-validation" } testCases := []testData{ @@ -301,8 +299,6 @@ func TestLintNoYamlLintValidation(t *testing.T) { } } - // will run the lint validation - runTests(false, 2, 1) - // will not run the lint validation - runTests(true, 0, 1) + runTests(true, 2, 0) + runTests(false, 0, 0) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 7a2f0f77..9f342a5a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -39,24 +39,24 @@ var ( ) type Configuration struct { - Remote string `mapstructure:"remote"` - TargetBranch string `mapstructure:"target-branch"` - BuildId string `mapstructure:"build-id"` - LintConf string `mapstructure:"lint-conf"` - ChartYamlSchema string `mapstructure:"chart-yaml-schema"` - ValidateMaintainers bool `mapstructure:"validate-maintainers"` - 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"` - Debug bool `mapstructure:"debug"` - Namespace string `mapstructure:"namespace"` - ReleaseLabel string `mapstructure:"release-label"` - NoChartSchemaValidation bool `mapstructure:"no-chart-schema-validation"` - NoYamlLint bool `mapstructure:"no-yaml-lint"` + Remote string `mapstructure:"remote"` + TargetBranch string `mapstructure:"target-branch"` + BuildId string `mapstructure:"build-id"` + LintConf string `mapstructure:"lint-conf"` + ChartYamlSchema string `mapstructure:"chart-yaml-schema"` + ValidateMaintainers bool `mapstructure:"validate-maintainers"` + ValidateSchema bool `mapstructure:"validate-schema"` + ValidateYamlLint bool `mapstructure:"validate-yaml-lint"` + 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"` + Debug bool `mapstructure:"debug"` + Namespace string `mapstructure:"namespace"` + ReleaseLabel string `mapstructure:"release-label"` } func LoadConfiguration(cfgFile string, cmd *cobra.Command, bindFlagsFunc ...func(flagSet *flag.FlagSet, viper *viper.Viper) error) (*Configuration, error) { diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index eff74a5a..830396f5 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -38,8 +38,8 @@ func loadAndAssertConfigFromFile(t *testing.T, configFile string) { require.Equal(t, "my-lint-conf.yaml", cfg.LintConf) require.Equal(t, "my-chart-yaml-schema.yaml", cfg.ChartYamlSchema) require.Equal(t, true, cfg.ValidateMaintainers) - require.Equal(t, false, cfg.NoChartSchemaValidation) - require.Equal(t, false, cfg.NoYamlLint) + require.Equal(t, true, cfg.ValidateSchema) + require.Equal(t, true, cfg.ValidateYamlLint) require.Equal(t, true, cfg.CheckVersionIncrement) require.Equal(t, false, cfg.ProcessAllCharts) require.Equal(t, []string{"incubator=https://incubator"}, cfg.ChartRepos) diff --git a/pkg/config/test_config.json b/pkg/config/test_config.json index a5a37e84..e1ff5472 100644 --- a/pkg/config/test_config.json +++ b/pkg/config/test_config.json @@ -6,8 +6,8 @@ "chart-yaml-schema": "my-chart-yaml-schema.yaml", "github-instance": "https://github.com", "validate-maintainers": true, - "no-chart-schema-validation": false, - "no-yaml-lint": false, + "validate-schema": true, + "validate-yaml-lint": true, "check-version-increment": true, "all": false, "chart-repos": [ diff --git a/pkg/config/test_config.yaml b/pkg/config/test_config.yaml index dea02d97..a197cafe 100644 --- a/pkg/config/test_config.yaml +++ b/pkg/config/test_config.yaml @@ -5,8 +5,8 @@ lint-conf: my-lint-conf.yaml chart-yaml-schema: my-chart-yaml-schema.yaml github-instance: https://github.com validate-maintainers: true -no-chart-schema-validation: false -no-yaml-lint: false +validate-schema: true +validate-yaml-lint: true check-version-increment: true all: false chart-repos: