Skip to content

Commit

Permalink
Merge pull request #171 from brendanjryan/bjr-single-warning
Browse files Browse the repository at this point in the history
Only logs missing schema warning once
  • Loading branch information
garethr committed Aug 13, 2019
2 parents a766f3c + 8cbf08a commit ecd0802
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 8 additions & 0 deletions acceptance.bats
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,11 @@
run bin/kubeval fixtures/invalid.yaml --openshift
[ "$status" -eq 1 ]
}

@test "Only prints a single warning when --ignore-missing-schemas is supplied" {
run bin/kubeval --ignore-missing-schemas fixtures/valid.yaml fixtures/valid.yaml
[ "$status" -eq 0 ]
[[ "${lines[0]}" == *"Warning: Set to ignore missing schemas"* ]]
[[ "${lines[1]}" == *"The file fixtures/valid.yaml contains a valid ReplicationController"* ]]
[[ "${lines[2]}" == *"The file fixtures/valid.yaml contains a valid ReplicationController"* ]]
}
5 changes: 0 additions & 5 deletions kubeval/kubeval.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/xeipuuv/gojsonschema"
"sigs.k8s.io/yaml"

"github.com/instrumenta/kubeval/log"
)

// ValidFormat is a type for quickly forcing
Expand Down Expand Up @@ -135,9 +133,6 @@ func validateResource(data []byte, schemaCache map[string]*gojsonschema.Schema,
}

func validateAgainstSchema(body interface{}, resource *ValidationResult, schemaCache map[string]*gojsonschema.Schema, config *Config) ([]gojsonschema.ResultError, error) {
if config.IgnoreMissingSchemas {
log.Warn("Warning: Set to ignore missing schemas")
}

schema, err := downloadSchema(resource, schemaCache, config)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ var RootCmd = &cobra.Command{
Long: `Validate a Kubernetes YAML file against the relevant schema`,
Version: fmt.Sprintf("Version: %s\nCommit: %s\nDate: %s\n", version, commit, date),
Run: func(cmd *cobra.Command, args []string) {
if config.IgnoreMissingSchemas {
log.Warn("Warning: Set to ignore missing schemas")
}
success := true
windowsStdinIssue := false
outputManager := kubeval.GetOutputManager(config.OutputFormat)
Expand Down

0 comments on commit ecd0802

Please sign in to comment.