Created
May 23, 2018 12:25
-
-
Save yuya-takeyama/61ef7f0aabd54c5526cd68d63f2a0c8c to your computer and use it in GitHub Desktop.
Split List object definition YAML into separate files
This file contains 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
#!/usr/bin/env ruby | |
require 'yaml' | |
def kind_to_sub_extension(kind) | |
case kind | |
when 'ConfigMap' | |
'cm' | |
when 'DaemonSet' | |
'ds' | |
when 'Deployment' | |
'deploy' | |
when 'Service' | |
'svc' | |
else | |
kind.downcase | |
end | |
end | |
YAML.load(ARGF.read)['items'].each do |item| | |
name = item.dig('metadata', 'name') | |
kind = item.fetch('kind') | |
file = "#{name}.#{kind_to_sub_extension(kind)}.yaml" | |
warn "Creating #{file}..." | |
open(file, "w") do |f| | |
f.write(YAML.dump(item)) | |
end | |
end | |
warn "Finished." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment