helm_upgrade_logs 0.2.3 → 0.2.6
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 +4 -4
- data/.github/workflows/test.yml +17 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +13 -0
- data/README.md +0 -3
- data/Rakefile +1 -1
- data/exe/helm_test_logs +8 -5
- data/exe/helm_upgrade_logs +29 -17
- data/lib/helm_upgrade_logs/version.rb +2 -1
- data/lib/helm_upgrade_logs.rb +35 -16
- metadata +2 -3
- data/get_pods.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b684e4674b966c9d98079db28468bf57ef4001864339ee751fcac7f732f8ec6e
|
4
|
+
data.tar.gz: 159438d7491016b11312941dd3fe9a7ff9a89234587243e0ce879bf5675af6f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9617547cfeb95b3b547196844bfa8cdfc20b33246b28c6b65b274dd2cba2a0271dfbe0574f96eb46daf50fb413ec10d6a45412d8010d94500ec3fa90710a9fcb
|
7
|
+
data.tar.gz: 67e19d49ffdd9ad203de6c7adb82f4344e35fb2b8637d2e32fb6f9df83c1d552cf63506ea67e3ce2c0a714f72b2b1a841256c7d418e57356d445cfc6dc6e6c0e
|
data/.github/workflows/test.yml
CHANGED
@@ -30,8 +30,6 @@ jobs:
|
|
30
30
|
ruby-version: ${{ matrix.ruby-version }}
|
31
31
|
- name: Start KIND cluster
|
32
32
|
run: bash -f bin/start_kind.sh
|
33
|
-
- name: Waiting for KIND cluster to get ready
|
34
|
-
run: sleep 70
|
35
33
|
- name: Install gem
|
36
34
|
run: gem install helm_upgrade_logs
|
37
35
|
- name: Add bitnami repo
|
@@ -39,6 +37,21 @@ jobs:
|
|
39
37
|
- name: Helm install debugging logs
|
40
38
|
run: helm_upgrade_logs --install nginx bitnami/nginx --wait --debug --set service.type=ClusterIP
|
41
39
|
|
40
|
+
unit_test:
|
41
|
+
runs-on: ubuntu-latest
|
42
|
+
strategy:
|
43
|
+
matrix:
|
44
|
+
ruby-version: ['3.0']
|
45
|
+
steps:
|
46
|
+
- uses: actions/checkout@v3
|
47
|
+
- name: Set up Ruby
|
48
|
+
uses: ruby/setup-ruby@v1
|
49
|
+
with:
|
50
|
+
ruby-version: ${{ matrix.ruby-version }}
|
51
|
+
bundler-cache: true
|
52
|
+
- name: Run tests
|
53
|
+
run: bundle exec rake
|
54
|
+
|
42
55
|
test_exe:
|
43
56
|
runs-on: ubuntu-latest
|
44
57
|
strategy:
|
@@ -49,11 +62,11 @@ jobs:
|
|
49
62
|
- uses: actions/checkout@v3
|
50
63
|
- name: Start KIND cluster
|
51
64
|
run: bash -f bin/start_kind.sh
|
52
|
-
# - name: Waiting for KIND cluster to get ready
|
53
|
-
# run: sleep 70
|
54
65
|
- name: Add bitnami repo
|
55
66
|
run: helm repo add bitnami https://charts.bitnami.com/bitnami
|
56
67
|
- name: Install bitnami
|
57
68
|
run: ./exe/helm_upgrade_logs --install nginx bitnami/nginx --wait --debug --set service.type=ClusterIP --set replicaCount=2
|
69
|
+
- name: Test bitnami
|
70
|
+
run: ./exe/helm_test_logs nginx
|
58
71
|
- name: Install Redis
|
59
72
|
run: ./exe/helm_upgrade_logs --install redis bitnami/redis --set auth.enabled=false --version 14.0.2 --wait
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## [0.2.6]
|
2
|
+
|
3
|
+
-- Don't log pods existing before an upgrade
|
4
|
+
|
5
|
+
## [0.2.5] 2022-04-21
|
6
|
+
|
7
|
+
- Return helm status code as script's status code
|
8
|
+
|
9
|
+
## [0.2.4] 2022-04-21
|
10
|
+
|
11
|
+
- Handle `n`, `--namespace` from helm command
|
12
|
+
- Exit if there is failure on helm command while trying to get logs
|
13
|
+
|
1
14
|
## [0.2.3] - 2022-04-20
|
2
15
|
|
3
16
|
- Configuration on initial wait for pods logs and subsequent wait limits
|
data/README.md
CHANGED
@@ -51,9 +51,6 @@ However if you do want to try it, to install `nginx` from the chart `bitnami/ngi
|
|
51
51
|
curl -s https://raw.githubusercontent.com/SamuelGarrattIqa/helm_upgrade_logs/main/bin/helm_upgrade_logs.sh | bash -s -- --install nginx bitnami/nginx
|
52
52
|
```
|
53
53
|
|
54
|
-
## TODO
|
55
|
-
* Make library handle `n`, `--namespace` from helm command
|
56
|
-
|
57
54
|
## Development
|
58
55
|
|
59
56
|
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.
|
data/Rakefile
CHANGED
data/exe/helm_test_logs
CHANGED
@@ -2,13 +2,16 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
5
|
-
require
|
5
|
+
require "helm_upgrade_logs"
|
6
6
|
|
7
|
-
|
7
|
+
@release_name = ARGV.find { |arg| !arg.start_with?("-") }
|
8
|
+
@namespace = namespace_from_args(ARGV)
|
8
9
|
|
9
|
-
helm_pid = Process.spawn "helm test #{ARGV.join(
|
10
|
+
helm_pid = Process.spawn "helm test #{ARGV.join(" ")}"
|
10
11
|
|
11
|
-
log_pid = Process.spawn
|
12
|
+
log_pid = Process.spawn(add_ns("kubectl logs -lapp.kubernetes.io/instance=#{@release_name} -f --all-containers --prefix --ignore-errors=true --max-log-requests=20 --timestamps=true --since=1s"))
|
12
13
|
|
13
14
|
Process.wait helm_pid
|
14
|
-
|
15
|
+
helm_status = $CHILD_STATUS.exitstatus
|
16
|
+
`kill #{log_pid}`
|
17
|
+
exit helm_status
|
data/exe/helm_upgrade_logs
CHANGED
@@ -1,42 +1,54 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
4
|
+
require "open3"
|
5
5
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
6
|
-
require
|
6
|
+
require "helm_upgrade_logs"
|
7
7
|
|
8
|
-
|
8
|
+
@release_name = ARGV.find { |arg| !arg.start_with?("-") }
|
9
|
+
@namespace = namespace_from_args(ARGV)
|
9
10
|
|
10
|
-
helm_pid = Process.spawn "helm upgrade #{ARGV.join(
|
11
|
+
@helm_pid = Process.spawn "helm upgrade #{ARGV.join(" ")}"
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
pods_before_upgrade = read_pods
|
14
|
+
puts "[INFO] Pods before upgrade #{pods_before_upgrade}" if pods_before_upgrade.size.positive?
|
15
|
+
|
16
|
+
event_pid = Process.spawn(add_ns("kubectl get events --watch-only=true"))
|
17
|
+
service_pid = Process.spawn(add_ns("kubectl get services --watch-only=true"))
|
14
18
|
|
15
19
|
wait_for_pod_to_log
|
16
20
|
|
17
21
|
@pods = []
|
18
22
|
@pod_pids = {}
|
19
23
|
|
20
|
-
|
21
|
-
|
24
|
+
begin
|
25
|
+
Process.waitpid(@helm_pid, Process::WNOHANG)
|
26
|
+
rescue Errno::ECHILD
|
27
|
+
`kill #{event_pid}`
|
28
|
+
`kill #{service_pid}`
|
29
|
+
raise HelmUpgradeLogs::Error, "Failed to find logs before helm finished"
|
30
|
+
end
|
31
|
+
|
32
|
+
while Process.waitpid(@helm_pid, Process::WNOHANG).nil?
|
33
|
+
pods = read_pods - pods_before_upgrade
|
22
34
|
if pods != @pods
|
23
35
|
@pods = pods
|
24
|
-
puts "[INFO] Pods: #{pods.join(
|
36
|
+
puts "[INFO] Pods: #{pods.join(",")}"
|
25
37
|
# Could change this each to Parallel.each
|
26
38
|
@pods.each do |pod|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
39
|
+
next unless @pod_pids[pod].nil?
|
40
|
+
|
41
|
+
wait_for_specific_pod_to_log pod
|
42
|
+
log_pid = Process.spawn(add_ns("kubectl logs #{pod} -f --all-containers --prefix --ignore-errors=true --timestamps=true"))
|
43
|
+
@pod_pids[pod] = log_pid
|
32
44
|
end
|
33
45
|
end
|
34
46
|
sleep 1
|
35
47
|
end
|
48
|
+
helm_status = $CHILD_STATUS.exitstatus
|
36
49
|
`kill #{event_pid}`
|
37
50
|
`kill #{service_pid}`
|
38
|
-
@pod_pids.each do |
|
51
|
+
@pod_pids.each do |_pod, pid|
|
39
52
|
`kill #{pid}`
|
40
53
|
end
|
41
|
-
|
42
|
-
|
54
|
+
exit helm_status
|
data/lib/helm_upgrade_logs.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "open3"
|
4
|
+
require 'English'
|
4
5
|
require_relative "helm_upgrade_logs/version"
|
5
6
|
|
6
|
-
ENV[
|
7
|
-
ENV[
|
7
|
+
ENV["helm_upgrade_logs_log_start"] ||= "90"
|
8
|
+
ENV["helm_upgrade_logs_pod_start"] ||= "35"
|
8
9
|
|
9
10
|
# Approach not ideal as it will for all containers to be ready and want to stream logs before that
|
10
11
|
def wait_for_container_ready
|
@@ -12,43 +13,61 @@ def wait_for_container_ready
|
|
12
13
|
Process.wait wait_pid
|
13
14
|
end
|
14
15
|
|
15
|
-
# Wait for pods with logs to be present
|
16
|
+
# Wait for very first pods with logs to be present
|
16
17
|
# Not ideal due to https://github.com/kubernetes/kubernetes/issues/28746
|
17
18
|
def wait_for_pod_to_log
|
18
|
-
ENV[
|
19
|
+
ENV["helm_upgrade_logs_log_start"].to_i.times do |i|
|
20
|
+
break unless Process.waitpid(@helm_pid, Process::WNOHANG).nil?
|
21
|
+
|
19
22
|
sleep 1
|
20
|
-
stdout, stderr,
|
23
|
+
stdout, stderr, = Open3.capture3(add_ns("kubectl logs -lapp.kubernetes.io/instance=#{@release_name}"))
|
21
24
|
if stderr.empty? && !stdout.strip.empty?
|
22
|
-
puts
|
25
|
+
puts "[INFO] Pods with logs found"
|
23
26
|
break
|
24
|
-
|
25
|
-
puts "[INFO] Waiting for pod logs: #{stderr}"
|
27
|
+
elsif (i % 3).zero?
|
28
|
+
puts "[INFO] Waiting for pod logs: #{stderr}"
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
33
|
+
# Wait for logs from a specific pod
|
30
34
|
def wait_for_specific_pod_to_log(pod_name)
|
31
|
-
ENV[
|
35
|
+
ENV["helm_upgrade_logs_pod_start"].to_i.times do |i|
|
32
36
|
sleep 1
|
33
|
-
stdout, stderr,
|
37
|
+
stdout, stderr, = Open3.capture3(add_ns("kubectl logs #{pod_name}"))
|
34
38
|
if stderr.empty? && !stdout.strip.empty?
|
35
39
|
puts "[INFO] Pod #{pod_name} with logs found"
|
36
40
|
break
|
37
|
-
|
38
|
-
puts "[INFO] Waiting for pod #{pod_name} logs: #{stderr}"
|
41
|
+
elsif i.even?
|
42
|
+
puts "[INFO] Waiting for pod #{pod_name} logs: #{stderr}"
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
|
-
|
44
|
-
|
47
|
+
# Get pods
|
48
|
+
def read_pods
|
49
|
+
stdout, stderr, = Open3.capture3(add_ns("kubectl get pods -lapp.kubernetes.io/instance=#{@release_name} -o name"))
|
45
50
|
if stderr.empty?
|
46
|
-
stdout.lines.collect
|
51
|
+
stdout.lines.collect(&:strip)
|
47
52
|
else
|
48
53
|
[]
|
49
54
|
end
|
50
55
|
end
|
51
56
|
|
57
|
+
# @param [Array] args
|
58
|
+
def namespace_from_args(args)
|
59
|
+
match_index = args.find_index { |arg| %w[-n --namespace].include?(arg) }
|
60
|
+
return nil unless match_index
|
61
|
+
|
62
|
+
args[match_index + 1]
|
63
|
+
end
|
64
|
+
|
65
|
+
# Add namespace to kube query
|
66
|
+
def add_ns(kube_query)
|
67
|
+
kube_query += " -n #{@namespace}" if @namespace
|
68
|
+
kube_query
|
69
|
+
end
|
70
|
+
|
52
71
|
module HelmUpgradeLogs
|
53
72
|
class Error < StandardError; end
|
54
73
|
# Your code goes here...
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: helm_upgrade_logs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Basic wrapper around helm and kubectl to allow easy debugging of a helm
|
14
14
|
release. All arguments after a usual helm upgrade are used as normal
|
@@ -41,7 +41,6 @@ files:
|
|
41
41
|
- bin/start_kind.sh
|
42
42
|
- exe/helm_test_logs
|
43
43
|
- exe/helm_upgrade_logs
|
44
|
-
- get_pods.rb
|
45
44
|
- helm_upgrade_logs.gemspec
|
46
45
|
- lib/helm_upgrade_logs.rb
|
47
46
|
- lib/helm_upgrade_logs/version.rb
|