kubetailrb 0.1.0

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: 4b945e0de1dfdd765db891edb1a5e8c59a6cf7c1940a81147a4cd3c31b398003
4
+ data.tar.gz: bbebd5de583b686f18750f26bb2b9b52f3505da68285286e91f20417c0ecfa23
5
+ SHA512:
6
+ metadata.gz: 871dc15cb59a8b657d4488fa08f78a04db28910b9aac8ff1938944d943d7a9a99b895164d6fe39f1ce8541a41730da3e34a84c09a89486bf73c2870fea13885d
7
+ data.tar.gz: 86d562f6163e7206a5c7a95f52bf8dd2e56de246590b35b4fdd338c1bc1624aacdbd2a7df91475f9612e737e320bdc7ba53ea86cb7bdb0f54ea6d0c89baaf6fc
data/.pryrc ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Define some debugging behaviours to ease debugging sessions.
5
+ # src: https://github.com/deivid-rodriguez/pry-byebug?tab=readme-ov-file#matching-byebug-behaviour
6
+ #
7
+
8
+ if defined?(PryByebug)
9
+ Pry.commands.alias_command 'c', 'continue'
10
+ Pry.commands.alias_command 's', 'step'
11
+ Pry.commands.alias_command 'n', 'next'
12
+ Pry.commands.alias_command 'f', 'finish'
13
+ end
14
+
15
+ # Hit Enter to repeat last command
16
+ Pry::Commands.command(/^$/, 'repeat last command') do
17
+ pry_instance.run_command Pry.history.to_a.last
18
+ end
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ require:
2
+ - rubocop-minitest
3
+ - rubocop-rake
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 3.0
7
+
8
+ Metrics/BlockLength:
9
+ Enabled: false
10
+
11
+ Metrics/ClassLength:
12
+ Enabled: false
13
+
14
+ Metrics/MethodLength:
15
+ Enabled: true
16
+ Max: 40
17
+
18
+ Style/StringLiterals:
19
+ Enabled: true
20
+ EnforcedStyle: single_quotes
21
+
22
+ Style/StringLiteralsInInterpolation:
23
+ EnforcedStyle: double_quotes
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-10-27
4
+
5
+ - Initial release
data/Guardfile ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Guard is a command line tool to easily handle events on file system modifications.
5
+ # More info at https://github.com/guard/guard#readme
6
+ #
7
+
8
+ #
9
+ # Configuration generated by using `guard init minitest`.
10
+ #
11
+ guard :minitest do
12
+ watch(%r{^test/(.*)/?(.*)_test\.rb$})
13
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
14
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
15
+ end
16
+
17
+ #
18
+ # Configuration generated by using `guard init cucumber`.
19
+ #
20
+ cucumber_options = {
21
+ # Need to disable this in order to make it work with recent version of cucumber.
22
+ # src: https://github.com/guard/guard-cucumber/issues/41#issuecomment-716199847
23
+ notification: false,
24
+ cmd_additional_args: '--publish-quiet'
25
+ }
26
+
27
+ guard 'cucumber', cucumber_options do
28
+ watch(%r{^features/.+\.feature$})
29
+ watch(%r{^features/support/.+$}) { 'features' }
30
+
31
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) do |m|
32
+ Dir[File.join("**/#{m[1]}.feature")][0] || 'features'
33
+ end
34
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Louis Lin
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,73 @@
1
+ # Kubetailrb
2
+
3
+ > Tail your Kubernetes pod logs at the same time.
4
+
5
+ > [!NOTE]
6
+ > This project is a pet project I used to learn the [Ruby programming language](https://www.ruby-lang.org/en/).
7
+ > So you might find lots of my [personal notes](./journey_log.md) in the codebase.
8
+ >
9
+ > If you want to have something that works, please look at the following
10
+ > projects that were used as inspirations instead:
11
+ >
12
+ > - https://github.com/stern/stern
13
+ > - https://github.com/johanhaleby/kubetail
14
+
15
+ ![kubetailrb](./kubetailrb.png)
16
+
17
+ ## Installation
18
+
19
+ ```sh
20
+ # Install dependencies.
21
+ ./bin/setup
22
+
23
+ # Install gem onto your local machine
24
+ bundle exec rake install
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```bash
30
+ # show help
31
+ kubetailrb -h
32
+
33
+ # follow pod logs
34
+ kubetailrb 'clock' --namespace sandbox
35
+
36
+ # follow pod structured JSON logs and display in human friendly way
37
+ kubetailrb 'clock-json' --namespace sandbox --pretty --raw --follow
38
+ # or with shorter flags
39
+ kubetailrb 'clock-json' -n sandbox -p -r -f
40
+
41
+ # you can filter the pods using regex on the pod names
42
+ kubetailrb '^clock(?!-json)' -n sandbox -p -r
43
+
44
+ ```
45
+
46
+ ## Development
47
+
48
+ ```bash
49
+ # Open interactive prompt to allow you to experiment.
50
+ ./bin/console
51
+
52
+ # Release new version
53
+ NEW_VERSION=1.0.1 \
54
+ && sed "s/VERSION = \".*\"/VERSION = \"${NEW_VERSION}\"/" lib/kubetailrb/version.rb
55
+ && bundle exec rake release
56
+
57
+ # Check available tasks that can be run
58
+ bundle exec rake --tasks
59
+
60
+ # During your development phase, run tests automatically.
61
+ bundle exec rake test:watch
62
+
63
+ # Run tests, cucumber features and lint.
64
+ bundle exec rake
65
+ ```
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/l-lin/kubetailrb.
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+
5
+ require 'bundler/gem_tasks'
6
+
7
+ require 'minitest/test_task'
8
+ Minitest::TestTask.create
9
+
10
+ require 'rubocop/rake_task'
11
+ RuboCop::RakeTask.new
12
+
13
+ require 'cucumber/rake/task'
14
+ Cucumber::Rake::Task.new
15
+
16
+ task default: %i[test cucumber rubocop]
17
+
18
+ namespace :test do
19
+ desc 'Watch files and re-execute tests.'
20
+ task :watch do
21
+ exec('guard -c')
22
+ end
23
+ end
24
+
25
+ K8S_NAMESPACE = 'sandbox'
26
+
27
+ namespace :k8s do
28
+ desc 'Create local Kubernetes cluster.'
29
+ task :create do
30
+ next if k8s_up?
31
+
32
+ puts 'Starting local Kubernetes cluster...'
33
+ puts `k3d cluster create --config k3d/default.yml \
34
+ --k3s-arg '--kubelet-arg=eviction-hard=imagefs.available<1%,nodefs.available<1%@agent:*' \
35
+ --k3s-arg '--kubelet-arg=eviction-minimum-reclaim=imagefs.available=1%,nodefs.available=1%@agent:*';`
36
+
37
+ puts "Creating namespace #{K8S_NAMESPACE}"
38
+ `kubectl create namespace #{K8S_NAMESPACE}`
39
+ `kubens #{K8S_NAMESPACE}`
40
+ end
41
+
42
+ desc 'Destroy local Kubernetes cluster.'
43
+ task :nuke do
44
+ next unless k8s_up?
45
+
46
+ k3d_cluster = `k3d cluster list --no-headers`.split(' ').first
47
+ puts "Destroying local Kubernetes cluster '#{k3d_cluster}'!!!"
48
+ `k3d cluster delete #{k3d_cluster}`
49
+ end
50
+
51
+ desc 'Deploy application to k8s.'
52
+ task :deploy, [:app_name] do |_, args|
53
+ next unless k8s_up?
54
+
55
+ app_name = args[:app_name]
56
+
57
+ next if app_name.nil? || app_name.strip.empty?
58
+
59
+ docker_image = "registry.localhost:5000/#{app_name}"
60
+ clock_dir = "k3d/#{app_name}"
61
+
62
+ puts "Building Docker image #{docker_image}"
63
+ `docker build -t #{docker_image} #{clock_dir}`
64
+ `docker push #{docker_image}`
65
+ puts `kubectl delete po #{app_name} --force true` if pod_up?(app_name)
66
+ puts `kubectl run #{app_name} --image #{docker_image}`
67
+ end
68
+
69
+ desc 'Deploy all applications to k8s.'
70
+ task :deploy_all do
71
+ Rake::Task['k8s:deploy'].invoke('clock')
72
+ # Rake does not actually run the task, but rather it adds it to a task
73
+ # queue. So we need to re-enable the task so it can be run again.
74
+ Rake::Task['k8s:deploy'].reenable
75
+ Rake::Task['k8s:deploy'].invoke('clock-json')
76
+ end
77
+ end
78
+
79
+ def k8s_up?
80
+ !`k3d cluster list --no-headers`.strip.empty?
81
+ end
82
+
83
+ def pod_up?(app_name)
84
+ !`kubectl get po | grep '^#{app_name}'`.strip.empty?
85
+ end
data/exe/kubetailrb ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'kubetailrb'
5
+
6
+ Kubetailrb::CLI.new.execute(*ARGV)