Class: K8sKit::Job
- Inherits:
-
Object
- Object
- K8sKit::Job
- Defined in:
- lib/k8s_kit/job.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #attach(container:, delete_on_completion: true, exit_on_completion: true) ⇒ Object
- #delete ⇒ Object
-
#initialize(context, name) ⇒ Job
constructor
A new instance of Job.
- #pod ⇒ Object
Constructor Details
#initialize(context, name) ⇒ Job
Returns a new instance of Job.
5 6 7 8 |
# File 'lib/k8s_kit/job.rb', line 5 def initialize(context, name) @context = context @name = name end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/k8s_kit/job.rb', line 3 def context @context end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/k8s_kit/job.rb', line 3 def name @name end |
Instance Method Details
#attach(container:, delete_on_completion: true, exit_on_completion: true) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/k8s_kit/job.rb', line 10 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 |
#delete ⇒ Object
21 22 23 |
# File 'lib/k8s_kit/job.rb', line 21 def delete context.run("delete job #{name}") end |
#pod ⇒ Object
25 26 27 28 29 30 |
# File 'lib/k8s_kit/job.rb', line 25 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 |