helm_upgrade_logs 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b684e4674b966c9d98079db28468bf57ef4001864339ee751fcac7f732f8ec6e
4
- data.tar.gz: 159438d7491016b11312941dd3fe9a7ff9a89234587243e0ce879bf5675af6f1
3
+ metadata.gz: 88dd5b1832da012298b7c2f8ce393bcc78df7b20014bc9514b37d70bb3c885fe
4
+ data.tar.gz: 4dd1b474d21f68ac9849d2523358e4550d518d81c0155d187cfe3b524b3236e7
5
5
  SHA512:
6
- metadata.gz: 9617547cfeb95b3b547196844bfa8cdfc20b33246b28c6b65b274dd2cba2a0271dfbe0574f96eb46daf50fb413ec10d6a45412d8010d94500ec3fa90710a9fcb
7
- data.tar.gz: 67e19d49ffdd9ad203de6c7adb82f4344e35fb2b8637d2e32fb6f9df83c1d552cf63506ea67e3ce2c0a714f72b2b1a841256c7d418e57356d445cfc6dc6e6c0e
6
+ metadata.gz: b6a0432ce7aee7a1a3b924e4599a0764674fb8ca3c61cab4862e51fefa57fe706dffeb15b3d9d134c22652fc65fbb5ccc4ae1e7383f78f65176bba50f93851b0
7
+ data.tar.gz: 8ddfd48e160614b8d7e3b03c6eca7699ab05b96f2ad3ecdcaa00f71981bcf5a040796d2fc689503496c3906fc9dc6a6a1a03a652e63f2190024f8bebe7e12458
@@ -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 14.0.2 --wait
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,6 +1,12 @@
1
+ ## [0.3.0]
2
+
3
+ - Log output to a file in a folder `helm_upgrade_logs` as well as STDOUT
4
+ - If `helm_upgrade_logs_error_msg` is set then rethrow error after install finished. For AzureDevOps, setting
5
+ `helm_upgrade_logs_ado_error` to `true` will raise an error in the build
6
+
1
7
  ## [0.2.6]
2
8
 
3
- -- Don't log pods existing before an upgrade
9
+ - Don't log pods existing before an upgrade
4
10
 
5
11
  ## [0.2.5] 2022-04-21
6
12
 
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
@@ -2,6 +2,7 @@
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"
7
8
 
@@ -29,6 +30,8 @@ rescue Errno::ECHILD
29
30
  raise HelmUpgradeLogs::Error, "Failed to find logs before helm finished"
30
31
  end
31
32
 
33
+ FileUtils.mkdir_p "helm_upgrade_logs"
34
+
32
35
  while Process.waitpid(@helm_pid, Process::WNOHANG).nil?
33
36
  pods = read_pods - pods_before_upgrade
34
37
  if pods != @pods
@@ -39,8 +42,15 @@ while Process.waitpid(@helm_pid, Process::WNOHANG).nil?
39
42
  next unless @pod_pids[pod].nil?
40
43
 
41
44
  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
45
+ std_out_pid = Process.spawn(
46
+ add_ns("kubectl logs #{pod} -f --all-containers --prefix --ignore-errors=true --timestamps=true")
47
+ )
48
+ logfile_pid = Process.spawn(
49
+ add_ns("kubectl logs #{pod} -f --all-containers --prefix --ignore-errors=true --timestamps=true"),
50
+ out: "helm_upgrade_logs/#{pod.gsub("/", "_")}.log"
51
+ )
52
+ @pod_pids["#{pod}_stdout"] = std_out_pid
53
+ @pod_pids["#{pod}_fileout"] = logfile_pid
44
54
  end
45
55
  end
46
56
  sleep 1
@@ -48,7 +58,23 @@ end
48
58
  helm_status = $CHILD_STATUS.exitstatus
49
59
  `kill #{event_pid}`
50
60
  `kill #{service_pid}`
61
+ puts @pod_pids if ENV["helm_upgrade_logs_debug"] == "true"
51
62
  @pod_pids.each do |_pod, pid|
63
+ puts "Terminating #{_pod} #{pid}" if ENV["helm_upgrade_logs_debug"] == "true"
52
64
  `kill #{pid}`
53
65
  end
66
+
67
+ if ENV["helm_upgrade_logs_error_msg"]
68
+ pod_logs_files = Dir.glob("helm_logs/*.log")
69
+ pod_logs_files.each do |log_file|
70
+ lines = File.readlines log_file
71
+ lines.each_with_index do |line, index|
72
+ next unless line.include?(ENV["helm_upgrade_logs_error_msg"])
73
+
74
+ msg = "Helm install error: #{line} from #{log_file} (Line #{index + 1})"
75
+ puts "[ERROR] #{msg}"
76
+ puts "##vso[task.logissue type=error] #{msg}" if ENV["helm_upgrade_logs_ado_error"] == "true"
77
+ end
78
+ end
79
+ end
54
80
  exit helm_status
@@ -2,5 +2,5 @@
2
2
 
3
3
  module HelmUpgradeLogs
4
4
  # @return [String] Version of helm upgrade logs
5
- VERSION = "0.2.6"
5
+ VERSION = "0.3.0"
6
6
  end
@@ -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.2.6
4
+ version: 0.3.0
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-21 00:00:00.000000000 Z
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