mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-23 11:47:01 +00:00
Update Readme, converter helper script can now reads straight from http
This commit is contained in:
parent
5ada0b67e5
commit
07883b8bb4
2 changed files with 16 additions and 1 deletions
10
Readme.md
10
Readme.md
|
|
@ -118,6 +118,16 @@ in a local folder - for example schemas. Then we specify this folder as an addit
|
||||||
$ ./bin/kubeconform -registry kubernetesjsonschema.dev -registry 'schemas/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/custom-resource.yaml
|
$ ./bin/kubeconform -registry kubernetesjsonschema.dev -registry 'schemas/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/custom-resource.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Generating a JSON schema from an OpenAPI file
|
||||||
|
|
||||||
|
Kubeconform uses JSON schemas to validate Kubernetes resources. For Custom Resource, the CustomResourceDefinition
|
||||||
|
first needs to be converted to JSON Schema. A script is provided to convert these CustomResourceDefinitions
|
||||||
|
to JSON schema. Here is an example how to use it:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ ./cmd/openapi2jsonschema/main.py https://raw.githubusercontent.com/aws/amazon-sagemaker-operator-for-k8s/master/config/crd/bases/sagemaker.aws.amazon.com_trainingjobs.yaml > fixtures/registry/trainingjob-sagemaker-v1.json
|
||||||
|
```
|
||||||
|
|
||||||
### Credits
|
### Credits
|
||||||
|
|
||||||
* @garethr for the [Kubeval](https://github.com/instrumenta/kubeval) and
|
* @garethr for the [Kubeval](https://github.com/instrumenta/kubeval) and
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
import yaml
|
import yaml
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
def iteritems(d):
|
def iteritems(d):
|
||||||
if hasattr(dict, "iteritems"):
|
if hasattr(dict, "iteritems"):
|
||||||
|
|
@ -90,7 +91,11 @@ if len(sys.argv) == 0:
|
||||||
print("missing file")
|
print("missing file")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
with open(sys.argv[1]) as f:
|
if sys.argv[1].startswith("http"):
|
||||||
|
f = urllib.request.urlopen(sys.argv[1])
|
||||||
|
else:
|
||||||
|
f = open(sys.argv[1])
|
||||||
|
with f:
|
||||||
y = yaml.load(f, Loader=yaml.SafeLoader)
|
y = yaml.load(f, Loader=yaml.SafeLoader)
|
||||||
schema = y["spec"]["validation"]["openAPIV3Schema"]
|
schema = y["spec"]["validation"]["openAPIV3Schema"]
|
||||||
schema = additional_properties(schema)
|
schema = additional_properties(schema)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue