Class: Cloud::Sh::Commands::K8sExec

Inherits:
Base
  • Object
show all
Defined in:
lib/cloud/sh/commands/k8s_exec.rb

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#config, execute, #initialize

Methods included from Helpers::Commands

#command_chain

Constructor Details

This class inherits a constructor from Cloud::Sh::Commands::Base

Instance Method Details

#executeObject



9
10
11
12
13
14
15
16
17
# File 'lib/cloud/sh/commands/k8s_exec.rb', line 9

def execute
  pod = kubectl.context(options[:context]).namespace(options[:namespace]).get.pod.no_headers(true).map(:name).find do |pod|
    pod.name.start_with?(options[:pod])
  end
  raise "Cannot find pod." unless pod
  command = kubectl.context(options[:context]).namespace(options[:namespace]).exec.with(pod.name).stdin(true).tty(true).with(options[:cmd])
  puts "Command: #{command}\n"
  command.replace_current_process
end

#kubectlObject



19
20
21
# File 'lib/cloud/sh/commands/k8s_exec.rb', line 19

def kubectl
  command_chain("kubectl").kubeconfig(Cloud::Sh::Providers::DigitalOcean.kube_config)
end