kube_wrapper 0.1.1 → 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/kube_wrapper/colors.rb +8 -1
- data/lib/kube_wrapper/runner.rb +26 -4
- data/lib/kube_wrapper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3eb2620cf4fb1a2c49a85399f0c9d2d1a5ce42c1fc76994769aee9ee7b1a3aad
|
4
|
+
data.tar.gz: 8b4dc4280e51f8fc988f47241f346bdf71fab1785863de3a0bd5778de2aea734
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fc3bee2c6c0bf12ed4d02c802b8b8bc3e7cd134c9b4d0dfc79b776d37cde8bdba14c24aa9906c5a601d61237fbf7d5d799a7fe9b30eaccc8f3fedd874a9becf
|
7
|
+
data.tar.gz: 153082642f0ffdea6f6195d04b97d0f21c724bad46148981a67bb313bf9f60b4d02a8ab1d8f4f89db5e0748b7a87dfb1046b77e20d02e39fe51465f0f80f04a6
|
data/Gemfile.lock
CHANGED
data/lib/kube_wrapper/colors.rb
CHANGED
@@ -4,8 +4,9 @@ module KubeWrapper
|
|
4
4
|
# Colors handles printing colored text to output
|
5
5
|
module Colors
|
6
6
|
COLORS = {
|
7
|
+
cyan: "\e[36m",
|
7
8
|
red: "\e[31m",
|
8
|
-
|
9
|
+
yellow: "\e[33m"
|
9
10
|
}.freeze
|
10
11
|
|
11
12
|
def print_cyan(text)
|
@@ -16,6 +17,12 @@ module KubeWrapper
|
|
16
17
|
print_color(text, COLORS[:red])
|
17
18
|
end
|
18
19
|
|
20
|
+
def print_yellow(text)
|
21
|
+
print_color(text, COLORS[:yellow])
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
19
26
|
def print_color(text, color)
|
20
27
|
@io_out.print "#{color}#{text}\e[0m"
|
21
28
|
end
|
data/lib/kube_wrapper/runner.rb
CHANGED
@@ -22,15 +22,22 @@ module KubeWrapper
|
|
22
22
|
clear: {
|
23
23
|
cmds: %w[cl clear],
|
24
24
|
blurb: 'Clears the screen'
|
25
|
+
},
|
26
|
+
set_context: {
|
27
|
+
cmds: ['set-c', '-c'],
|
28
|
+
blurb: <<~DESC
|
29
|
+
Changes kubernetes context. Pass nothing to print all available contexts
|
30
|
+
DESC
|
25
31
|
}
|
26
32
|
}.freeze
|
27
33
|
|
28
|
-
attr_reader :namespace
|
34
|
+
attr_reader :context, :namespace
|
29
35
|
|
30
36
|
def initialize(io_in = STDIN, io_out = STDOUT)
|
31
37
|
@io_in = io_in
|
32
38
|
@io_out = io_out
|
33
39
|
@namespace = 'default'
|
40
|
+
@context = `kubectl config current-context`.chomp
|
34
41
|
@callbacks = {}
|
35
42
|
end
|
36
43
|
|
@@ -64,23 +71,38 @@ module KubeWrapper
|
|
64
71
|
exit!
|
65
72
|
end
|
66
73
|
|
74
|
+
def update_context!(context)
|
75
|
+
if context.nil? || context.empty?
|
76
|
+
puts `kubectl config get-contexts`
|
77
|
+
return
|
78
|
+
end
|
79
|
+
|
80
|
+
context = Shellwords.escape(context)
|
81
|
+
result = `kubectl config use-context #{context}`
|
82
|
+
return if result.empty?
|
83
|
+
|
84
|
+
@io_out.puts "Context set to #{context}"
|
85
|
+
@context = context
|
86
|
+
end
|
87
|
+
|
67
88
|
def update_namespace!(namespace)
|
68
89
|
@namespace = namespace || 'default'
|
69
90
|
@io_out.puts "Namespace set to #{@namespace}"
|
70
91
|
end
|
71
92
|
|
72
|
-
def handle_input(input)
|
93
|
+
def handle_input(input) # rubocop:disable Metrics/AbcSize
|
73
94
|
case input.first
|
74
95
|
when *COMMANDS[:help][:cmds] then print_help
|
75
96
|
when *COMMANDS[:set_namespace][:cmds] then update_namespace!(input[1])
|
76
|
-
when *COMMANDS[:clear][:cmds] then print "\e[2J\e[f"
|
97
|
+
when *COMMANDS[:clear][:cmds] then @io_out.print "\e[2J\e[f"
|
98
|
+
when *COMMANDS[:set_context][:cmds] then update_context!(input[1])
|
77
99
|
else
|
78
100
|
@io_out.puts `kubectl -n #{namespace} #{Shellwords.shelljoin(input)}`
|
79
101
|
end
|
80
|
-
nil
|
81
102
|
end
|
82
103
|
|
83
104
|
def run
|
105
|
+
print_yellow "(#{context}) "
|
84
106
|
print_cyan "kubectl -n #{namespace} "
|
85
107
|
input = fetch_input
|
86
108
|
handle_input(input)
|
data/lib/kube_wrapper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kube_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Blues
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|