Class: Kuberun::Commands::RunPod
- Inherits:
-
Kuberun::Command
- Object
- Kuberun::Command
- Kuberun::Commands::RunPod
- Defined in:
- lib/kuberun/commands/run_pod.rb
Constant Summary collapse
- NEW_POD =
'Start new one'
Instance Method Summary collapse
- #execute(input: $stdin, output: $stdout) ⇒ Object
-
#initialize(deployment_name, options) ⇒ RunPod
constructor
A new instance of RunPod.
Methods inherited from Kuberun::Command
#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #screen, #which
Constructor Details
#initialize(deployment_name, options) ⇒ RunPod
Returns a new instance of RunPod.
10 11 12 13 14 |
# File 'lib/kuberun/commands/run_pod.rb', line 10 def initialize(deployment_name, ) @deployment_name = deployment_name @options = super() end |
Instance Method Details
#execute(input: $stdin, output: $stdout) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/kuberun/commands/run_pod.rb', line 16 def execute(input: $stdin, output: $stdout) output.puts(Kuberun::Pastel.yellow('Checking access to needed commands...')) Kuberun::Kubectl.auth_check('create', resource: 'pods') Kuberun::Kubectl.auth_check('exec', resource: 'pods') output.puts(Kuberun::Pastel.green('You have all permissions needed.')) output.puts(Kuberun::Pastel.yellow('Searching for existing pods')) existing_pods = Kuberun::Kubectl.get(resource: 'pods', options: "-l kuberun-provisioned=true,kuberun-source=#{@deployment_name}") if existing_pods['items'].size > 0 select = existing_pods['items'].map { |item| item.dig('metadata', 'name') } select << NEW_POD selection = prompt.select('I found some already running pods. Do you want to use one?', select) if selection == NEW_POD create_pod_from_deployment(output) else @generated_pod_name = selection end else create_pod_from_deployment(output) end execute_command(input, output) unless prompt.no?('Should I delete pod?') Kuberun::Kubectl.delete(resource: 'pod', resource_name: generated_pod_name) end output.puts(Kuberun::Pastel.green('Done!')) end |