Class: Kubert::Pods
- Inherits:
-
Object
- Object
- Kubert::Pods
- Defined in:
- lib/kubert/pods.rb
Instance Attribute Summary collapse
-
#pods ⇒ Object
readonly
Returns the value of attribute pods.
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
Class Method Summary collapse
- .console ⇒ Object
- .execute(command) ⇒ Object
- .list(pod_type, status) ⇒ Object
- .logs(pod_type, status) ⇒ Object
Instance Method Summary collapse
- #all(pod_type) ⇒ Object
- #execute(command, pod_type = Kubert.task_pod) ⇒ Object
-
#initialize(project_name = Kubert.configuration[:project_name]) ⇒ Pods
constructor
A new instance of Pods.
- #logs ⇒ Object
- #names ⇒ Object
- #status(pod_status) ⇒ Object
Constructor Details
#initialize(project_name = Kubert.configuration[:project_name]) ⇒ Pods
Returns a new instance of Pods.
20 21 22 23 |
# File 'lib/kubert/pods.rb', line 20 def initialize(project_name= Kubert.configuration[:project_name]) @project_name = project_name @pods = [] end |
Instance Attribute Details
#pods ⇒ Object (readonly)
Returns the value of attribute pods.
19 20 21 |
# File 'lib/kubert/pods.rb', line 19 def pods @pods end |
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
19 20 21 |
# File 'lib/kubert/pods.rb', line 19 def project_name @project_name end |
Class Method Details
.console ⇒ Object
7 8 9 |
# File 'lib/kubert/pods.rb', line 7 def self.console new.console end |
.execute(command) ⇒ Object
11 12 13 |
# File 'lib/kubert/pods.rb', line 11 def self.execute(command) new.execute(command) end |
.list(pod_type, status) ⇒ Object
3 4 5 |
# File 'lib/kubert/pods.rb', line 3 def self.list(pod_type, status) new.all(pod_type).status(status).names end |
.logs(pod_type, status) ⇒ Object
15 16 17 |
# File 'lib/kubert/pods.rb', line 15 def self.logs(pod_type, status) new.all(pod_type).status(status).logs end |
Instance Method Details
#all(pod_type) ⇒ Object
25 26 27 28 |
# File 'lib/kubert/pods.rb', line 25 def all(pod_type) @pods = Kubert.client.get_pods(label_selector: "app=#{project_name}-#{pod_type}") self end |
#execute(command, pod_type = Kubert.task_pod) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/kubert/pods.rb', line 39 def execute(command, pod_type=Kubert.task_pod) pod = all(pod_type).status(:running).pods.sample exec_command = "kubectl exec -n #{pod.metadata.namespace} #{pod.metadata.name} -it #{Kubert.command_prefix} #{command.join(' ')}" puts "Executing command: \n#{exec_command}" Open3.popen3("bash") do exec exec_command end puts "THIS WILL NEVER EXECUTE BECAUSE OF EXEC ABOVE" end |
#logs ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kubert/pods.rb', line 49 def logs fibers = names.map.with_index do |pod_name, i| puts "logging #{pod_name}:" watcher = Kubert.client.watch_pod_log(pod_name, pods.first..namespace) pod_name = names[i] log_enum = watcher.to_enum Fiber.new do loop do Fiber.yield(puts "#{pod_name} |> #{log_enum.next}") end end end while fibers.all?(&:alive?) do fibers.shuffle.each(&:resume) end end |
#names ⇒ Object
35 36 37 |
# File 'lib/kubert/pods.rb', line 35 def names pods.map(&:metadata).map(&:name) end |
#status(pod_status) ⇒ Object
30 31 32 33 |
# File 'lib/kubert/pods.rb', line 30 def status(pod_status) @pods = pods.select {|pod| pod.status.phase.downcase == pod_status.to_s } self end |