Module: Cuber::Utils
- Included in:
- Commands::Ctl, Commands::Deploy, Commands::Info, Commands::Logs, Commands::Restart, Commands::Run
- Defined in:
- lib/cuber/utils.rb
Instance Method Summary collapse
- #kubectl(*args) ⇒ Object
- #kubeget(type, name = nil, *args) ⇒ Object
- #render(template, target_file = nil) ⇒ Object
Instance Method Details
#kubectl(*args) ⇒ Object
3 4 5 6 |
# File 'lib/cuber/utils.rb', line 3 def kubectl *args cmd = ['kubectl', '--kubeconfig', @options[:kubeconfig], '-n', @options[:app]] + args system(*cmd) || abort("Cuber: \"#{cmd.shelljoin}\" failed") end |
#kubeget(type, name = nil, *args) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/cuber/utils.rb', line 8 def kubeget type, name = nil, *args cmd = ['kubectl', 'get', type, name, '-o', 'json', '--kubeconfig', @options[:kubeconfig], '-n', @options[:app], *args].compact out, status = Open3.capture2 *cmd abort "Cuber: \"#{cmd.shelljoin}\" failed" unless status.success? out.empty? ? nil : JSON.parse(out) end |
#render(template, target_file = nil) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/cuber/utils.rb', line 15 def render template, target_file = nil template = File.join __dir__, 'templates', "#{template}.erb" renderer = ERB.new File.read(template), trim_mode: '-' content = renderer.result binding return content unless target_file FileUtils.mkdir_p File.dirname target_file File.write target_file, content end |