Skip to content

Commit

Permalink
update per feedback
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <[email protected]>
  • Loading branch information
cpanato committed Dec 19, 2018
1 parent b1b0917 commit fb23880
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 118 deletions.
6 changes: 4 additions & 2 deletions app/cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion doc/ct.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion doc/ct_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
76 changes: 38 additions & 38 deletions doc/ct_lint-and-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
58 changes: 29 additions & 29 deletions doc/ct_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion doc/ct_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions pkg/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 16 additions & 20 deletions pkg/chart/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)

}

Expand All @@ -268,23 +266,23 @@ 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)

fakeMockLinter.On("Yamale", mock.Anything, mock.Anything).Return(true)
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{
Expand All @@ -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)
}
36 changes: 18 additions & 18 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit fb23880

Please sign in to comment.