Sha256: 023ef0d29b0378f0b8499138d6ebaf5ab7702f68896e3012576af88983c725e3
Contents?: true
Size: 1.89 KB
Versions: 4
Compression:
Stored size: 1.89 KB
Contents
module Vidar module K8s class ContainerStatus attr_reader :data, :state, :namespace def initialize(data) @data = data @state = data["state"] @namespace = data["namespace"] end def name data["name"] end def ok? (ready? && running?) || terminated_completed? end def print puts to_text end def to_text parts = [] parts << namespace.to_s.ljust(20, " ") parts << name.to_s.ljust(25, " ") parts += text_statuses.map { |s| s.ljust(40, " ") } "| #{parts.join(' | ')} |" end def text_statuses if running? if 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, "Finished at: #{terminated_finished_at}"] elsif terminated_error? [ColorizedString["Terminated/Error"].light_red] elsif waiting? [ColorizedString["Waiting"].light_green] else [ColorizedString[state.inspect].light_red] end end def waiting? state["waiting"] end def ready? data["ready"] end def running? !running_started_at.nil? end def running_started_at state.dig("running", "startedAt") end def terminated_completed? state.dig("terminated", "reason") == "Completed" || state.dig("terminated", "exitCode") == 0 end def terminated_finished_at state.dig("terminated", "finishedAt") end def terminated_error? state.dig("terminated", "reason") == "Error" || state.dig("terminated", "exitCode") end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
vidar-0.3.4 | lib/vidar/k8s/container_status.rb |
vidar-0.3.3 | lib/vidar/k8s/container_status.rb |
vidar-0.3.2 | lib/vidar/k8s/container_status.rb |
vidar-0.3.0 | lib/vidar/k8s/container_status.rb |