Class: Kerby::Cli
- Inherits:
-
Thor
- Object
- Thor
- Kerby::Cli
- Defined in:
- lib/kerby/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build(*src_manifests) ⇒ Object
-
#k8s_config_map(path) ⇒ Object
k8s_include with YAML indent.
-
#k8s_include(path) ⇒ Object
k8s include directive.
-
#k8s_node(key) ⇒ Object
return node_yaml value for the key.
Class Method Details
.exit_on_failure? ⇒ Boolean
13 14 15 |
# File 'lib/kerby/cli.rb', line 13 def exit_on_failure? true end |
Instance Method Details
#build(*src_manifests) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/kerby/cli.rb', line 20 def build(*src_manifests) load_k8s_node([:node_yaml]) temp_name = sprintf("/tmp/kerby-%s-%s.yml", Time.now.strftime("%Y%m%d-%H%M%S"), SecureRandom.alphanumeric(8).downcase) t = File.open(temp_name, 'w') for src_manifest in src_manifests do saved_file = @_curr_file; @_curr_file = src_manifest File.write(t.path, ERB.new(File.read(src_manifest)).result(binding)) end t.close File.open(temp_name) do |f| while s = f.gets do print s end end FileUtils.rm_f(temp_name) @_curr_file = saved_file end |
#k8s_config_map(path) ⇒ Object
k8s_include with YAML indent
109 110 111 112 113 114 |
# File 'lib/kerby/cli.rb', line 109 def k8s_config_map(path) "|\n" + ERB.new(File.read(Pathname(@_curr_file).dirname + path)).result(binding).split("\n").map do |line| " " + line + "\n" end.join('') end |
#k8s_include(path) ⇒ Object
k8s include directive
For example, <%= k8s_include(‘base/namespace’) %> in manifest file will include ‘base/namespace.yml’ file.
The path is relative to the current (sometimes partial) manifest file.
52 53 54 |
# File 'lib/kerby/cli.rb', line 52 def k8s_include(path) ERB.new(File.read(Pathname(@_curr_file).dirname + (path + '.yml'))).result(binding) end |
#k8s_node(key) ⇒ Object
return node_yaml value for the key.
For example, command execution:
$ kerby build --node_yaml staging-node.yml manifest.yml
and stageing-node.yml contains:
app:
namespace: city-A
Then, <%= k8s_node(‘app.namespace’) %> in manifest.yml will be generated to ‘city-A’.
89 90 91 |
# File 'lib/kerby/cli.rb', line 89 def k8s_node(key) k8s_node_sub(@_k8s_node, key, key) end |