require 'date' require 'picsolve_docker_builder/helpers/kubernetes/resource' module PicsolveDockerBuilder module Helpers module Kubernetes # A generic kuberntes resource class Pod < Resource attr_reader :pod def initialize(pod, kubernetes) @pod = pod @kubernetes = kubernetes # seconds after a running pod consider as healthy @grace_time = 20 end def remove log.debug "remove pod #{pod.metadata.name}" client.delete_pod(@pod.metadata.name, @pod.metadata.namespace) end def ready? # ensure pod is running return false unless pod.status.phase == 'Running' diff = DateTime.now - DateTime.strptime(pod.status.startTime) diff_seconds = diff * 24 * 60 * 60 # ensure pod is running for more than 20 seconds return false if diff_seconds < @grace_time true end end end end end