Class: Vidar::K8s::Container
- Inherits:
-
Object
- Object
- Vidar::K8s::Container
- Defined in:
- lib/vidar/k8s/container.rb
Constant Summary collapse
- JOB_KIND =
"Job".freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#pod_name ⇒ Object
readonly
Returns the value of attribute pod_name.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #deployed? ⇒ Boolean
-
#initialize(data) ⇒ Container
constructor
A new instance of Container.
- #istio? ⇒ Boolean
- #job? ⇒ Boolean
- #name ⇒ Object
- #print ⇒ Object
- #ready? ⇒ Boolean
- #ready_and_running? ⇒ Boolean
- #running? ⇒ Boolean
- #running_started_at ⇒ Object
- #success? ⇒ Boolean
- #terminated? ⇒ Boolean
- #terminated_completed? ⇒ Boolean
- #terminated_error? ⇒ Boolean
- #terminated_finished_at ⇒ Object
- #text_statuses ⇒ Object
- #to_text ⇒ Object
- #unschedulable? ⇒ Boolean
- #waiting? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ Container
Returns a new instance of Container.
10 11 12 13 14 15 16 17 18 |
# File 'lib/vidar/k8s/container.rb', line 10 def initialize(data) @data = data @state = data["state"] || {} @namespace = data["namespace"] @kind = data["kind"] @pod_name = data["pod_name"] @reason = data["reason"] @message = data["message"] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/vidar/k8s/container.rb', line 6 def data @data end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
6 7 8 |
# File 'lib/vidar/k8s/container.rb', line 6 def kind @kind end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/vidar/k8s/container.rb', line 6 def @message end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
6 7 8 |
# File 'lib/vidar/k8s/container.rb', line 6 def namespace @namespace end |
#pod_name ⇒ Object (readonly)
Returns the value of attribute pod_name.
6 7 8 |
# File 'lib/vidar/k8s/container.rb', line 6 def pod_name @pod_name end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
6 7 8 |
# File 'lib/vidar/k8s/container.rb', line 6 def reason @reason end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
6 7 8 |
# File 'lib/vidar/k8s/container.rb', line 6 def state @state end |
Instance Method Details
#deployed? ⇒ Boolean
24 25 26 27 28 |
# File 'lib/vidar/k8s/container.rb', line 24 def deployed? return terminated? if job? ready? && running? end |
#istio? ⇒ Boolean
114 115 116 |
# File 'lib/vidar/k8s/container.rb', line 114 def istio? name == "istio-proxy" end |
#job? ⇒ Boolean
110 111 112 |
# File 'lib/vidar/k8s/container.rb', line 110 def job? kind == JOB_KIND end |
#name ⇒ Object
20 21 22 |
# File 'lib/vidar/k8s/container.rb', line 20 def name data["name"] || pod_name end |
#print ⇒ Object
40 41 42 |
# File 'lib/vidar/k8s/container.rb', line 40 def print puts to_text end |
#ready? ⇒ Boolean
78 79 80 |
# File 'lib/vidar/k8s/container.rb', line 78 def ready? data["ready"] end |
#ready_and_running? ⇒ Boolean
36 37 38 |
# File 'lib/vidar/k8s/container.rb', line 36 def ready_and_running? ready? && running? end |
#running? ⇒ Boolean
82 83 84 |
# File 'lib/vidar/k8s/container.rb', line 82 def running? !running_started_at.nil? end |
#running_started_at ⇒ Object
86 87 88 |
# File 'lib/vidar/k8s/container.rb', line 86 def running_started_at state.dig("running", "startedAt") end |
#success? ⇒ Boolean
30 31 32 33 34 |
# File 'lib/vidar/k8s/container.rb', line 30 def success? return terminated_completed? if job? ready_and_running? end |
#terminated? ⇒ Boolean
90 91 92 |
# File 'lib/vidar/k8s/container.rb', line 90 def terminated? !state["terminated"].nil? end |
#terminated_completed? ⇒ Boolean
94 95 96 |
# File 'lib/vidar/k8s/container.rb', line 94 def terminated_completed? state.dig("terminated", "reason") == "Completed" || state.dig("terminated", "exitCode") == 0 end |
#terminated_error? ⇒ Boolean
102 103 104 |
# File 'lib/vidar/k8s/container.rb', line 102 def terminated_error? state.dig("terminated", "reason") == "Error" || state.dig("terminated", "exitCode") end |
#terminated_finished_at ⇒ Object
98 99 100 |
# File 'lib/vidar/k8s/container.rb', line 98 def terminated_finished_at state.dig("terminated", "finishedAt") end |
#text_statuses ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vidar/k8s/container.rb', line 52 def text_statuses if unschedulable? [ColorizedString["Unschedulable"].light_red, ColorizedString[].light_red] elsif running? if job? [ColorizedString["Running"].light_yellow, "Started at: #{running_started_at}"] elsif ready? [ColorizedString["Ready & Running"].light_green, "Started at: #{running_started_at}"] else [ColorizedString["Not ready"].light_red, "Started at: #{running_started_at}"] end elsif terminated_completed? [ColorizedString["Terminated/Completed"].light_green, terminated_finished_at ? "Finished at: #{terminated_finished_at}" : ""] elsif terminated_error? [ColorizedString["Terminated/Error"].light_red, ""] elsif waiting? [ColorizedString["Waiting"].light_yellow, ""] else [ColorizedString[state.inspect].light_red, ""] end end |
#to_text ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/vidar/k8s/container.rb', line 44 def to_text parts = [] parts << namespace.to_s.ljust(20, " ") parts << name.to_s.ljust(35, " ") parts += text_statuses.map { |s| s.ljust(45, " ") } "| #{parts.join(' | ')} |" end |
#unschedulable? ⇒ Boolean
106 107 108 |
# File 'lib/vidar/k8s/container.rb', line 106 def unschedulable? reason == "Unschedulable" end |
#waiting? ⇒ Boolean
74 75 76 |
# File 'lib/vidar/k8s/container.rb', line 74 def waiting? state["waiting"] end |