mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-20 10:27:02 +00:00
Merge branch 'master' of github.com:yannh/kubeconform
This commit is contained in:
commit
c664451a9d
2 changed files with 30 additions and 16 deletions
|
|
@ -183,6 +183,8 @@ $ ./scripts/openapi2jsonschema.py https://raw.githubusercontent.com/aws/amazon-s
|
||||||
JSON schema written to trainingjob_v1.json
|
JSON schema written to trainingjob_v1.json
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The `FILENAME_FORMAT` environment variable can be used to change the output file name (Available variables: `kind`, `group`, `version`) (Default: `{kind}_{version}`).
|
||||||
|
|
||||||
### Speed comparison with Kubeval
|
### Speed comparison with Kubeval
|
||||||
|
|
||||||
Running on a pretty large kubeconfigs setup, on a laptop with 4 cores:
|
Running on a pretty large kubeconfigs setup, on a laptop with 4 cores:
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,21 @@ def append_no_duplicates(obj, key, value):
|
||||||
obj[key].append(value)
|
obj[key].append(value)
|
||||||
|
|
||||||
|
|
||||||
|
def write_schema_file(schema, filename):
|
||||||
|
schemaJSON = ""
|
||||||
|
|
||||||
|
schema = additional_properties(schema)
|
||||||
|
schema = replace_int_or_string(schema)
|
||||||
|
schemaJSON = json.dumps(schema)
|
||||||
|
|
||||||
|
# Dealing with user input here..
|
||||||
|
filename = os.path.basename(filename)
|
||||||
|
f = open(filename, "w")
|
||||||
|
f.write(schemaJSON)
|
||||||
|
f.close()
|
||||||
|
print("JSON schema written to {filename}".format(filename=filename))
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) == 0:
|
if len(sys.argv) == 0:
|
||||||
print("missing file")
|
print("missing file")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
@ -104,30 +119,27 @@ for crdFile in sys.argv[1:]:
|
||||||
if y["kind"] != "CustomResourceDefinition":
|
if y["kind"] != "CustomResourceDefinition":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
filename_format = os.getenv("FILENAME_FORMAT", "{kind}_{version}")
|
||||||
filename = ""
|
filename = ""
|
||||||
schemaJSON = ""
|
|
||||||
if "spec" in y and "validation" in y["spec"] and "openAPIV3Schema" in y["spec"]["validation"]:
|
if "spec" in y and "validation" in y["spec"] and "openAPIV3Schema" in y["spec"]["validation"]:
|
||||||
filename = y["spec"]["names"]["kind"].lower()+"_"+y["spec"]["version"].lower()+".json"
|
filename = filename_format.format(
|
||||||
|
kind=y["spec"]["names"]["kind"],
|
||||||
|
group=y["spec"]["group"].split(".")[0],
|
||||||
|
version=y["spec"]["version"],
|
||||||
|
).lower() + ".json"
|
||||||
|
|
||||||
schema = y["spec"]["validation"]["openAPIV3Schema"]
|
schema = y["spec"]["validation"]["openAPIV3Schema"]
|
||||||
schema = additional_properties(schema)
|
write_schema_file(schema, filename)
|
||||||
schema = replace_int_or_string(schema)
|
|
||||||
schemaJSON = json.dumps(schema)
|
|
||||||
elif "spec" in y and "versions" in y["spec"]:
|
elif "spec" in y and "versions" in y["spec"]:
|
||||||
for version in y["spec"]["versions"]:
|
for version in y["spec"]["versions"]:
|
||||||
if "schema" in version and "openAPIV3Schema" in version["schema"]:
|
if "schema" in version and "openAPIV3Schema" in version["schema"]:
|
||||||
filename = y["spec"]["names"]["kind"].lower()+"_"+version["name"].lower()+".json"
|
filename = filename_format.format(
|
||||||
|
kind=y["spec"]["names"]["kind"],
|
||||||
|
group=y["spec"]["group"].split(".")[0],
|
||||||
|
version=version["name"],
|
||||||
|
).lower() + ".json"
|
||||||
|
|
||||||
schema = version["schema"]["openAPIV3Schema"]
|
schema = version["schema"]["openAPIV3Schema"]
|
||||||
schema = additional_properties(schema)
|
write_schema_file(schema, filename)
|
||||||
schema = replace_int_or_string(schema)
|
|
||||||
schemaJSON = json.dumps(schema)
|
|
||||||
|
|
||||||
# Dealing with user input here..
|
|
||||||
filename = os.path.basename(filename)
|
|
||||||
f = open(filename, "w")
|
|
||||||
f.write(schemaJSON)
|
|
||||||
f.close()
|
|
||||||
print("JSON schema written to {filename}".format(filename=filename))
|
|
||||||
|
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue