helm_upgrade_logs 0.2.5 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +3 -1
- data/CHANGELOG.md +14 -0
- data/README.md +7 -0
- data/exe/helm_upgrade_logs +34 -3
- data/lib/helm_upgrade_logs/version.rb +1 -1
- data/lib/helm_upgrade_logs.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b0bd4dec8d15bd330ceb45ba82dc81e0a5ca0301c8032037462bd532ed6f75a
|
4
|
+
data.tar.gz: d4bd99f9a4d04e25b8f34089169f3355ac43d75081438aa3d8ed6854b0f787f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c097c2af0698ad0c844c97c78f94498edafa94f66213d782a9fa9b5dc959cc6a0f9bf3ae11b39ce70860b7e91de92e00d4da6d0cd07b361145b4c6d04f118115
|
7
|
+
data.tar.gz: a8e3188650ec71f1a8de1c44c2f6105d02c09247e18feebbd2f625b898a9cc983f92c4eab9e0dec08d7daabd4e1298f720fc901a985be65658f274e5a8764c97
|
data/.github/workflows/test.yml
CHANGED
@@ -60,6 +60,8 @@ jobs:
|
|
60
60
|
|
61
61
|
steps:
|
62
62
|
- uses: actions/checkout@v3
|
63
|
+
- name: Use Debug
|
64
|
+
run: export helm_upgrade_logs_debug=true
|
63
65
|
- name: Start KIND cluster
|
64
66
|
run: bash -f bin/start_kind.sh
|
65
67
|
- name: Add bitnami repo
|
@@ -69,4 +71,4 @@ jobs:
|
|
69
71
|
- name: Test bitnami
|
70
72
|
run: ./exe/helm_test_logs nginx
|
71
73
|
- name: Install Redis
|
72
|
-
run: ./exe/helm_upgrade_logs --install redis bitnami/redis --set auth.enabled=false --version
|
74
|
+
run: ./exe/helm_upgrade_logs --install redis bitnami/redis --set auth.enabled=false --version 15.7.2 --set replica.replicaCount=1 --wait
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [0.3.1]
|
2
|
+
|
3
|
+
- Fix LOG folder parsed to check error message
|
4
|
+
|
5
|
+
## [0.3.0]
|
6
|
+
|
7
|
+
- Log output to a file in a folder `helm_upgrade_logs` as well as STDOUT
|
8
|
+
- If `helm_upgrade_logs_error_msg` is set then rethrow error after install finished. For AzureDevOps, setting
|
9
|
+
`helm_upgrade_logs_ado_error` to `true` will raise an error in the build
|
10
|
+
|
11
|
+
## [0.2.6]
|
12
|
+
|
13
|
+
- Don't log pods existing before an upgrade
|
14
|
+
|
1
15
|
## [0.2.5] 2022-04-21
|
2
16
|
|
3
17
|
- Return helm status code as script's status code
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
Idea is to show logs of pods and events while doing a kubernetes helm install or upgrade.
|
4
4
|
|
5
|
+
> This has only been tested on linux. More more would be needed to run script properly on Windows
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
@@ -35,6 +37,11 @@ This library waits for logs to start in pods for 90 seconds or controlled by env
|
|
35
37
|
After that it waits 35 seconds for logs to start in pods after the first one.
|
36
38
|
This is controlled by environment variable `helm_upgrade_logs_pod_start`
|
37
39
|
|
40
|
+
Logs are pushed to STDOUT and also to files in a folder `helm_upgrade_logs`.
|
41
|
+
The ENV variable `helm_upgrade_logs_error_msg` can be set to throw an error at the end for a certain string
|
42
|
+
contained in the logs like `ERROR`. The `helm_upgrade_logs_ado_error` can be set to raise a signal to Azure
|
43
|
+
Dev Ops to throw an error in the build.
|
44
|
+
|
38
45
|
To test a chart showing it logs, in a similar way run
|
39
46
|
```bash
|
40
47
|
helm_test_logs redis
|
data/exe/helm_upgrade_logs
CHANGED
@@ -2,14 +2,19 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require "open3"
|
5
|
+
require "fileutils"
|
5
6
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
6
7
|
require "helm_upgrade_logs"
|
8
|
+
UPGRADE_LOG_FOLDER = "helm_upgrade_logs"
|
7
9
|
|
8
10
|
@release_name = ARGV.find { |arg| !arg.start_with?("-") }
|
9
11
|
@namespace = namespace_from_args(ARGV)
|
10
12
|
|
11
13
|
@helm_pid = Process.spawn "helm upgrade #{ARGV.join(" ")}"
|
12
14
|
|
15
|
+
pods_before_upgrade = read_pods
|
16
|
+
puts "[INFO] Pods before upgrade #{pods_before_upgrade}" if pods_before_upgrade.size.positive?
|
17
|
+
|
13
18
|
event_pid = Process.spawn(add_ns("kubectl get events --watch-only=true"))
|
14
19
|
service_pid = Process.spawn(add_ns("kubectl get services --watch-only=true"))
|
15
20
|
|
@@ -26,8 +31,10 @@ rescue Errno::ECHILD
|
|
26
31
|
raise HelmUpgradeLogs::Error, "Failed to find logs before helm finished"
|
27
32
|
end
|
28
33
|
|
34
|
+
FileUtils.mkdir_p UPGRADE_LOG_FOLDER
|
35
|
+
|
29
36
|
while Process.waitpid(@helm_pid, Process::WNOHANG).nil?
|
30
|
-
pods = read_pods
|
37
|
+
pods = read_pods - pods_before_upgrade
|
31
38
|
if pods != @pods
|
32
39
|
@pods = pods
|
33
40
|
puts "[INFO] Pods: #{pods.join(",")}"
|
@@ -36,8 +43,15 @@ while Process.waitpid(@helm_pid, Process::WNOHANG).nil?
|
|
36
43
|
next unless @pod_pids[pod].nil?
|
37
44
|
|
38
45
|
wait_for_specific_pod_to_log pod
|
39
|
-
|
40
|
-
|
46
|
+
std_out_pid = Process.spawn(
|
47
|
+
add_ns("kubectl logs #{pod} -f --all-containers --prefix --ignore-errors=true --timestamps=true")
|
48
|
+
)
|
49
|
+
logfile_pid = Process.spawn(
|
50
|
+
add_ns("kubectl logs #{pod} -f --all-containers --prefix --ignore-errors=true --timestamps=true"),
|
51
|
+
out: "#{UPGRADE_LOG_FOLDER}/#{pod.gsub("/", "_")}.log"
|
52
|
+
)
|
53
|
+
@pod_pids["#{pod}_stdout"] = std_out_pid
|
54
|
+
@pod_pids["#{pod}_fileout"] = logfile_pid
|
41
55
|
end
|
42
56
|
end
|
43
57
|
sleep 1
|
@@ -45,7 +59,24 @@ end
|
|
45
59
|
helm_status = $CHILD_STATUS.exitstatus
|
46
60
|
`kill #{event_pid}`
|
47
61
|
`kill #{service_pid}`
|
62
|
+
puts @pod_pids if ENV["helm_upgrade_logs_debug"] == "true"
|
48
63
|
@pod_pids.each do |_pod, pid|
|
64
|
+
puts "Terminating #{_pod} #{pid}" if ENV["helm_upgrade_logs_debug"] == "true"
|
49
65
|
`kill #{pid}`
|
50
66
|
end
|
67
|
+
|
68
|
+
if ENV["helm_upgrade_logs_error_msg"]
|
69
|
+
pod_logs_files = Dir.glob("#{UPGRADE_LOG_FOLDER}/*.log")
|
70
|
+
puts "Reading logs from #{pod_logs_files.count} pod logs" if ENV["helm_upgrade_logs_debug"] == "true"
|
71
|
+
pod_logs_files.each do |log_file|
|
72
|
+
lines = File.readlines log_file
|
73
|
+
lines.each_with_index do |line, index|
|
74
|
+
next unless line.include?(ENV["helm_upgrade_logs_error_msg"])
|
75
|
+
|
76
|
+
msg = "Helm install error: #{line} from #{log_file} (Line #{index + 1})"
|
77
|
+
puts "[ERROR] #{msg}"
|
78
|
+
puts "##vso[task.logissue type=error] #{msg}" if ENV["helm_upgrade_logs_ado_error"] == "true"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
51
82
|
exit helm_status
|
data/lib/helm_upgrade_logs.rb
CHANGED
@@ -68,6 +68,13 @@ def add_ns(kube_query)
|
|
68
68
|
kube_query
|
69
69
|
end
|
70
70
|
|
71
|
+
# Add namespace to kube query
|
72
|
+
def add_ns_file(kube_query, pod)
|
73
|
+
kube_query += " -n #{@namespace}" if @namespace
|
74
|
+
kube_query += "> #{pod}.log"
|
75
|
+
kube_query
|
76
|
+
end
|
77
|
+
|
71
78
|
module HelmUpgradeLogs
|
72
79
|
class Error < StandardError; end
|
73
80
|
# 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.
|
4
|
+
version: 0.3.1
|
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-
|
11
|
+
date: 2022-06-29 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
|