ranch-hand 0.4.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Changelog.md +4 -0
- data/README.md +16 -1
- data/bin/ranch-hand +14 -5
- data/doc/ranch-hand-demo.gif +0 -0
- data/lib/ranch_hand.rb +1 -0
- data/lib/ranch_hand/base.rb +6 -0
- data/lib/ranch_hand/commands.rb +1 -1
- data/lib/ranch_hand/config.rb +45 -0
- data/lib/ranch_hand/kube_ctl.rb +20 -11
- data/lib/ranch_hand/version.rb +1 -1
- data/ranch-hand.gemspec +7 -5
- metadata +16 -17
- data/Gemfile.lock +0 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 739b914a9a3aaa61cbd1ea414310158a5de894f02f93028c6c6927d3dcf4d567
|
4
|
+
data.tar.gz: 0166cfe7b29ad795d8f8ee3e0bef4a91bb3fce4e55e2a662ab24e7cf06474596
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0608be5112035aa5f4ca5e9e7ce1fc570763f485d688541de6c9095bcd3345cf0ce69378c820f60b782f0051b88322e4f7c052960f75db9c18ddffd3be44dc8
|
7
|
+
data.tar.gz: 957785da2e00ac1fb0834a9cb9cec97a6ed7628d1c0ad02e458ab1da3fdf76625801b733c1d4439a58ab8d1437d7ab6b3ce80ad09978a4d79417e1e39ff86f72
|
data/.gitignore
CHANGED
data/Changelog.md
ADDED
data/README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# RanchHand
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/ranch-hand.svg)](https://badge.fury.io/rb/ranch-hand)
|
4
|
+
|
5
|
+
Provides a simple interface on top the Rancher CLI and the Kubectl commands to make running commands in pods easier.
|
4
6
|
This is particularily useful when using Kubernetes in a development environment.
|
5
7
|
|
8
|
+
![ranch-hand demo](https://github.com/peregrinator/ranch-hand/raw/main/doc/ranch-hand-demo.gif "Ranch-hand Demo")
|
9
|
+
|
6
10
|
## Installation
|
7
11
|
|
8
12
|
Add this line to your application's Gemfile:
|
@@ -19,6 +23,17 @@ Or install it yourself as:
|
|
19
23
|
|
20
24
|
$ gem install ranch-hand
|
21
25
|
|
26
|
+
## Setup
|
27
|
+
|
28
|
+
Once ranch-hand is installed, run `ranch-hand setup` from the command line. This will create the necessary files in `~/.ranch-hand`.
|
29
|
+
|
30
|
+
#### Project setup
|
31
|
+
|
32
|
+
Project setup is optional. You can create a set of default values for certain flags by running `ranch-hand init` in any directory. When ranch-hand is run from a directory it will use the values in the `.ranch-hand` file if it is present.
|
33
|
+
|
34
|
+
Normally you might run the following command: `ranch-hand -n my-namespace -g -p my-project -c /bin/bash`
|
35
|
+
Using `ranch-hand init` you can set the namespace, grouping flag and pod name as defaults, and instead just run: `ranch-hand -c /bin/bash`.
|
36
|
+
|
22
37
|
## Usage
|
23
38
|
|
24
39
|
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.
|
data/bin/ranch-hand
CHANGED
@@ -14,7 +14,7 @@ module RanchHandCLI
|
|
14
14
|
version RanchHand::VERSION
|
15
15
|
|
16
16
|
subcommand_option_handling :normal
|
17
|
-
arguments :
|
17
|
+
arguments :loose
|
18
18
|
|
19
19
|
desc 'Sets up ranch hand'
|
20
20
|
command :setup do |c|
|
@@ -23,19 +23,28 @@ module RanchHandCLI
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
desc 'Initializes ranch hand for project'
|
27
|
+
command :init do |c|
|
28
|
+
c.action do |global_options, command_options, args|
|
29
|
+
RanchHand::Base.init
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
26
33
|
desc 'Execs into a running container'
|
27
34
|
command :exec do |c|
|
28
|
-
|
35
|
+
config = RanchHand::Config.load
|
36
|
+
|
37
|
+
c.switch [:g, :group], negatable: true, default_value: config[:group] || false, desc: "Group pods returned so that there is only one from each deployment, --no-group can be used to override project config as needed."
|
29
38
|
c.switch [:rm, :remove], negatable: false, desc: "Used to indicated that you want to remove a previously saved command."
|
30
39
|
c.switch [:r, :repeat], negatable: false, desc: "Repeat the last command ran (against the same pod)."
|
31
40
|
|
32
41
|
c.flag [:c, :command], desc: "Command to run once (not permanently stored)"
|
33
42
|
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"
|
43
|
+
c.flag [:n, :namespace], required: true, default_value: config[:namespace], desc: "Namespace against which to retreive pods and run command"
|
44
|
+
c.flag [:p, :pod], default_value: config[: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
45
|
|
37
46
|
c.action do |global_options, command_options, args|
|
38
|
-
RanchHand::KubeCtl.new.exec(command_options)
|
47
|
+
RanchHand::KubeCtl.new.exec(args: args, cmd_options: command_options)
|
39
48
|
end
|
40
49
|
end
|
41
50
|
|
Binary file
|
data/lib/ranch_hand.rb
CHANGED
data/lib/ranch_hand/base.rb
CHANGED
@@ -6,5 +6,11 @@ module RanchHand
|
|
6
6
|
File.new(RanchHand::STORE_FILE, 'w+', 0640)
|
7
7
|
RanchHand::Logger.info("complete")
|
8
8
|
end
|
9
|
+
|
10
|
+
def self.init
|
11
|
+
RanchHand::Logger.info("initializing ranch-hand for project")
|
12
|
+
RanchHand::Config.create
|
13
|
+
RanchHand::Logger.info("initialization complete")
|
14
|
+
end
|
9
15
|
end
|
10
16
|
end
|
data/lib/ranch_hand/commands.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
module RanchHand
|
2
|
+
class Config
|
3
|
+
extend RanchHand::Commands
|
4
|
+
|
5
|
+
def self.create
|
6
|
+
save(generate_config)
|
7
|
+
RanchHand::Logger.info("Config file saved to #{project_config_path}")
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.load
|
11
|
+
begin
|
12
|
+
YAML.load_file(project_config_path)
|
13
|
+
rescue Errno::ENOENT
|
14
|
+
{}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def self.generate_config
|
21
|
+
namespace = prompt.ask('Namespace:')
|
22
|
+
group = prompt.ask('Use group command by default? (Y/n):')
|
23
|
+
group = %w(n N).include?(group) ? false : true
|
24
|
+
pod = prompt.ask('Pod name:')
|
25
|
+
|
26
|
+
{
|
27
|
+
group: group,
|
28
|
+
namespace: namespace,
|
29
|
+
pod: pod
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.save(config)
|
34
|
+
# File.new(project_config_path, 'w+', 0640)
|
35
|
+
|
36
|
+
File.open(project_config_path, 'w', 0640) do |f|
|
37
|
+
f.write(config.to_yaml)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.project_config_path
|
42
|
+
File.join(Dir.pwd, ".ranch-hand")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/ranch_hand/kube_ctl.rb
CHANGED
@@ -2,23 +2,25 @@ module RanchHand
|
|
2
2
|
class KubeCtl
|
3
3
|
include RanchHand::Commands
|
4
4
|
|
5
|
-
def exec(
|
6
|
-
|
5
|
+
def exec(args: [], cmd_options: {})
|
6
|
+
args = Array(args)
|
7
|
+
|
8
|
+
namespace = cmd_options.delete(:namespace)
|
7
9
|
|
8
|
-
if
|
10
|
+
if cmd_options[:remove]
|
9
11
|
remove_command(namespace)
|
10
|
-
elsif
|
12
|
+
elsif cmd_options[:repeat]
|
11
13
|
repeat_command(namespace)
|
12
|
-
elsif
|
13
|
-
pod = select_pod(namespace,
|
14
|
-
run_command(namespace, pod,
|
14
|
+
elsif cmd_options[:command]
|
15
|
+
pod = select_pod(namespace, cmd_options)
|
16
|
+
run_command(namespace, pod, cmd_options[:command], args)
|
15
17
|
else
|
16
|
-
choose_command(namespace,
|
18
|
+
choose_command(namespace, cmd_options)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
def run_command(namespace, pod, cmd)
|
21
|
-
system("rancher kubectl -n #{namespace} exec -it #{pod} -- #{cmd}")
|
22
|
+
def run_command(namespace, pod, cmd, args=[])
|
23
|
+
system("rancher kubectl -n #{namespace} exec -it #{pod} -- #{cmd} #{args.join(' ')}".strip)
|
22
24
|
end
|
23
25
|
|
24
26
|
def choose_command(namespace, options={})
|
@@ -173,11 +175,18 @@ module RanchHand
|
|
173
175
|
|
174
176
|
def pods(namespace)
|
175
177
|
pods_cmd = "rancher kubectl -n #{namespace} get po"
|
176
|
-
command(printer: :null).run(pods_cmd).out.split("\n")[1..-1]
|
178
|
+
pods = command(printer: :null).run(pods_cmd).out.split("\n")[1..-1]&.map{|l| l.split(/\s+/)[0]}
|
179
|
+
|
180
|
+
pods || []
|
177
181
|
end
|
178
182
|
|
179
183
|
def storage
|
180
184
|
@storage ||= RanchHand::Storage.new
|
181
185
|
end
|
186
|
+
|
187
|
+
# def project_config
|
188
|
+
# project_config_file = File.join(Dir.pwd, ".ranch-hand")
|
189
|
+
# YAML.load_file(project_config_file) || {}
|
190
|
+
# end
|
182
191
|
end
|
183
192
|
end
|
data/lib/ranch_hand/version.rb
CHANGED
data/ranch-hand.gemspec
CHANGED
@@ -20,15 +20,17 @@ Gem::Specification.new do |spec|
|
|
20
20
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }.reject { |f| f.match(%r{.gem$}) }
|
21
21
|
end
|
22
22
|
spec.bindir = "bin"
|
23
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/ranch-hand}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
+
spec.required_ruby_version = '~> 3.0'
|
27
|
+
|
26
28
|
spec.add_development_dependency "bundler", "~> 2.0"
|
27
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
31
|
|
30
|
-
spec.add_runtime_dependency "gli", "~> 2.
|
31
|
-
spec.add_runtime_dependency "pry", "~> 0.
|
32
|
-
spec.add_runtime_dependency "tty-command", "~> 0.
|
33
|
-
spec.add_runtime_dependency "tty-prompt", "~> 0.
|
32
|
+
spec.add_runtime_dependency "gli", "~> 2.20"
|
33
|
+
spec.add_runtime_dependency "pry", "~> 0.14"
|
34
|
+
spec.add_runtime_dependency "tty-command", "~> 0.10"
|
35
|
+
spec.add_runtime_dependency "tty-prompt", "~> 0.23"
|
34
36
|
end
|
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.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peregrinator
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,63 +58,61 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '2.
|
61
|
+
version: '2.20'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '2.
|
68
|
+
version: '2.20'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: '0.14'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: '0.14'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: tty-command
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: '0.10'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: '0.10'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: tty-prompt
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
103
|
+
version: '0.23'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
110
|
+
version: '0.23'
|
111
111
|
description: ''
|
112
112
|
email:
|
113
113
|
- bob.burbach@gmail.com
|
114
114
|
executables:
|
115
|
-
- console
|
116
115
|
- ranch-hand
|
117
|
-
- setup
|
118
116
|
extensions: []
|
119
117
|
extra_rdoc_files: []
|
120
118
|
files:
|
@@ -122,17 +120,19 @@ files:
|
|
122
120
|
- ".rspec"
|
123
121
|
- ".travis.yml"
|
124
122
|
- CODE_OF_CONDUCT.md
|
123
|
+
- Changelog.md
|
125
124
|
- Gemfile
|
126
|
-
- Gemfile.lock
|
127
125
|
- LICENSE.txt
|
128
126
|
- README.md
|
129
127
|
- Rakefile
|
130
128
|
- bin/console
|
131
129
|
- bin/ranch-hand
|
132
130
|
- bin/setup
|
131
|
+
- doc/ranch-hand-demo.gif
|
133
132
|
- lib/ranch_hand.rb
|
134
133
|
- lib/ranch_hand/base.rb
|
135
134
|
- lib/ranch_hand/commands.rb
|
135
|
+
- lib/ranch_hand/config.rb
|
136
136
|
- lib/ranch_hand/constants.rb
|
137
137
|
- lib/ranch_hand/kube_ctl.rb
|
138
138
|
- lib/ranch_hand/logger.rb
|
@@ -149,17 +149,16 @@ require_paths:
|
|
149
149
|
- lib
|
150
150
|
required_ruby_version: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
|
-
- - "
|
152
|
+
- - "~>"
|
153
153
|
- !ruby/object:Gem::Version
|
154
|
-
version: '0'
|
154
|
+
version: '3.0'
|
155
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
|
-
|
162
|
-
rubygems_version: 2.7.6.2
|
161
|
+
rubygems_version: 3.2.3
|
163
162
|
signing_key:
|
164
163
|
specification_version: 4
|
165
164
|
summary: Provides an interface between the Rancher CLI and the Kubectl commands
|
data/Gemfile.lock
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
ranch-hand (0.3.0)
|
5
|
-
gli (~> 2.18)
|
6
|
-
pry (~> 0.12.2)
|
7
|
-
tty-command (~> 0.8.2)
|
8
|
-
tty-prompt (~> 0.18.1)
|
9
|
-
|
10
|
-
GEM
|
11
|
-
remote: https://rubygems.org/
|
12
|
-
specs:
|
13
|
-
coderay (1.1.2)
|
14
|
-
diff-lcs (1.3)
|
15
|
-
equatable (0.5.0)
|
16
|
-
gli (2.18.0)
|
17
|
-
method_source (0.9.2)
|
18
|
-
necromancer (0.4.0)
|
19
|
-
pastel (0.7.2)
|
20
|
-
equatable (~> 0.5.0)
|
21
|
-
tty-color (~> 0.4.0)
|
22
|
-
pry (0.12.2)
|
23
|
-
coderay (~> 1.1.0)
|
24
|
-
method_source (~> 0.9.0)
|
25
|
-
rake (10.5.0)
|
26
|
-
rspec (3.8.0)
|
27
|
-
rspec-core (~> 3.8.0)
|
28
|
-
rspec-expectations (~> 3.8.0)
|
29
|
-
rspec-mocks (~> 3.8.0)
|
30
|
-
rspec-core (3.8.0)
|
31
|
-
rspec-support (~> 3.8.0)
|
32
|
-
rspec-expectations (3.8.2)
|
33
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
-
rspec-support (~> 3.8.0)
|
35
|
-
rspec-mocks (3.8.0)
|
36
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.8.0)
|
38
|
-
rspec-support (3.8.0)
|
39
|
-
timers (4.3.0)
|
40
|
-
tty-color (0.4.3)
|
41
|
-
tty-command (0.8.2)
|
42
|
-
pastel (~> 0.7.0)
|
43
|
-
tty-cursor (0.6.1)
|
44
|
-
tty-prompt (0.18.1)
|
45
|
-
necromancer (~> 0.4.0)
|
46
|
-
pastel (~> 0.7.0)
|
47
|
-
timers (~> 4.0)
|
48
|
-
tty-cursor (~> 0.6.0)
|
49
|
-
tty-reader (~> 0.5.0)
|
50
|
-
tty-reader (0.5.0)
|
51
|
-
tty-cursor (~> 0.6.0)
|
52
|
-
tty-screen (~> 0.6.4)
|
53
|
-
wisper (~> 2.0.0)
|
54
|
-
tty-screen (0.6.5)
|
55
|
-
wisper (2.0.0)
|
56
|
-
|
57
|
-
PLATFORMS
|
58
|
-
ruby
|
59
|
-
|
60
|
-
DEPENDENCIES
|
61
|
-
bundler (~> 2.0)
|
62
|
-
rake (~> 10.0)
|
63
|
-
ranch-hand!
|
64
|
-
rspec (~> 3.0)
|
65
|
-
|
66
|
-
BUNDLED WITH
|
67
|
-
2.0.1
|