scripts: Check versions before version

CRD versions can have multiple schemas, but they can also share the
same.

https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#specify-multiple-versions
This commit is contained in:
Maxime Brunet 2021-07-12 16:58:39 -07:00
parent f8ffb2f9e3
commit c489a69a4c
No known key found for this signature in database
GPG key ID: 757B11B65F872567

View file

@ -123,16 +123,7 @@ for crdFile in sys.argv[1:]:
filename_format = os.getenv("FILENAME_FORMAT", "{kind}_{version}")
filename = ""
if "spec" in y and "validation" in y["spec"] and "openAPIV3Schema" in y["spec"]["validation"]:
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"]
write_schema_file(schema, filename)
elif "spec" in y and "versions" in y["spec"]:
if "spec" in y and "versions" in y["spec"] and y["spec"]["versions"]:
for version in y["spec"]["versions"]:
if "schema" in version and "openAPIV3Schema" in version["schema"]:
filename = filename_format.format(
@ -143,5 +134,23 @@ for crdFile in sys.argv[1:]:
schema = version["schema"]["openAPIV3Schema"]
write_schema_file(schema, filename)
elif "validation" in y["spec"] and "openAPIV3Schema" in y["spec"]["validation"]:
filename = filename_format.format(
kind=y["spec"]["names"]["kind"],
group=y["spec"]["group"].split(".")[0],
version=version["name"],
).lower() + ".json"
schema = y["spec"]["validation"]["openAPIV3Schema"]
write_schema_file(schema, filename)
elif "spec" in y and "validation" in y["spec"] and "openAPIV3Schema" in y["spec"]["validation"]:
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"]
write_schema_file(schema, filename)
exit(0)