Skip to content

Instantly share code, notes, and snippets.

@lnattrass
Created August 25, 2020 20:16
Show Gist options
  • Save lnattrass/1886b28bcfe85484fc88bfc7892cb6a8 to your computer and use it in GitHub Desktop.
Save lnattrass/1886b28bcfe85484fc88bfc7892cb6a8 to your computer and use it in GitHub Desktop.
Split Kubernetes Manifests to Directory
#!/usr/bin/env python3
import sys
import os
from ruamel.yaml import YAML
yaml = YAML()
infilename = sys.argv[1]
outfolder = sys.argv[2]
doc_counter=0
with open(infilename) as infile:
docs = yaml.load_all(infile)
for doc in docs:
if not doc:
continue
outpath = f"{outfolder}/{doc['kind']}-{doc['metadata']['name']}.yaml"
print(f"Writing {outpath}")
with open(f"{outpath}", 'w') as outfile:
yaml.dump(doc, outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment