specify CRD work is in progress

This commit is contained in:
Yann Hamon 2020-06-07 15:58:39 +02:00
parent a9ad8b4290
commit 58363ddcfd
2 changed files with 8 additions and 22 deletions

View file

@ -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 It is inspired by and similar to [Kubeval](https://github.com/instrumenta/kubeval), but with the
following improvements: following improvements:
* **high performance**: will validate & download manifests over multiple routines * **high performance**: will validate & download manifests over multiple routines
* support for **Kubernetes CRDs** * support for **Kubernetes CRDs** (in progress)
### Usage ### 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 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 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 ### Credits

20
main.go
View file

@ -39,29 +39,23 @@ func resourcesFromReader(r io.Reader) ([][]byte, error) {
func downloadSchema(registries []registry.Registry, kind, version, k8sVersion string) (*gojsonschema.Schema, error) { func downloadSchema(registries []registry.Registry, kind, version, k8sVersion string) (*gojsonschema.Schema, error) {
var err error var err error
var schema *gojsonschema.Schema
var schemaBytes []byte var schemaBytes []byte
for _, reg := range registries { for _, reg := range registries {
schemaBytes, err = reg.DownloadSchema(kind, version, k8sVersion) schemaBytes, err = reg.DownloadSchema(kind, version, k8sVersion)
if err == nil {
if err != nil { return gojsonschema.NewSchema(gojsonschema.NewBytesLoader(schemaBytes))
// 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 schema, err = gojsonschema.NewSchema(gojsonschema.NewBytesLoader(schemaBytes)); err != nil { // If we get a 404, we try the next registry, but we exit if we get a real failure
return nil, err // Got a schema, but fail to parse it 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 // filter returns true if the file should be skipped