Skip to content

Commit

Permalink
fix: do not fail on empty lists
Browse files Browse the repository at this point in the history
Fixes #246
  • Loading branch information
carlossg committed Mar 30, 2021
1 parent 0bd1898 commit 026c0d6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions fixtures/list_empty_valid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
apiVersion: v1
kind: List
items: []
2 changes: 1 addition & 1 deletion kubeval/kubeval.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func ValidateWithCache(input []byte, schemaCache map[string]*gojsonschema.Schema
}{}

unmarshalErr := yaml.Unmarshal(input, &list)
isYamlList := unmarshalErr == nil && list.Items != nil && len(list.Items) > 0
isYamlList := unmarshalErr == nil && list.Items != nil

var bits [][]byte
if isYamlList {
Expand Down
1 change: 1 addition & 0 deletions kubeval/kubeval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestValidateValidInputs(t *testing.T) {
"full_domain_group.yaml",
"unconventional_keys.yaml",
"list_valid.yaml",
"list_empty_valid.yaml",
"same-object-different-namespace.yaml",
"same-object-different-namespace-default.yaml",
"duplicates-skipped-kinds.yaml",
Expand Down

0 comments on commit 026c0d6

Please # to comment.