class Vidar::K8s::Container

Constants

JOB_KIND

Attributes

data[R]
kind[R]
message[R]
namespace[R]
pod_name[R]
reason[R]
state[R]

Public Class Methods

new(data) click to toggle source
# 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

Public Instance Methods

deployed?() click to toggle source
# File lib/vidar/k8s/container.rb, line 24
def deployed?
  return terminated? if job?

  ready? && running?
end
istio?() click to toggle source
# File lib/vidar/k8s/container.rb, line 114
def istio?
  name == "istio-proxy"
end
job?() click to toggle source
# File lib/vidar/k8s/container.rb, line 110
def job?
  kind == JOB_KIND
end
name() click to toggle source
# File lib/vidar/k8s/container.rb, line 20
def name
  data["name"] || pod_name
end
print() click to toggle source
ready?() click to toggle source
# File lib/vidar/k8s/container.rb, line 78
def ready?
  data["ready"]
end
ready_and_running?() click to toggle source
# File lib/vidar/k8s/container.rb, line 36
def ready_and_running?
  ready? && running?
end
running?() click to toggle source
# File lib/vidar/k8s/container.rb, line 82
def running?
  !running_started_at.nil?
end
running_started_at() click to toggle source
# File lib/vidar/k8s/container.rb, line 86
def running_started_at
  state.dig("running", "startedAt")
end
success?() click to toggle source
# File lib/vidar/k8s/container.rb, line 30
def success?
  return terminated_completed? if job?

  ready_and_running?
end
terminated?() click to toggle source
# File lib/vidar/k8s/container.rb, line 90
def terminated?
  !state["terminated"].nil?
end
terminated_completed?() click to toggle source
# File lib/vidar/k8s/container.rb, line 94
def terminated_completed?
  state.dig("terminated", "reason") == "Completed" || state.dig("terminated", "exitCode") == 0
end
terminated_error?() click to toggle source
# File lib/vidar/k8s/container.rb, line 102
def terminated_error?
  state.dig("terminated", "reason") == "Error" || state.dig("terminated", "exitCode")
end
terminated_finished_at() click to toggle source
# File lib/vidar/k8s/container.rb, line 98
def terminated_finished_at
  state.dig("terminated", "finishedAt")
end
text_statuses() click to toggle source
# File lib/vidar/k8s/container.rb, line 52
def text_statuses
  if unschedulable?
    [ColorizedString["Unschedulable"].light_red, ColorizedString[message].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() click to toggle source
# 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?() click to toggle source
# File lib/vidar/k8s/container.rb, line 106
def unschedulable?
  reason == "Unschedulable"
end
waiting?() click to toggle source
# File lib/vidar/k8s/container.rb, line 74
def waiting?
  state["waiting"]
end