in hack/build_kfdef_specs.py [0:0]
def run():
root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
kfdef_dir = os.path.join(root, "kfdef")
source_dir = os.path.join(root, "kfdef", "source")
# Walk over all versions
for base, dirs, _ in os.walk(source_dir):
for version in dirs:
package_dir = os.path.join(base, version)
# Create a temporary directory to write all the kustomize output to
temp_dir = tempfile.mkdtemp()
subprocess.check_call(["kustomize", "build", package_dir, "-o",
temp_dir])
for f in os.listdir(temp_dir):
new_name = f[len(RESOURCE_PREFIX):]
# To preserve the existing pattern for now master files are just
# named kfctl_?.Yaml
# whereas version files are named kfctl_?.version.yaml
# in subsequent PRs we might change that
if version == "master":
ext = ".yaml"
else:
ext = "." + version + ".yaml"
basename, _ = os.path.splitext(new_name)
new_name = basename + ext
new_file = os.path.join(kfdef_dir, new_name.replace("-", "_"))
logging.info(f"Processing file: {f} -> {new_file}")
with open(os.path.join(temp_dir, f)) as hf:
spec = yaml.load(hf)
# Remove the name. Kustomize requires a name but we don't want
# a name so that kfctl will fill it in based on the app directory
del spec["metadata"]["name"]
with open(new_file, "w") as hf:
yaml.safe_dump(spec, hf, default_flow_style = False)