Skip to content

Commit

Permalink
Extract error_notice? and parse_notice methods
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Feb 13, 2024
1 parent 8a15e24 commit 45e3def
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions lib/floe/workflow/runner/kubernetes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,13 @@ def wait(timeout: nil, events: %i[create update delete])
end

watcher.each do |notice|
if notice.type == "ERROR"
message = notice.object&.message
code = notice.object&.code
reason = notice.object&.reason

logger.warn("Received [#{code} #{reason}], [#{message}]")
break
end
break if error_notice?(notice)

event = kube_notice_type_to_event(notice.type)
next unless events.include?(event)

pod = notice.object
container_ref = pod.metadata.name
container_state = pod.to_h[:status].deep_stringify_keys

runner_context = {"container_ref" => container_ref, "container_state" => container_state}
runner_context = parse_notice(notice)
next if runner_context.nil?

if block_given?
yield [event, runner_context]
Expand Down Expand Up @@ -288,6 +278,28 @@ def kube_notice_type_to_event(type)
end
end

def error_notice?(notice)
return false unless notice.type == "ERROR"

message = notice.object&.message
code = notice.object&.code
reason = notice.object&.reason

logger.warn("Received [#{code} #{reason}], [#{message}]")

true
end

def parse_notice(notice)
return if notice.object.nil?

pod = notice.object
container_ref = pod.metadata.name
container_state = pod.to_h[:status].deep_stringify_keys

{"container_ref" => container_ref, "container_state" => container_state}
end

def kubeclient
return @kubeclient unless @kubeclient.nil?

Expand Down

0 comments on commit 45e3def

Please sign in to comment.