Class: Dapp::Kube::Kubernetes::Client::Resource::Pod

Inherits:
Base
  • Object
show all
Defined in:
lib/dapp/kube/kubernetes/client/resource/pod.rb

Instance Attribute Summary

Attributes inherited from Base

#spec

Instance Method Summary collapse

Methods inherited from Base

#annotations, #initialize, #metadata, #name, #status, #uid

Constructor Details

This class inherits a constructor from Dapp::Kube::Kubernetes::Client::Resource::Base

Instance Method Details

#container_id(container_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dapp/kube/kubernetes/client/resource/pod.rb', line 19

def container_id(container_name)
  container_status = spec.fetch('status', {})
    .fetch('containerStatuses')
    .find {|cs| cs['name'] == container_name}

  if container_status
    container_status['containerID']
  else
    nil
  end
end

#container_state(container_name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dapp/kube/kubernetes/client/resource/pod.rb', line 31

def container_state(container_name)
  container_status = status
    .fetch('containerStatuses', [])
    .find {|cs| cs['name'] == container_name}

  if container_status
    container_state, container_state_data = container_status.fetch('state', {}).first
    [container_state, container_state_data]
  else
    [nil, {}]
  end
end

#containers_namesObject



48
49
50
51
52
# File 'lib/dapp/kube/kubernetes/client/resource/pod.rb', line 48

def containers_names
  spec.fetch('spec', {})
    .fetch('containers', [])
    .map {|container_spec| container_spec['name']}
end

#phaseObject



44
45
46
# File 'lib/dapp/kube/kubernetes/client/resource/pod.rb', line 44

def phase
  status.fetch('phase', nil)
end

#ready_conditionObject



15
16
17
# File 'lib/dapp/kube/kubernetes/client/resource/pod.rb', line 15

def ready_condition
  status.fetch('conditions', {}).find {|condition| condition['type'] == 'Ready'}
end

#ready_condition_statusObject

Returns:

nil: no such condition yet
"True" string: ready
"False" string: not ready


9
10
11
12
13
# File 'lib/dapp/kube/kubernetes/client/resource/pod.rb', line 9

def ready_condition_status
  rd = self.ready_condition
  return nil unless rd
  return rd['status']
end

#restart_policyObject



54
55
56
57
58
# File 'lib/dapp/kube/kubernetes/client/resource/pod.rb', line 54

def restart_policy
  spec
    .fetch('spec', {})
    .fetch('restartPolicy', nil)
end