Class: Runners::Kubernetes::UpdateNodeStatus

Inherits:
Object
  • Object
show all
Includes:
UpdateNodeStatusHelper
Defined in:
app/services/runners/kubernetes/update_node_status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UpdateNodeStatusHelper

#check_slot_release, #remove_unknown_runner, #send_metrics

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



8
9
10
# File 'app/services/runners/kubernetes/update_node_status.rb', line 8

def node
  @node
end

Instance Method Details

#perform(node:) ⇒ Object



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
42
43
44
45
# File 'app/services/runners/kubernetes/update_node_status.rb', line 10

def perform(node:)
  @node = node

  # Other tasks can be started at this time. Because of this it's necessary to load the tasks first and then the containers
  started_tasks = Task.started.where(:slot.in => node.slots.pluck(:id)).to_a

  node.update!(runner_capacity_reached: pending_schedule_pods?)

  execution_infos.each do |execution_info|
    runner_id = execution_info.id
    slot = node.slots.find_by(runner_id: runner_id)

    if slot
      if execution_info.terminated?
        Rails.logger.debug("Pod #{runner_id} Complete")
        check_slot_release(slot: slot, runner_id: runner_id)
      else
        slot.current_task&.update!(error: execution_info.error) if execution_info.error
        Rails.logger.debug("Pod is not terminated (it is #{execution_info.status}). Ignoring.")
      end
    else
      remove_unknown_runner(node: node, runner_id: runner_id)
    end
  end

  RescheduleTasksForMissingRunners
    .new(runner_ids: pods.keys, started_tasks: started_tasks)
    .perform

  node.register_success

  send_metrics(node: node, execution_infos: execution_infos)
rescue KubernetesClient::NetworkError => e
  Rails.logger.debug("Error #{e.class}: #{e}")
  node.register_error(e.message)
end