diff --git a/fixtures/unconventional_keys.yaml b/fixtures/unconventional_keys.yaml new file mode 100644 index 0000000..aa37f8c --- /dev/null +++ b/fixtures/unconventional_keys.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: unconventional-keys +data: + 5: "integer" + 3.14: "float" + true: "boolean" diff --git a/kubeval/kubeval_test.go b/kubeval/kubeval_test.go index 100ebae..50538cc 100644 --- a/kubeval/kubeval_test.go +++ b/kubeval/kubeval_test.go @@ -28,6 +28,7 @@ func TestValidateValidInputs(t *testing.T) { "quantity.yaml", "extra_property.yaml", "full_domain_group.yaml", + "unconventional_keys.yaml", } for _, test := range tests { filePath, _ := filepath.Abs("../fixtures/" + test) @@ -51,6 +52,7 @@ func TestValidateValidInputsWithCache(t *testing.T) { "quantity.yaml", "extra_property.yaml", "full_domain_group.yaml", + "unconventional_keys.yaml", } schemaCache := make(map[string]*gojsonschema.Schema, 0) @@ -89,7 +91,6 @@ func TestStrictCatchesAdditionalErrors(t *testing.T) { } } - func TestValidateMultipleVersions(t *testing.T) { Strict = true Version = "1.14.0" @@ -171,4 +172,3 @@ func TestSkipCrdSchemaMiss(t *testing.T) { t.Errorf("For custom CRD's with schema missing we should skip with SkipCrdSchemaMiss flag") } } - diff --git a/kubeval/utils.go b/kubeval/utils.go index 9be29c6..89e89e8 100644 --- a/kubeval/utils.go +++ b/kubeval/utils.go @@ -1,5 +1,7 @@ package kubeval +import "fmt" + // Based on https://stackoverflow.com/questions/40737122/convert-yaml-to-json-without-struct-golang // We unmarshal yaml into a value of type interface{}, // go through the result recursively, and convert each encountered @@ -10,7 +12,7 @@ func convertToStringKeys(i interface{}) interface{} { case map[interface{}]interface{}: m2 := map[string]interface{}{} for k, v := range x { - m2[k.(string)] = convertToStringKeys(v) + m2[fmt.Sprintf("%v", k)] = convertToStringKeys(v) } return m2 case []interface{}: