Skip to content

Commit a742f83

Browse files
author
Brendan Ryan
committed
only logs missing schema warning once
1 parent 4e5d0f6 commit a742f83

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

acceptance.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,11 @@
155155
run bin/kubeval fixtures/invalid.yaml --openshift
156156
[ "$status" -eq 1 ]
157157
}
158+
159+
@test "Only prints a single warning when --ignore-missing-schemas is supplied" {
160+
run bin/kubeval --ignore-missing-schemas fixtures/valid.yaml fixtures/valid.yaml
161+
[ "$status" -eq 0 ]
162+
[[ "${lines[0]}" == *"Warning: Set to ignore missing schemas"* ]]
163+
[[ "${lines[1]}" == *"The file fixtures/valid.yaml contains a valid ReplicationController"* ]]
164+
[[ "${lines[2]}" == *"The file fixtures/valid.yaml contains a valid ReplicationController"* ]]
165+
}

kubeval/kubeval.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"github.com/hashicorp/go-multierror"
1111
"github.com/xeipuuv/gojsonschema"
1212
"sigs.k8s.io/yaml"
13-
14-
"github.com/instrumenta/kubeval/log"
1513
)
1614

1715
// ValidFormat is a type for quickly forcing
@@ -130,9 +128,6 @@ func validateResource(data []byte, schemaCache map[string]*gojsonschema.Schema,
130128
}
131129

132130
func validateAgainstSchema(body interface{}, resource *ValidationResult, schemaCache map[string]*gojsonschema.Schema, config *Config) ([]gojsonschema.ResultError, error) {
133-
if config.IgnoreMissingSchemas {
134-
log.Warn("Warning: Set to ignore missing schemas")
135-
}
136131
schemaRef := determineSchema(resource.Kind, resource.APIVersion, config)
137132
schema, ok := schemaCache[schemaRef]
138133
if !ok {

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ var RootCmd = &cobra.Command{
3939
Long: `Validate a Kubernetes YAML file against the relevant schema`,
4040
Version: fmt.Sprintf("Version: %s\nCommit: %s\nDate: %s\n", version, commit, date),
4141
Run: func(cmd *cobra.Command, args []string) {
42+
if config.IgnoreMissingSchemas {
43+
log.Warn("Warning: Set to ignore missing schemas")
44+
}
4245
success := true
4346
windowsStdinIssue := false
4447
stat, err := os.Stdin.Stat()

0 commit comments

Comments
 (0)