Class: Kubecontrol::Resources::Pod

Inherits:
Object
  • Object
show all
Defined in:
lib/kubecontrol/resources/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.



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

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.



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

def age
  @age
end

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

#readyObject (readonly)

Returns the value of attribute ready.



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

def ready
  @ready
end

#restartsObject (readonly)

Returns the value of attribute restarts.



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

def restarts
  @restarts
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#exec(command) ⇒ Object



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

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

#ready?Boolean

Returns:

  • (Boolean)


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

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

#running?Boolean

Returns:

  • (Boolean)


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

def running?
  @status == RUNNING
end

#stopped?Boolean

Returns:

  • (Boolean)


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

def stopped?
  @status != RUNNING
end