Compare commits

...

2 commits

Author SHA1 Message Date
Yann Hamon
a2ad239853 Add test validating using CRD that misses explicit draft version 2023-07-16 09:39:52 +02:00
Yann Hamon
51065ea828 Force Draft version of JsonSchema 2023-07-16 09:32:36 +02:00
3 changed files with 25 additions and 1 deletions

View file

@ -340,3 +340,8 @@ resetCacheFolder() {
run xmllint --noout --schema fixtures/junit.xsd output.xml run xmllint --noout --schema fixtures/junit.xsd output.xml
[ "$status" -eq 0 ] [ "$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 ]
}

13
fixtures/httpproxy.yaml Normal file
View file

@ -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

View file

@ -6,6 +6,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"strings"
jsonschema "github.com/santhosh-tekuri/jsonschema/v5" jsonschema "github.com/santhosh-tekuri/jsonschema/v5"
_ "github.com/santhosh-tekuri/jsonschema/v5/httploader" _ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
@ -254,7 +255,12 @@ func downloadSchema(registries []registry.Registry, kind, version, k8sVersion st
for _, reg := range registries { for _, reg := range registries {
path, schemaBytes, err = reg.DownloadSchema(kind, version, k8sVersion) path, schemaBytes, err = reg.DownloadSchema(kind, version, k8sVersion)
if err == nil { 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 we got a non-parseable response, we try the next registry
if err != nil { if err != nil {
continue continue