Class: Eclair::K8sItem

Inherits:
Item
  • Object
show all
Defined in:
lib/eclair/providers/k8s/k8s_item.rb

Instance Attribute Summary collapse

Attributes inherited from Item

#selected, #visible

Instance Method Summary collapse

Methods inherited from Item

#select, #title, #toggle_select

Methods included from ConfigHelper

#config

Constructor Details

#initialize(pod) ⇒ K8sItem

Returns a new instance of K8sItem.



10
11
12
13
# File 'lib/eclair/providers/k8s/k8s_item.rb', line 10

def initialize pod
  super()
  @pod = pod
end

Instance Attribute Details

#podObject (readonly)

Returns the value of attribute pod.



8
9
10
# File 'lib/eclair/providers/k8s/k8s_item.rb', line 8

def pod
  @pod
end

Instance Method Details

#colorObject



19
20
21
22
23
24
25
26
27
# File 'lib/eclair/providers/k8s/k8s_item.rb', line 19

def color
  if @selected
    [Curses::COLOR_YELLOW, -1, Curses::A_BOLD]
  elsif !connectable?
    [Curses::COLOR_BLACK, -1, Curses::A_BOLD]
  else
    [Curses::COLOR_WHITE, -1]
  end
end

#commandObject



33
34
35
# File 'lib/eclair/providers/k8s/k8s_item.rb', line 33

def command
  "kubectl exec --namespace #{namespace} -ti #{name} #{exec_command}"
end

#connectable?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/eclair/providers/k8s/k8s_item.rb', line 56

def connectable?
  status == "running"
end

#exec_commandObject



29
30
31
# File 'lib/eclair/providers/k8s/k8s_item.rb', line 29

def exec_command
  @pod["metadata"]["labels"]["eclair_exec_command"] || "/bin/sh"
end

#headerObject



37
38
39
40
41
42
# File 'lib/eclair/providers/k8s/k8s_item.rb', line 37

def header
  "  \#{name}\n  launched at \#{launch_time.to_time}\n  EOS\nend\n"

#idObject



15
16
17
# File 'lib/eclair/providers/k8s/k8s_item.rb', line 15

def id
  @pod["metadata"]["uid"]
end

#labelObject



44
45
46
# File 'lib/eclair/providers/k8s/k8s_item.rb', line 44

def label
  " - #{name} [#{launched_at}]"
end

#nameObject



52
53
54
# File 'lib/eclair/providers/k8s/k8s_item.rb', line 52

def name
  @pod["metadata"]["name"]
end

#namespaceObject



48
49
50
# File 'lib/eclair/providers/k8s/k8s_item.rb', line 48

def namespace
  @pod["metadata"]["namespace"]
end

#search_keyObject



60
61
62
# File 'lib/eclair/providers/k8s/k8s_item.rb', line 60

def search_key
  name.downcase
end