kubert 0.0.1.pre.dev6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df48773e44f09c65f555a75fe4303e33ad1c597c
4
- data.tar.gz: ba0e595e8f60e62f6b6f0340d7c9629430157108
3
+ metadata.gz: 13d3f33521c6405a0742f4ad72762bae8eb98039
4
+ data.tar.gz: f6063a35ffe1f8146b779f515f1646bc448286c4
5
5
  SHA512:
6
- metadata.gz: b2e861857520e53524f27dfd461e5d058e4ba4e7f011bc9945f1f3ef9a995f8e3493e2713a5a692480b6d4afdc4db6fb57b855cf20cfb6ec61fd5bf7cd527a26
7
- data.tar.gz: 969626a019d04a92f3a70f168f07ba8328cd565da3489afbdc7fea797ac5212a06d8b8e1c3e7b68e0ce7fc430d1b8147f1f9c9ac58e940623a6103f5776d92a1
6
+ metadata.gz: cad02b12eabe8d9bf7d6edac689ec48c91f6ebaaeef5da59a96624ac0a0071dd67165454419bd25fbd18dc631d87a4f0727bedd41e4ee2d2d04b3ed2acb2854d
7
+ data.tar.gz: 2c9545f878499dba963ef758ee5bcb4f56a6c0057d7901cbd87493d333d9b67f957923888484cdaa8fb641b6513393d252ff8c521fff6bb6b10414ab38022534
data/README.md CHANGED
@@ -1,37 +1,48 @@
1
- # Kubert
1
+ # Kubert - Your helpful kubernetes ruby terminal friend!
2
2
 
3
- ## Installation
3
+ ## The gem relies on a second gem, [ky](https://github.com/stellaservice/ky) which may be used independently
4
4
 
5
- Add this line to your application's Gemfile:
5
+ # Install gem via `gem install kubert` as usual. This will also install the ky gem, which handles configuration.
6
6
 
7
- ```ruby
8
- gem 'kubert'
9
- ```
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install kubert
18
-
19
- ## Usage
7
+ Kubert assumes your kubernetes config file lives in `~/.kube/config` and reads that to talk to the cluster.
20
8
 
21
- TODO: Write usage instructions here
9
+ If you don't intend to use KY for generating your deployment yml, you can ignore kubert's compile and rollback methods, which rely on ky and a Procfile to define the scope of a deployment as a group of related, seperate kubernetes deployments. Typing `ky example` at the console will import example ky configuration, including kubert configuration. You may ignore most of this if not using ky itself, and focus primarily on the kubert section of the yml for a few pieces of kubert configuration... the important ones are these:
22
10
 
23
- ## Development
24
-
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
11
+ ```
12
+ project_name: "my-project"
13
+ kubert:
14
+ contexts:
15
+ staging: staging.example.com
16
+ prod: production.example.com
17
+ excluded_deployments: [sanitize, migration]
18
+ default_environment: stg
19
+ default_namespace: default
20
+ task_pod: console
21
+ console_command: rails c
22
+ command_prefix: bundle exec
23
+ ```
26
24
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
25
+ The project name is used by ky and assumes a metadata namespace for your app deployments in the format of `{{project_name}}-{{deployment_name}}`, so as long as your deployments obey this pattern it should be usable for you without ky.
26
+ contexts is used to create convenience functions for switching between different clusters defined in the same kubeconfig file, i.e. `kubert staging` with above config will switch/ensure your config is using staging.example.com
28
27
 
29
- ## Contributing
28
+ excluded_deployments says not to deploy the following deployments defined in your Procfile during a normal deployment, and not to rollback during a rollback.
30
29
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kubert.
30
+ default_environment and/or default_namespace are optional but effect pod selection if no task_pod is defined, and effect default target environment for deployment and rollback if not specified via CLI flags.
32
31
 
32
+ Task pod is what is used for running consoles and executing tasks. If not defined it selects a random pod and uses that pod's type, though it is splitting on dashes so may not work if your pod type has dashes in its deployment name at present.
33
33
 
34
- ## License
34
+ console_command and console_prefix are for opening a REPL and for prefixing all task commands with a common prefix
35
35
 
36
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
36
+ ###Example usage
37
+ ```
38
+ $ kubert console # open a console on a task_pod
39
+ $ kubert execute rake db:migrate # run a migration
40
+ $ kubert list web # list all running web pods
41
+ $ kubert sandbox # only if rails c/rails console is console_command above, opens console wrapped in DB transaction
42
+ $ kubert context # print current kubectl context/cluster
43
+ $ kubert deploy -e prd # perform a production deployment
44
+ $ kubert rollback -e prd # rollback a production deployment
45
+ $ kubert deploy # perform a deployment to the default environment
46
+ ```
37
47
 
48
+ A valid url may also be used in place of a file path for input.
@@ -30,7 +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.2.pre1'
33
+ spec.add_runtime_dependency 'ky', '~> 0.6'
34
34
  spec.add_development_dependency 'pry', '~> 0.10'
