Class: Rhea::Kubernetes::Nodes::All

Inherits:
Object
  • Object
show all
Defined in:
lib/rhea/kubernetes/nodes/all.rb

Instance Method Summary collapse

Instance Method Details

#performObject



5
6
7
8
9
10
11
12
13
14
15
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
# File 'lib/rhea/kubernetes/nodes/all.rb', line 5

def perform
  api = Rhea::Kubernetes::Api.new
  pods = api.get_pods
  hostnames_nodes = {}
  pods.each do |pod|
    command_expression = pod..annotations.rhea_command
    next if command_expression.nil?
    hostname = pod.spec.nodeName
    hostnames_nodes[hostname] ||= {}
    hostnames_nodes[hostname][:image] = pod[:table][:spec][:containers][0]['image']

    started_at = pod.status.startTime
    if started_at
      started_at = Time.parse(started_at)
      last_started_at = hostnames_nodes[hostname][:last_started_at]
      if last_started_at.nil? || started_at > last_started_at
        hostnames_nodes[hostname][:last_started_at] = started_at
      end
    end

    phase = pod.status.phase
    containers = pod.spec.containers
    containers.each do |container|
      image = container.image
      command = Command.new(
        expression: command_expression,
        image: image
      )
      hostnames_nodes[hostname][:commands_phases] ||= {}
      hostnames_nodes[hostname][:commands_phases][command] ||= []
      hostnames_nodes[hostname][:commands_phases][command] << phase
    end
  end
  hostnames_nodes.map do |hostname, node|
    OpenStruct.new(node.merge(hostname: hostname))
  end
end