Sha256: 97e53bb14eab0e9493846c5c857c14e06e8fc52d46c83c6eadd84171f246f2a3

Contents?: true

Size: 728 Bytes

Versions: 4

Compression:

Stored size: 728 Bytes

Contents

module K8sKit
  class Job
    attr_reader :context, :name

    def initialize(context, name)
      @context = context
      @name = name
    end

    def attach(container:, delete_on_completion: true, exit_on_completion: true)
      pod.wait_until_ready
      pod.logs(container: container, stream: true)
      exit_code = pod.exit_code(container: container)

      delete if delete_on_completion
      exit exit_code if exit_on_completion

      exit_code
    end

    def delete
      context.run("delete job #{name}")
    end

    def pod
      @pod ||= begin
        pod_name = context.run("get pod -l job-name=#{name} -o jsonpath='{.items[0].metadata.name}'")
        Pod.new(context, pod_name)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
k8s_kit-0.0.5 lib/k8s_kit/job.rb
k8s_kit-0.0.3 lib/k8s_kit/job.rb
k8s_kit-0.0.2 lib/k8s_kit/job.rb
k8s_kit-0.0.1 lib/k8s_kit/job.rb