Class: Kubecontrol::Pod

Inherits:
Object
  • Object
show all
Defined in:
lib/kubecontrol/pod.rb

Constant Summary collapse

RESOURCE_NAME =
'pods'.freeze
RUNNING =
'Running'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, ready, status, restarts, age, namespace, client) ⇒ Pod

Returns a new instance of Pod.



8
9
10
11
12
13
14
15
16
# File 'lib/kubecontrol/pod.rb', line 8

def initialize(name, ready, status, restarts, age, namespace, client)
  @name = name
  @ready = ready
  @status = status
  @restarts = restarts
  @age = age
  @namespace = namespace
  @client = client
end

Instance Attribute Details

#ageObject (readonly)

Returns the value of attribute age.



6
7
8
# File 'lib/kubecontrol/pod.rb', line 6

def age
  @age
end

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/kubecontrol/pod.rb', line 6

def client
  @client
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/kubecontrol/pod.rb', line 6

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



6
7
8
# File 'lib/kubecontrol/pod.rb', line 6

def namespace
  @namespace
end

#readyObject (readonly)

Returns the value of attribute ready.



6
7
8
# File 'lib/kubecontrol/pod.rb', line 6

def ready
  @ready
end

#restartsObject (readonly)

Returns the value of attribute restarts.



6
7
8
# File 'lib/kubecontrol/pod.rb', line 6

def restarts
  @restarts
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/kubecontrol/pod.rb', line 6

def status
  @status
end

Instance Method Details

#exec(command) ⇒ Object



31
32
33
# File 'lib/kubecontrol/pod.rb', line 31

def exec(command)
  @client.kubectl_command("exec -i #{name} -- sh -c \"#{command.gsub('"', '\"')}\"")
end

#ready?Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/kubecontrol/pod.rb', line 26

def ready?
  pod_containers = @ready.split('/').last
  @ready == "#{pod_containers}/#{pod_containers}"
end

#running?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/kubecontrol/pod.rb', line 22

def running?
  @status == RUNNING
end

#stopped?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/kubecontrol/pod.rb', line 18

def stopped?
  @status != RUNNING
end