kube_wrapper 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 334f97cfae1fd7f26b6d3c68e7b865aeda5dba3b3ee095a3fdf65b836f9235d4
4
+ data.tar.gz: 6fca950d764ed6baf45047c7098265416e9b89216a23fadede868c66fbf33ad4
5
+ SHA512:
6
+ metadata.gz: c327bd3f0c79caa20e3f10c72a1aee4c6809039a2b678c25f049a9c250673e61c621fcc4252a2dccba84d7ba7837e0f4af8daee1ab3ddfa4f1baabfa018979e9
7
+ data.tar.gz: 94edd9af89ca865ff601beb01a994b3ed3d064a0b6ec7ecdc8e261f9ec045639111a707d42b47d430a8bb633234dfbfb726dacf547905d1b56144767638ba194
@@ -0,0 +1,23 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ build:
10
+
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v1
15
+ - name: Set up Ruby 2.6
16
+ uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.6.x
19
+ - name: Build and test with Rake
20
+ run: |
21
+ gem install bundler -v '1.17.3'
22
+ bundle install --jobs 4 --retry 3
23
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,13 @@
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
12
+
13
+ .*_history
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 1.17.3
data/Dockerfile ADDED
@@ -0,0 +1,15 @@
1
+ FROM ruby:2.6-alpine
2
+ MAINTAINER Kevin Blues <kevin@thinkific.com>
3
+
4
+ RUN apk update && apk add --no-cache \
5
+ bash \
6
+ dumb-init \
7
+ gcc \
8
+ git \
9
+ libc-dev \
10
+ make
11
+ RUN gem install bundler -v '~> 1'
12
+ WORKDIR /root
13
+ COPY . /root
14
+ RUN bundle
15
+ CMD dumb-init tail -f /dev/null
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in kube_wrapper.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kube_wrapper (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (11.0.1)
10
+ diff-lcs (1.3)
11
+ rake (10.5.0)
12
+ rspec (3.8.0)
13
+ rspec-core (~> 3.8.0)
14
+ rspec-expectations (~> 3.8.0)
15
+ rspec-mocks (~> 3.8.0)
16
+ rspec-core (3.8.2)
17
+ rspec-support (~> 3.8.0)
18
+ rspec-expectations (3.8.4)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-mocks (3.8.1)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-support (3.8.2)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.17)
31
+ byebug (~> 11.0)
32
+ kube_wrapper!
33
+ rake (~> 10.0)
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 1.17.3
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # KubeWrapper
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/kube_wrapper`. 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
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kube_wrapper'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kube_wrapper
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kube_wrapper.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'kube_wrapper'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/run ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'kube_wrapper'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ KubeWrapper.run
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/bin/start ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ docker-compose up -d
5
+ docker-compose exec ruby bash
6
+ docker-compose down -v
@@ -0,0 +1,6 @@
1
+ version: '3'
2
+ services:
3
+ ruby:
4
+ build: ./
5
+ volumes:
6
+ - ./:/root
data/exe/kw ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'kube_wrapper'
5
+ KubeWrapper.run
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'kube_wrapper/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'kube_wrapper'
9
+ spec.version = KubeWrapper::VERSION
10
+ spec.authors = ['Kevin Blues']
11
+ spec.email = ['kbluescode@gmail.com']
12
+
13
+ spec.summary = 'Wraps the kubectl command for more efficient K8s work'
14
+ # spec.description =
15
+ # => %q{TODO: Write a longer description or delete this line.}
16
+ spec.homepage = 'https://github.com/kbluescode/kube_wrapper'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the
19
+ # =>'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to
21
+ # => any host.
22
+ if spec.respond_to?(:metadata)
23
+ # spec.metadata["allowed_push_host"] =
24
+ # => "TODO: Set to 'http://mygemserver.com'"
25
+
26
+ spec.metadata['homepage_uri'] = spec.homepage
27
+ # spec.metadata["source_code_uri"] =
28
+ # => "TODO: Put your gem's public repo URL here."
29
+ # spec.metadata["changelog_uri"] =
30
+ # => "TODO: Put your gem's CHANGELOG.md URL here."
31
+ else
32
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
33
+ 'public gem pushes.'
34
+ end
35
+
36
+ # Specify which files should be added to the gem when it is released.
37
+ # The `git ls-files -z` loads the files in the RubyGem that have been
38
+ # => added into git.
39
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
40
+ `git ls-files -z`.split("\x0").reject do |f|
41
+ f.match(%r{^(test|spec|features)/})
42
+ end
43
+ end
44
+ spec.bindir = 'exe'
45
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
46
+ spec.require_paths = ['lib']
47
+
48
+ spec.add_development_dependency 'bundler', '~> 1.17'
49
+ spec.add_development_dependency 'byebug', '~> 11.0'
50
+ spec.add_development_dependency 'rake', '~> 10.0'
51
+ spec.add_development_dependency 'rspec', '~> 3.0'
52
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kube_wrapper/version'
4
+ require 'kube_wrapper/runner'
5
+
6
+ # KubeWrapper handles wrapping commands to kubectl to make it easier to use
7
+ module KubeWrapper
8
+ class Error < StandardError; end
9
+
10
+ class << self
11
+ def run
12
+ runner = Runner.new
13
+ runner.on(:start) { puts 'Starting Kubernetes Wrapper' }
14
+ runner.on(:exit) { puts 'Exiting Kubernetes Wrapper' }
15
+ runner.start!
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KubeWrapper
4
+ # Colors handles printing colored text to output
5
+ module Colors
6
+ COLORS = {
7
+ red: "\e[31m",
8
+ cyan: "\e[36m"
9
+ }.freeze
10
+
11
+ def print_cyan(text)
12
+ print_color(text, COLORS[:cyan])
13
+ end
14
+
15
+ def print_red(text)
16
+ print_color(text, COLORS[:red])
17
+ end
18
+
19
+ def print_color(text, color)
20
+ @io_out.print "#{color}#{text}\e[0m"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kube_wrapper/colors'
4
+ require 'shellwords'
5
+
6
+ module KubeWrapper
7
+ # Runner creates a REPL to run kubectl commands
8
+ class Runner
9
+ include KubeWrapper::Colors
10
+
11
+ COMMANDS = {
12
+ help: {
13
+ cmds: ['?', '-h', '--help'],
14
+ blurb: 'Prints this help blurb'
15
+ },
16
+ set_namespace: {
17
+ cmds: ['set-n', '-n'],
18
+ blurb: <<~DESC
19
+ Changes namespace prefix for further commands to $1. Defaults to `default`
20
+ DESC
21
+ },
22
+ clear: {
23
+ cmds: %w[cl clear],
24
+ blurb: 'Clears the screen'
25
+ }
26
+ }.freeze
27
+
28
+ attr_reader :namespace
29
+
30
+ def initialize(io_in = STDIN, io_out = STDOUT)
31
+ @io_in = io_in
32
+ @io_out = io_out
33
+ @namespace = 'default'
34
+ @callbacks = {}
35
+ end
36
+
37
+ def on(key, &block)
38
+ @callbacks[key] = block
39
+ end
40
+
41
+ def start!
42
+ @callbacks[:start]&.call
43
+ print_help
44
+ loop { run }
45
+ end
46
+
47
+ private
48
+
49
+ def exit!
50
+ @io_out.puts
51
+ @callbacks[:exit]&.call
52
+ exit
53
+ end
54
+
55
+ def print_help
56
+ COMMANDS.each do |_, cmd|
57
+ @io_out.puts "#{cmd[:cmds]}: #{cmd[:blurb]}"
58
+ end
59
+ end
60
+
61
+ def fetch_input
62
+ @io_in.gets.chomp.split(' ')
63
+ rescue NoMethodError, Interrupt
64
+ exit!
65
+ end
66
+
67
+ def update_namespace!(namespace)
68
+ @namespace = namespace || 'default'
69
+ @io_out.puts "Namespace set to #{@namespace}"
70
+ end
71
+
72
+ def handle_input(input)
73
+ case input.first
74
+ when *COMMANDS[:help][:cmds] then print_help
75
+ when *COMMANDS[:set_namespace][:cmds] then update_namespace!(input[1])
76
+ when *COMMANDS[:clear][:cmds] then print "\e[2J\e[f"
77
+ else
78
+ @io_out.puts `kubectl -n #{namespace} #{Shellwords.shelljoin(input)}`
79
+ end
80
+ nil
81
+ end
82
+
83
+ def run
84
+ print_cyan "kubectl -n #{namespace} "
85
+ input = fetch_input
86
+ handle_input(input)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KubeWrapper
4
+ VERSION = '0.1.1'
5
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kube_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Blues
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.0'
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
+ - kbluescode@gmail.com
72
+ executables:
73
+ - kw
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".github/workflows/ruby.yml"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Dockerfile
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/run
88
+ - bin/setup
89
+ - bin/start
90
+ - docker-compose.yml
91
+ - exe/kw
92
+ - kube_wrapper.gemspec
93
+ - lib/kube_wrapper.rb
94
+ - lib/kube_wrapper/colors.rb
95
+ - lib/kube_wrapper/runner.rb
96
+ - lib/kube_wrapper/version.rb
97
+ homepage: https://github.com/kbluescode/kube_wrapper
98
+ licenses: []
99
+ metadata:
100
+ homepage_uri: https://github.com/kbluescode/kube_wrapper
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.0.4
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Wraps the kubectl command for more efficient K8s work
120
+ test_files: []