diff --git a/Readme.md b/Readme.md index 8e59f87..5f4ee14 100644 --- a/Readme.md +++ b/Readme.md @@ -10,7 +10,7 @@ configuration using the schemas from the registry maintained by the It is inspired by and similar to [Kubeval](https://github.com/instrumenta/kubeval), but with the following improvements: * **high performance**: will validate & download manifests over multiple routines - * support for **Kubernetes CRDs** + * support for **Kubernetes CRDs** (in progress) ### Usage @@ -79,14 +79,6 @@ fixtures/multi_invalid.yaml - Service is invalid: Invalid type. Expected: intege fixtures/invalid.yaml - ReplicationController is invalid: Invalid type. Expected: [integer,null], given: string [...] Summary: 48 resources found in 25 files - Valid: 39, Invalid: 2, Errors: 7 Skipped: 0 - -``` - -* Validating a custom resources, using a local schema - -``` -$ bin/kubeconform -schema fixtures/crd_schema.yaml -verbose fixtures/test_crd.yaml -fixtures/test_crd.yaml - TrainingJob is valid ``` ### Credits diff --git a/main.go b/main.go index eb7a65f..7559457 100644 --- a/main.go +++ b/main.go @@ -39,29 +39,23 @@ func resourcesFromReader(r io.Reader) ([][]byte, error) { func downloadSchema(registries []registry.Registry, kind, version, k8sVersion string) (*gojsonschema.Schema, error) { var err error - var schema *gojsonschema.Schema var schemaBytes []byte for _, reg := range registries { schemaBytes, err = reg.DownloadSchema(kind, version, k8sVersion) - - if err != nil { - // If we get a 404, we keep trying, but we exit if we get a real failure - if er, retryable := err.(registry.Retryable); !retryable || er.IsRetryable() { - return nil, err - } - - continue // 404 from this registry, try next registry + if err == nil { + return gojsonschema.NewSchema(gojsonschema.NewBytesLoader(schemaBytes)) } - if schema, err = gojsonschema.NewSchema(gojsonschema.NewBytesLoader(schemaBytes)); err != nil { - return nil, err // Got a schema, but fail to parse it + // If we get a 404, we try the next registry, but we exit if we get a real failure + if er, retryable := err.(registry.Retryable); retryable && !er.IsRetryable() { + continue } - return schema, nil + return nil, err } - return nil, nil // No schema found - we don't consider it an error, resource willb e skipped + return nil, nil // No schema found - we don't consider it an error, resource will be skipped } // filter returns true if the file should be skipped