kbe 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/kbe.rb +35 -14
- data/lib/kbe/cli/delete_command.rb +21 -0
- data/lib/kbe/cli/enter_command.rb +2 -2
- data/lib/kbe/cli/list_command.rb +4 -2
- data/lib/kbe/cli/root_command.rb +3 -0
- data/lib/kbe/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6305d833ab3cf7f17e9e62a7a60c9cb767e19220f01cca2e2c24e5bd08a60cab
|
4
|
+
data.tar.gz: 21132300f9c022d1db52d8432aec27898ac4fd452bbd53a4b857b7abf78efd75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0b9ac3700f873bec682f6d2d4111837b9242c55cb96b9dd505673673aaf45b0cc1de111ff783e90cdc8623977891f3e4e216a07d7dbd53aec701cf1dd645d19
|
7
|
+
data.tar.gz: 8db51d7e138940dfe30e75ff11d681621bddc25c02af7956e67c5905b36f3311ede3bd710284803c18a60d0cc32f27e87853e5049be4173848abc117e8ad4b6d
|
data/Gemfile.lock
CHANGED
data/lib/kbe.rb
CHANGED
@@ -12,27 +12,48 @@ module KBE
|
|
12
12
|
exec cmd_string
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.pod_by(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
15
|
+
def self.pod_by(name_or_selector, only_running: true)
|
16
|
+
pods = if name_or_selector.match? "="
|
17
|
+
get_pods selector: name_or_selector, only_running: only_running
|
18
|
+
else
|
19
|
+
get_pods name: name_or_selector, only_running: only_running
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
22
|
+
if pods.empty?
|
23
|
+
["app", "job-name"].each do |selector_prefix|
|
24
|
+
magic_selector = "#{selector_prefix}=#{name_or_selector}"
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
pods = get_pods selector: magic_selector, only_running: only_running
|
27
|
+
break if pods.any?
|
28
|
+
end
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
+
if pods.size == 1
|
32
|
+
return pods.first
|
33
|
+
elsif pods.size > 1
|
34
|
+
STDERR.puts "too many pods found:"
|
35
|
+
STDERR.p pods
|
36
|
+
else
|
37
|
+
STDERR.puts "no pods found."
|
31
38
|
end
|
32
39
|
|
33
|
-
STDERR.puts "no pod found"
|
34
40
|
exit 1
|
35
41
|
end
|
42
|
+
|
43
|
+
def self.get_pods(selector:nil, name:nil, only_running: true)
|
44
|
+
parts = []
|
45
|
+
parts << "kubectl get pods --no-headers -o custom-columns=':metadata.name'"
|
46
|
+
if selector
|
47
|
+
parts << "--field-selector=status.phase=Running" if only_running
|
48
|
+
parts << "--selector=#{selector}"
|
49
|
+
else
|
50
|
+
parts << name
|
51
|
+
end
|
52
|
+
|
53
|
+
cmd = parts.join " "
|
54
|
+
# dev/null supresses the "pod not found" by name
|
55
|
+
`#{cmd} 2>/dev/null`.split("\n")
|
56
|
+
end
|
36
57
|
end
|
37
58
|
|
38
59
|
require_relative 'kbe/version'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module KBE
|
5
|
+
module CLI
|
6
|
+
class DeleteCommand < Clamp::Command
|
7
|
+
option ['-h', '--help'], :flag, "help" do
|
8
|
+
puts "kbe delete selector"
|
9
|
+
exit 0
|
10
|
+
end
|
11
|
+
|
12
|
+
parameter "SELECTOR_OR_POD", "selector or pod name"
|
13
|
+
|
14
|
+
def execute
|
15
|
+
pod = KBE.pod_by(selector_or_pod, only_running: false)
|
16
|
+
KBE.kubectl "delete pod #{pod}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -13,12 +13,12 @@ module KBE
|
|
13
13
|
|
14
14
|
option ['-c', '--container'], 'CONTAINER', 'container', default: :first
|
15
15
|
|
16
|
-
parameter "
|
16
|
+
parameter "SELECTOR_OR_POD", "selector or pod name"
|
17
17
|
parameter "[CMD] ...", "cmd"
|
18
18
|
|
19
19
|
def execute
|
20
20
|
cmd_list = ["sh"] unless cmd_list
|
21
|
-
pod = KBE.pod_by
|
21
|
+
pod = KBE.pod_by selector_or_pod
|
22
22
|
|
23
23
|
args = []
|
24
24
|
args << "exec -it #{pod}"
|
data/lib/kbe/cli/list_command.rb
CHANGED
@@ -10,10 +10,11 @@ module KBE
|
|
10
10
|
exit 0
|
11
11
|
end
|
12
12
|
|
13
|
-
parameter "[POD]", "pod"
|
13
|
+
parameter "[POD]", "list containers from pod", attribute_name: :selector
|
14
14
|
|
15
15
|
def execute
|
16
|
-
if
|
16
|
+
if selector
|
17
|
+
pod = KBE.pod_by(selector, only_running: false)
|
17
18
|
json = JSON.parse(`kubectl get pod #{pod} -o json`)
|
18
19
|
for container in json["spec"]["containers"]
|
19
20
|
puts container["name"]
|
@@ -21,6 +22,7 @@ module KBE
|
|
21
22
|
else
|
22
23
|
KBE.kubectl ["get pod"]
|
23
24
|
end
|
25
|
+
rescue JSON::ParserError
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
data/lib/kbe/cli/root_command.rb
CHANGED
@@ -3,6 +3,7 @@ require_relative "version_command"
|
|
3
3
|
require_relative "help_command"
|
4
4
|
require_relative "enter_command"
|
5
5
|
require_relative "list_command"
|
6
|
+
require_relative "delete_command"
|
6
7
|
|
7
8
|
module KBE
|
8
9
|
module CLI
|
@@ -15,6 +16,8 @@ module KBE
|
|
15
16
|
end
|
16
17
|
subcommand ["list"], "List pods", ListCommand
|
17
18
|
subcommand ["enter"], "Enter a container", EnterCommand
|
19
|
+
subcommand ["delete"], "Delete a pod", DeleteCommand
|
20
|
+
|
18
21
|
subcommand ["version"], "Show version information", VersionCommand
|
19
22
|
subcommand ["help"], "Show help", HelpCommand
|
20
23
|
|
data/lib/kbe/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kbe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matti Paksula
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- kbe.gemspec
|
111
111
|
- lib/kbe.rb
|
112
112
|
- lib/kbe/cli.rb
|
113
|
+
- lib/kbe/cli/delete_command.rb
|
113
114
|
- lib/kbe/cli/enter_command.rb
|
114
115
|
- lib/kbe/cli/help_command.rb
|
115
116
|
- lib/kbe/cli/list_command.rb
|