Last active
March 9, 2020 16:42
-
-
Save dflemstr/bca89d44ea3e7730b05555a12eacf696 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
import subprocess | |
from os import path | |
# Which k8s versions to support; this is only used to support the kubeval --kubernetes-version flag | |
versions = ["master"] | |
crd_data = json.loads( | |
subprocess.check_output(["kubectl", "get", "customresourcedefinitions", "-o", "json"])) | |
crd_definitions = {} | |
for item in crd_data["items"]: | |
group = item["spec"]["group"] | |
kind = item["spec"]["names"]["kind"] | |
singular_name = item["spec"]["names"]["singular"] | |
for version in item["spec"]["versions"]: | |
validation = item["spec"].get("validation") | |
if validation is None: | |
continue | |
version_name = version["name"] | |
schema = validation["openAPIV3Schema"] | |
schema["$schema"] = "http://json-schema.org/schema#" | |
schema["x-kubernetes-group-version-kind"] = { | |
"group": group, | |
"version": version_name, | |
"kind": kind | |
} | |
group_prefix = group.split(".")[0] | |
crd_definitions[f"{singular_name}-{group_prefix}-{version_name}"] = schema | |
for version in versions: | |
version_dir = f"{version}-standalone" | |
if not path.isdir(version_dir): | |
os.mkdir(version_dir) | |
for name, schema in crd_definitions.items(): | |
with open(path.join(version_dir, name + ".json"), "w") as f: | |
json.dump(schema, f) | |
subprocess.check_call( | |
["gsutil", "-m", "cp", "-r", version_dir, | |
f"gs://spotify-declarative-infra-k8s-apis/{version_dir}"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment