kbe 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 94d0a36ad8a5781a720654438e391faf89f77f9e4779602e35bb44f6217ba38f
4
+ data.tar.gz: 60c4010109c95b55a83b21a7aca4a38057d32ea4a53c09c00420c334ca5d67b7
5
+ SHA512:
6
+ metadata.gz: 02fa5d1987ba79fe18be0d57b805f7d28d87290239323991f299c4a04dc38d51bbc5b1fcf5fa51a16d934c241862d00494049be5400dc2b52d74015021d6bfaa
7
+ data.tar.gz: bb7316fe6c1c42d4f7fb3ca3ef2c3387ef54335e664561f5b9b2226b9a3cd428dd778e69148d73315b2d1d0a700cb56dba07b1f9b551e161d883a0bf2e11a339
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ kbe
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.17.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in kbe.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kbe (0.1.0)
5
+ clamp
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ clamp (1.3.0)
11
+ diff-lcs (1.3)
12
+ rake (10.5.0)
13
+ rspec (3.8.0)
14
+ rspec-core (~> 3.8.0)
15
+ rspec-expectations (~> 3.8.0)
16
+ rspec-mocks (~> 3.8.0)
17
+ rspec-core (3.8.0)
18
+ rspec-support (~> 3.8.0)
19
+ rspec-expectations (3.8.2)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.8.0)
22
+ rspec-mocks (3.8.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-support (3.8.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.17)
32
+ kbe!
33
+ rake (~> 10.0)
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 1.17.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Matti Paksula
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # kbe
2
+
3
+ kbe enter myapp
4
+ kbe enter myapp -c first
5
+ kbe enter myapp -c first -- uptime -h
6
+ kbe enter app=myapp -c first -- uptime -h
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kbe"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/kbe ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # add lib to libpath (only needed when running from the sources)
5
+ require 'pathname'
6
+ lib_path = File.expand_path('../../lib', Pathname.new(__FILE__).realpath)
7
+ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
8
+
9
+ STDOUT.sync = true
10
+
11
+ require 'kbe'
12
+ KBE::CLI::RootCommand.run
data/kbe.gemspec ADDED
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "kbe/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kbe"
8
+ spec.version = KBE::VERSION
9
+ spec.authors = ["Matti Paksula"]
10
+ spec.email = ["matti.paksula@iki.fi"]
11
+
12
+ spec.summary = "kubectl booster"
13
+ spec.homepage = "https://github.com/matti/kbe"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_runtime_dependency "clamp"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.17"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBE
4
+ module CLI
5
+ class EnterCommand < Clamp::Command
6
+ option ['-h', '--help'], :flag, "help" do
7
+ puts "kbe enter myapp"
8
+ puts "kbe enter myapp -c first"
9
+ puts "kbe enter myapp -c first -- uptime -h"
10
+ puts "kbe enter app=myapp -c first -- uptime -h"
11
+ exit 0
12
+ end
13
+
14
+ option ['-c', '--container'], 'CONTAINER', 'container', default: :first
15
+
16
+ parameter "SELECTOR", "k8s selector, like app=nginx"
17
+ parameter "[CMD] ...", "cmd", default: ['sh']
18
+
19
+ def execute
20
+ pod = KBE.pod_by selector
21
+
22
+ args = []
23
+ args << "exec -it #{pod}"
24
+ unless container == :first
25
+ args << "-c #{container}"
26
+ end
27
+ args << cmd_list.join(" ")
28
+
29
+ KBE.kubectl args
30
+ end
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBE
4
+ module CLI
5
+ class HelpCommand < Clamp::Command
6
+ def execute
7
+ exec "kbe -h"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ require_relative "version_command"
3
+ require_relative "help_command"
4
+ require_relative "enter_command"
5
+
6
+ module KBE
7
+ module CLI
8
+ class RootCommand < Clamp::Command
9
+ banner "kbe 🍻"
10
+
11
+ option ['-v', '--version'], :flag, "Show version information" do
12
+ puts KBE::VERSION
13
+ exit(0)
14
+ end
15
+
16
+ subcommand ["enter"], "Enter a container", EnterCommand
17
+ subcommand ["version"], "Show version information", VersionCommand
18
+ subcommand ["help"], "Show help", HelpCommand
19
+
20
+ def self.run
21
+ super
22
+ rescue StandardError => exc
23
+ warn exc.message
24
+ warn exc.backtrace.join("\n")
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBE
4
+ module CLI
5
+ class VersionCommand < Clamp::Command
6
+ def execute
7
+ puts KBE::VERSION
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/kbe/cli.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'clamp'
2
+ #Clamp.allow_options_after_parameters = true
3
+
4
+ module KBE
5
+ module CLI
6
+ end
7
+ end
8
+
9
+ require_relative 'cli/root_command'
10
+
@@ -0,0 +1,3 @@
1
+ module KBE
2
+ VERSION = "0.1.0"
3
+ end
data/lib/kbe.rb ADDED
@@ -0,0 +1,39 @@
1
+ module KBE
2
+ class Error < StandardError; end
3
+
4
+ def self.kubectl(*args)
5
+ cmd = []
6
+ cmd << "kubectl"
7
+ cmd << args
8
+
9
+ cmd_string = cmd.join " "
10
+ STDERR.puts cmd_string
11
+ exec cmd_string
12
+ end
13
+
14
+ def self.pod_by(selector)
15
+ ["app", "job-name"].each do |selector_prefix|
16
+ magic_selector = if selector.match? "="
17
+ selector
18
+ else
19
+ "#{selector_prefix}=#{selector}"
20
+ end
21
+
22
+ pods = `kubectl get pods --no-headers -o custom-columns=":metadata.name" --field-selector=status.phase=Running --selector=#{magic_selector}`.split("\n")
23
+ return pods.first if pods.size == 1
24
+
25
+ break if magic_selector == selector
26
+ next if pods.empty?
27
+
28
+ STDERR.puts "too many pods"
29
+ exit 1
30
+ end
31
+
32
+ STDERR.puts "no pod found"
33
+ exit 1
34
+ end
35
+ end
36
+
37
+ require_relative 'kbe/version'
38
+ require_relative 'kbe/cli'
39
+
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kbe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matti Paksula
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: clamp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - matti.paksula@iki.fi
72
+ executables:
73
+ - kbe
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".ruby-gemset"
80
+ - ".ruby-version"
81
+ - ".travis.yml"
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - exe/kbe
90
+ - kbe.gemspec
91
+ - lib/kbe.rb
92
+ - lib/kbe/cli.rb
93
+ - lib/kbe/cli/enter_command.rb
94
+ - lib/kbe/cli/help_command.rb
95
+ - lib/kbe/cli/root_command.rb
96
+ - lib/kbe/cli/version_command.rb
97
+ - lib/kbe/version.rb
98
+ homepage: https://github.com/matti/kbe
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.7.7
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: kubectl booster
122
+ test_files: []