Class: K8sKit::Pod
- Inherits:
-
Object
- Object
- K8sKit::Pod
- Defined in:
- lib/k8s_kit/pod.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
- #exit_code(container:) ⇒ Object
-
#initialize(context, name) ⇒ Pod
constructor
A new instance of Pod.
- #logs(container: nil, stream: false) ⇒ Object
- #wait_until_ready(timeout: '5m') ⇒ Object
Constructor Details
#initialize(context, name) ⇒ Pod
Returns a new instance of Pod.
5 6 7 8 |
# File 'lib/k8s_kit/pod.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/pod.rb', line 3 def context @context end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/k8s_kit/pod.rb', line 3 def name @name end |
Instance Method Details
#exit_code(container:) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/k8s_kit/pod.rb', line 22 def exit_code(container:) json_path = "{ .status.containerStatuses[?(@.name == '#{container}')].state.terminated.exitCode }" Integer(context.run("get pod #{name} -o jsonpath=\"#{json_path}\"")) rescue StandardError nil end |
#logs(container: nil, stream: false) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/k8s_kit/pod.rb', line 10 def logs(container: nil, stream: false) command = "logs #{name}" command += " -c #{container}" if container command += " -f" if stream context.run(command, silent: false) end |
#wait_until_ready(timeout: '5m') ⇒ Object
18 19 20 |
# File 'lib/k8s_kit/pod.rb', line 18 def wait_until_ready(timeout: '5m') context.run("wait pod/#{name} --for=condition=Ready --timeout=#{timeout}") end |