kubert 0.0.1.pre.dev4 → 0.0.1.pre.dev5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -4
- data/kubert.gemspec +1 -0
- data/lib/kubert/cli.rb +33 -1
- data/lib/kubert/deployment.rb +23 -0
- data/lib/kubert/pods.rb +12 -7
- data/lib/kubert/version.rb +1 -1
- data/lib/kubert.rb +20 -5
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 502c0c47c579535db10030b1cfb5dabf820d860c
|
4
|
+
data.tar.gz: e182069a2f38088918f467bfa8b64f5f0588ed13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ad31da5c06bc00a311088ce584219ea1565fa7cce4b08f478a6fa778e9d7499224e56e6738c4dab54d1e24c2b6827f6eab37f43a89b6b7fd1fd0d3b7c40afb4
|
7
|
+
data.tar.gz: 7b1ad5f9a64ba36c7b5bf5360c8f16187926ff10bbca4787e078f8722642517c2535c632727d169a11710a4c514bb58389c8b92b40e0cc3de1aa57d6f6744402
|
data/README.md
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# Kubert
|
2
2
|
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kubert`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
3
|
## Installation
|
8
4
|
|
9
5
|
Add this line to your application's Gemfile:
|
data/kubert.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
spec.add_runtime_dependency 'thor', '~> 0.19'
|
32
32
|
spec.add_runtime_dependency 'kubeclient', '~> 2'
|
33
|
+
spec.add_runtime_dependency 'ky', '~> 0.5'
|
33
34
|
spec.add_development_dependency 'pry', '~> 0.10'
|
34
35
|
spec.add_development_dependency "bundler", "~> 1.13"
|
35
36
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/kubert/cli.rb
CHANGED
@@ -9,9 +9,41 @@ module Kubert
|
|
9
9
|
puts Pods.list(pod_type, status)
|
10
10
|
end
|
11
11
|
|
12
|
+
desc "context", "Print current kubectl current context"
|
13
|
+
def context
|
14
|
+
puts Kubert.kube_config.contexts.select {|c| Kubert.kube_config.context.api_endpoint.match(c) }
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "sandbox", "Connect to a Rails console in sandbox that will wrap session in DB transaction and rollback when done"
|
18
|
+
def sandbox
|
19
|
+
execute("rails", "console", "--sandbox")
|
20
|
+
end
|
21
|
+
|
12
22
|
desc "console", "Connect to a Rails console on a console pod"
|
13
23
|
def console
|
14
|
-
|
24
|
+
execute("rails", "console")
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "execute command", "Connect to a pod run the specified command (with bundle exec prefix)"
|
28
|
+
def execute(*command)
|
29
|
+
Pods.execute(command)
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "deploy", "Perform a deployment"
|
33
|
+
def deploy
|
34
|
+
Deployment.perform
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "rollback", "Connect to a pod run the specified command (with bundle exec prefix)"
|
38
|
+
def rollback
|
39
|
+
Deployment.rollback
|
40
|
+
end
|
41
|
+
|
42
|
+
Kubert.contexts.each do |context_name, context_endpoint|
|
43
|
+
desc context_name, "Use kubernetes #{context_endpoint} for kubectl commands"
|
44
|
+
define_method(context_name) do
|
45
|
+
puts `kubectl config use-context #{context_endpoint}`
|
46
|
+
end
|
15
47
|
end
|
16
48
|
|
17
49
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Kubert
|
2
|
+
class Deployment
|
3
|
+
def self.perform
|
4
|
+
new.perform
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.rollback
|
8
|
+
new.rollback
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :project_name, :deployments
|
12
|
+
def initialize(project_name= Kubert.configuration[:project_name])
|
13
|
+
@project_name = project_name
|
14
|
+
@deployments = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def rollback
|
18
|
+
end
|
19
|
+
|
20
|
+
def perform
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/kubert/pods.rb
CHANGED
@@ -8,14 +8,18 @@ module Kubert
|
|
8
8
|
new.console
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
def self.execute(command)
|
12
|
+
new.execute(command)
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :project_name, :pods
|
16
|
+
def initialize(project_name= Kubert.configuration[:project_name])
|
17
|
+
@project_name = project_name
|
14
18
|
@pods = []
|
15
19
|
end
|
16
20
|
|
17
21
|
def all(pod_type)
|
18
|
-
@pods = Kubert.client.get_pods(label_selector: "app=#{
|
22
|
+
@pods = Kubert.client.get_pods(label_selector: "app=#{project_name}-#{pod_type}")
|
19
23
|
self
|
20
24
|
end
|
21
25
|
|
@@ -28,14 +32,15 @@ module Kubert
|
|
28
32
|
pods.map(&:metadata).map(&:name)
|
29
33
|
end
|
30
34
|
|
31
|
-
def
|
35
|
+
def execute(command)
|
32
36
|
pod = all('console').status(:running).pods.sample
|
37
|
+
exec_command = "kubectl exec -n #{pod.metadata.namespace} #{pod.metadata.name} -it bundle exec #{command.join(' ')}"
|
38
|
+
puts "Executing command: \n#{exec_command}"
|
33
39
|
Open3.popen3("bash") do
|
34
|
-
exec
|
40
|
+
exec exec_command
|
35
41
|
end
|
36
42
|
puts "THIS WILL NEVER EXECUTE BECAUSE OF EXEC ABOVE"
|
37
43
|
end
|
38
44
|
|
39
|
-
|
40
45
|
end
|
41
46
|
end
|
data/lib/kubert/version.rb
CHANGED
data/lib/kubert.rb
CHANGED
@@ -1,17 +1,32 @@
|
|
1
1
|
require 'kubeclient'
|
2
|
+
require 'ky'
|
2
3
|
require 'open3'
|
3
4
|
require_relative "kubert/pods"
|
4
5
|
|
5
6
|
module Kubert
|
7
|
+
def self.kube_config
|
8
|
+
@kube_config ||= Kubeclient::Config.read(File.expand_path('~/.kube/config'))
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.contexts
|
12
|
+
configuration[:contexts] || []
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configuration
|
16
|
+
@config ||= begin
|
17
|
+
config = KY::Configuration.new
|
18
|
+
(config[:kubert] || {}).merge(project_name: config[:project_name])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
6
22
|
def self.client
|
7
23
|
@client ||= begin
|
8
|
-
kube_client_config = Kubeclient::Config.read(File.expand_path('~/.kube/config'))
|
9
24
|
Kubeclient::Client.new(
|
10
|
-
|
11
|
-
|
25
|
+
kube_config.context.api_endpoint,
|
26
|
+
kube_config.context.api_version,
|
12
27
|
{
|
13
|
-
ssl_options:
|
14
|
-
auth_options:
|
28
|
+
ssl_options: kube_config.context.ssl_options,
|
29
|
+
auth_options: kube_config.context.auth_options
|
15
30
|
}
|
16
31
|
)
|
17
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.pre.
|
4
|
+
version: 0.0.1.pre.dev5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Glusman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ky
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.5'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: pry
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,6 +131,7 @@ files:
|
|
117
131
|
- kubert.gemspec
|
118
132
|
- lib/kubert.rb
|
119
133
|
- lib/kubert/cli.rb
|
134
|
+
- lib/kubert/deployment.rb
|
120
135
|
- lib/kubert/pods.rb
|
121
136
|
- lib/kubert/version.rb
|
122
137
|
homepage:
|