35
35
  spec.add_development_dependency "bundler", "~> 1.13"
36
36
  spec.add_development_dependency "rake", "~> 10.0"
@@ -13,14 +13,30 @@ module Kubert
13
13
  configuration[:contexts] || []
14
14
  end
15
15
 
16
+ def self.task_pod
17
+ configuration[:task_pod] || random_pod_type
18
+ end
19
+
16
20
  def self.default_environment
17
21
  configuration[:default_environment]
18
22
  end
19
23
 
24
+ def self.default_namespace
25
+ configuration[:default_namespace] || configuration[:default_environment]
26
+ end
27
+
20
28
  def self.context
21
29
  kube_config.contexts.select {|c| kube_config.context.api_endpoint.match(c) }
22
30
  end
23
31
 
32
+ def self.console_command
33
+ Array(configuration[:console_command] && configuration[:console_command].split(" "))
34
+ end
35
+
36
+ def self.command_prefix
37
+ configuration[:command_prefix]
38
+ end
39
+
24
40
  def self.excluded_deployments
25
41
  configuration[:excluded_deployments] || []
26
42
  end
@@ -44,4 +60,22 @@ module Kubert
44
60
  )
45
61
  end
46
62
  end
63
+
64
+ private
65
+
66
+ def self.random_pod_type
67
+ Kubert.client.get_pods(namespace: current_namespace)
68
+ .sample
69
+ .metadata
70
+ .name
71
+ .split("-")
72
+ .first
73
+ end
74
+
75
+ def self.current_namespace
76
+ KY::Configuration.new[:namespace] ||
77
+ default_namespace ||
78
+ (raise "MUST DEFINE A NAMESPACE FOR POD OPERATIONS, ky namespace, default_namespace or default_environment")
79
+ end
80
+
47
81
  end
@@ -4,7 +4,7 @@ require "irb"
4
4
  module Kubert
5
5
  class Cli < Thor
6
6
 
7
- desc "list pod_type", "display a list of one type of Pod, only Ready by default"
7
+ desc "list pod_type", "Display a list of one type of Pod, only Running by default"
8
8
  def list(pod_type, status=:running)
9
9
  puts Pods.list(pod_type, status)
10
10
  end
@@ -14,17 +14,19 @@ module Kubert
14
14
  puts Kubert.context
15
15
  end
16
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")
17
+ if Kubert.console_command.first == "rails"
18
+ desc "sandbox", "Connect to a Rails console in sandbox that will wrap session in DB transaction and rollback when done"
19
+ def sandbox
20
+ execute(*Kubert.console_command, "--sandbox")
21
+ end
20
22
  end
21
23
 
22
- desc "console", "Connect to a Rails console on a console pod"
24
+ desc "console", "Connect to a console on a task pod"
23
25
  def console
24
- execute("rails", "console")
26
+ execute(*Kubert.console_command)
25
27
  end
26
28
 
27
- desc "execute command", "Connect to a pod run the specified command (with bundle exec prefix)"
29
+ desc "execute command", "Connect to a task pod and run the specified command (with #{Kubert.command_prefix} prefix)"
28
30
  def execute(*command)
29
31
  Pods.execute(command)
30
32
  end
@@ -40,7 +42,7 @@ module Kubert
40
42
  Deployment.perform(options)
41
43
  end
42
44
 
43
- desc "rollback", "Connect to a pod run the specified command (with bundle exec prefix)"
45
+ desc "rollback", "Rollback a deployment, reverse of a kubert deploy command with same flags"
44
46
  method_option :namespace, type: :string, aliases: "-n"
45
47
  method_option :environment, type: :string, aliases: "-e"
46
48
  method_option :image_tag, type: :string, aliases: "-t"
@@ -32,9 +32,9 @@ module Kubert
32
32
  pods.map(&:metadata).map(&:name)
33
33
  end
34
34
 
35
- def execute(command)
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(' ')}"
35
+ def execute(command, pod_type=Kubert.task_pod)
36
+ pod = all(pod_type).status(:running).pods.sample
37
+ exec_command = "kubectl exec -n #{pod.metadata.namespace} #{pod.metadata.name} -it #{Kubert.command_prefix} #{command.join(' ')}"
38
38
  puts "Executing command: \n#{exec_command}"
39
39
  Open3.popen3("bash") do
40
40
  exec exec_command
@@ -1,3 +1,3 @@
1
1
  module Kubert
2
- VERSION = "0.0.1-dev6"
2
+ VERSION = "0.1.0"
3
3
  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.dev6
4
+ version: 0.1.0
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-27 00:00:00.000000000 Z
11
+ date: 2017-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.5.2.pre1
47
+ version: '0.6'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.5.2.pre1
54
+ version: '0.6'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -149,9 +149,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  requirements:
152
- - - ">"
152
+ - - ">="
153
153
  - !ruby/object:Gem::Version
154
- version: 1.3.1
154
+ version: '0'
155
155
  requirements: []
156
156
  rubyforge_project:
157
157
  rubygems_version: 2.6.8