ranch-hand 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +4 -5
- data/bin/ranch-hand +12 -4
- data/lib/ranch_hand/kube_ctl.rb +63 -13
- data/lib/ranch_hand/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: 28e355a00dd066ac8d0b0270f59a2a97c25bd28e69066a289aec029db9661fa9
|
4
|
+
data.tar.gz: 56a686da7e0be9a823b75fd7d349d75b7d7cd8c497106d153fe3018f6921ce87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7639b1029f2cfb0a415794dd22ca8af87f38a20be8efdb757373a0218ae2fbdbf50f13365985afdd55a0e44fdcce72e6cf40c260d33823f1dd8dafe0ece392b
|
7
|
+
data.tar.gz: be9d54eed465ab6b3bb9b09f845ddb1d514f701076cf9d1f4b601b07fadfad36e2672c74d3b816380ab311ec4d619825ef4b966ebd657d7f4293f92900bd24f8
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# RanchHand
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Provides an interface between the Rancher CLI and the Kubectl commands to make running commands in pods easier.
|
4
|
+
This is particularily useful when using Kubernetes in a development environment.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -22,7 +21,7 @@ Or install it yourself as:
|
|
22
21
|
|
23
22
|
## Usage
|
24
23
|
|
25
|
-
|
24
|
+
RanchHand makes use of the [GLI](https://github.com/davetron5000/gli) (Git Like Interface) gem to create a CLI with features similar to the Git CLI. Run `ranch-hand help` or `ranch-hand command help` for usage information.
|
26
25
|
|
27
26
|
## Development
|
28
27
|
|
@@ -40,4 +39,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
40
39
|
|
41
40
|
## Code of Conduct
|
42
41
|
|
43
|
-
Everyone interacting in the
|
42
|
+
Everyone interacting in the RanchHand project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/peregrinator/ranch-hand/blob/master/CODE_OF_CONDUCT.md).
|
data/bin/ranch-hand
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
module RanchHandCLI
|
3
3
|
require 'gli'
|
4
4
|
require 'ranch_hand'
|
5
|
+
require 'pry'
|
5
6
|
|
6
7
|
include GLI::App
|
7
8
|
# our cli is wrapped in a module (to not pollute the global namespace with GLI methods),
|
@@ -23,11 +24,18 @@ module RanchHandCLI
|
|
23
24
|
end
|
24
25
|
|
25
26
|
desc 'Execs into a running container'
|
26
|
-
arg_name 'namespace'
|
27
27
|
command :exec do |c|
|
28
|
-
c.switch [:
|
29
|
-
c.
|
30
|
-
|
28
|
+
c.switch [:g, :group], negatable: false, desc: "Group pods returned so that there is only one from each deployment."
|
29
|
+
c.switch [:rm, :remove], negatable: false, desc: "Used to indicated that you want to remove a previously saved command."
|
30
|
+
c.switch [:r, :repeat], negatable: false, desc: "Repeat the last command ran (against the same pod)."
|
31
|
+
|
32
|
+
c.flag [:c, :command], desc: "Command to run once (not permanently stored)"
|
33
|
+
c.flag [:f, :filter], desc: "Filter pods returned to those that contain the string provided (negative matches supported). Examples: '-f nginx', '-f -apache'"
|
34
|
+
c.flag [:n, :namespace], required: true, desc: "Namespace against which to retreive pods and run command"
|
35
|
+
c.flag [:p, :pod], desc: "Run command in a specific pod. If used with -g only the pod name can be specified and the command will be run against the first in the group"
|
36
|
+
|
37
|
+
c.action do |global_options, command_options, args|
|
38
|
+
RanchHand::KubeCtl.new.exec(command_options)
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
data/lib/ranch_hand/kube_ctl.rb
CHANGED
@@ -2,19 +2,30 @@ module RanchHand
|
|
2
2
|
class KubeCtl
|
3
3
|
include RanchHand::Commands
|
4
4
|
|
5
|
-
def exec(
|
6
|
-
|
5
|
+
def exec(options={})
|
6
|
+
namespace = options.delete(:namespace)
|
7
|
+
|
8
|
+
if options[:remove]
|
7
9
|
remove_command(namespace)
|
10
|
+
elsif options[:repeat]
|
11
|
+
repeat_command(namespace)
|
12
|
+
elsif options[:command]
|
13
|
+
pod = select_pod(namespace, options)
|
14
|
+
run_command(namespace, pod, options[:command])
|
8
15
|
else
|
9
|
-
|
16
|
+
choose_command(namespace, options)
|
10
17
|
end
|
11
18
|
end
|
12
19
|
|
13
|
-
def run_command(namespace)
|
14
|
-
pod
|
20
|
+
def run_command(namespace, pod, cmd)
|
21
|
+
system("rancher kubectl -n #{namespace} exec -it #{pod} -- #{cmd}")
|
22
|
+
end
|
23
|
+
|
24
|
+
def choose_command(namespace, options={})
|
25
|
+
pod = select_pod(namespace, options)
|
15
26
|
type, cmd = select_command(namespace, pod)
|
16
27
|
|
17
|
-
|
28
|
+
run_command(namespace, pod, cmd)
|
18
29
|
end
|
19
30
|
|
20
31
|
def remove_command(namespace)
|
@@ -33,13 +44,46 @@ module RanchHand
|
|
33
44
|
storage.set(storage_key, storage.get(storage_key) - Array(cmd))
|
34
45
|
end
|
35
46
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
).to_i + 1
|
47
|
+
def repeat_command(namespace)
|
48
|
+
run_command(
|
49
|
+
namespace,
|
50
|
+
storage.get("exec:#{namespace}:latest:pod"),
|
51
|
+
storage.get("exec:#{namespace}:latest:cmd")
|
42
52
|
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def select_pod(namespace, options={})
|
56
|
+
pods = pods(namespace)
|
57
|
+
|
58
|
+
if options[:filter]
|
59
|
+
if options[:filter].start_with?('-')
|
60
|
+
pods = pods.reject{|p| p.match?(/#{options[:filter][1..-1]}/)}
|
61
|
+
else
|
62
|
+
pods = pods.select{|p| p.match?(/#{options[:filter]}/)}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
prompt.error("No pods matching filter: '#{options[:filter]}'") and exit if pods.empty?
|
66
|
+
|
67
|
+
if options[:group]
|
68
|
+
pods = pods.group_by{|p| pod_name(p)}.map{|name, pods| pods.first}
|
69
|
+
end
|
70
|
+
|
71
|
+
if options[:pod]
|
72
|
+
if options[:group]
|
73
|
+
pod = pods.select{|p| p.match?(/#{options[:pod]}/)}.first
|
74
|
+
else
|
75
|
+
pod = pods.select{|p| options[:pod] == p}.first
|
76
|
+
end
|
77
|
+
|
78
|
+
prompt.error("No pods match: '#{options[:pod]}'. Did you mean to use the group (-g) switch?") and exit unless pod
|
79
|
+
else
|
80
|
+
pod = prompt.enum_select("Which pod?", pods, per_page: 10,
|
81
|
+
default: pods.index(
|
82
|
+
storage.get("exec:#{namespace}:latest:pod")
|
83
|
+
).to_i + 1
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
43
87
|
storage.set("exec:#{namespace}:latest:pod", pod)
|
44
88
|
pod
|
45
89
|
end
|
@@ -63,6 +107,8 @@ module RanchHand
|
|
63
107
|
unless options[:remove]
|
64
108
|
if cmd == "Add command"
|
65
109
|
type, cmd = add_command(namespace, pod)
|
110
|
+
elsif cmd == "Run once"
|
111
|
+
type, cmd = nil, run_once(namespace, pod)
|
66
112
|
end
|
67
113
|
|
68
114
|
# save cmd as latest
|
@@ -90,6 +136,10 @@ module RanchHand
|
|
90
136
|
[type, cmd]
|
91
137
|
end
|
92
138
|
|
139
|
+
def run_once(namespace, pod)
|
140
|
+
prompt.ask('Command:')
|
141
|
+
end
|
142
|
+
|
93
143
|
private
|
94
144
|
|
95
145
|
def all_commands(namespace, pod, options)
|
@@ -101,7 +151,7 @@ module RanchHand
|
|
101
151
|
if options[:remove]
|
102
152
|
{base: []}
|
103
153
|
else
|
104
|
-
{base: ["Add command"]}
|
154
|
+
{base: ["Add command", "Run once"]}
|
105
155
|
end
|
106
156
|
end
|
107
157
|
|
data/lib/ranch_hand/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ranch-hand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peregrinator
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|