Skip to content

Commit

Permalink
only logs missing schema warning once
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendan Ryan committed Aug 13, 2019
1 parent 4e5d0f6 commit a742f83
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 @@ -130,9 +128,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")
}
schemaRef := determineSchema(resource.Kind, resource.APIVersion, config)
schema, ok := schemaCache[schemaRef]
if !ok {
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
stat, err := os.Stdin.Stat()
Expand Down

0 comments on commit a742f83

Please sign in to comment.