diff --git a/acceptance.bats b/acceptance.bats index 2a6d94c..ca49c6f 100755 --- a/acceptance.bats +++ b/acceptance.bats @@ -340,3 +340,8 @@ resetCacheFolder() { run xmllint --noout --schema fixtures/junit.xsd output.xml [ "$status" -eq 0 ] } + +@test "passes when trying to use a CRD that does not have the JSONSchema set" { + run bash -c "bin/kubeconform -schema-location default -schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json' fixtures/httpproxy.yaml" + [ "$status" -eq 0 ] +} diff --git a/fixtures/httpproxy.yaml b/fixtures/httpproxy.yaml new file mode 100644 index 0000000..7b0bd31 --- /dev/null +++ b/fixtures/httpproxy.yaml @@ -0,0 +1,13 @@ +apiVersion: projectcontour.io/v1 +kind: HTTPProxy +metadata: + name: basic +spec: + virtualhost: + fqdn: foo-basic.example.com + routes: + - conditions: + - prefix: / + services: + - name: s1 + port: 80 diff --git a/pkg/validator/validator.go b/pkg/validator/validator.go index f4827c8..b9f7c8d 100644 --- a/pkg/validator/validator.go +++ b/pkg/validator/validator.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "strings" jsonschema "github.com/santhosh-tekuri/jsonschema/v5" _ "github.com/santhosh-tekuri/jsonschema/v5/httploader" @@ -254,7 +255,12 @@ func downloadSchema(registries []registry.Registry, kind, version, k8sVersion st for _, reg := range registries { path, schemaBytes, err = reg.DownloadSchema(kind, version, k8sVersion) if err == nil { - schema, err := jsonschema.CompileString(path, string(schemaBytes)) + c := jsonschema.NewCompiler() + c.Draft = jsonschema.Draft4 + if err := c.AddResource(path, strings.NewReader(string(schemaBytes))); err != nil { + continue + } + schema, err := c.Compile(path) // If we got a non-parseable response, we try the next registry if err != nil { continue