Sha256: cebb9794ef015726ce94da7f1f1d323d6aa52c5df88b8f6fccade2ec847110df

Contents?: true

Size: 991 Bytes

Versions: 13

Compression:

Stored size: 991 Bytes

Contents

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
picsolve_docker_builder-0.5.5 lib/picsolve_docker_builder/helpers/kubernetes/pod.rb
picsolve_docker_builder-0.5.4 lib/picsolve_docker_builder/helpers/kubernetes/pod.rb
picsolve_docker_builder-0.5.3 lib/picsolve_docker_builder/helpers/kubernetes/pod.rb
picsolve_docker_builder-0.5.2 lib/picsolve_docker_builder/helpers/kubernetes/pod.rb
picsolve_docker_builder-0.5.1 lib/picsolve_docker_builder/helpers/kubernetes/pod.rb
picsolve_docker_builder-0.5.0 lib/picsolve_docker_builder/helpers/kubernetes/pod.rb
picsolve_docker_builder-0.4.0 lib/picsolve_docker_builder/helpers/kubernetes/pod.rb
picsolve_docker_builder-0.3.2 lib/picsolve_docker_builder/helpers/kubernetes/pod.rb
picsolve_docker_builder-0.3.1 lib/picsolve_docker_builder/helpers/kubernetes/pod.rb
picsolve_docker_builder-0.3.0 lib/picsolve_docker_builder/helpers/kubernetes/pod.rb
picsolve_docker_builder-0.2.0 lib/picsolve_docker_builder/helpers/kubernetes/pod.rb
picsolve_docker_builder-0.1.1 lib/picsolve_docker_builder/helpers/kubernetes/pod.rb
picsolve_docker_builder-0.1.0 lib/picsolve_docker_builder/helpers/kubernetes/pod.rb