helm_upgrade_logs 0.2.4 → 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: b2dc5816493e1b7e6382d703dcc55063f5a6dd59557e233aeb8ad8f355a542c1
4
- data.tar.gz: 2d5d74dc6af95bf6ff06ee3d3c5ad7c6d76baade4d405e141c274041c8ac5914
3
+ metadata.gz: 88dd5b1832da012298b7c2f8ce393bcc78df7b20014bc9514b37d70bb3c885fe
4
+ data.tar.gz: 4dd1b474d21f68ac9849d2523358e4550d518d81c0155d187cfe3b524b3236e7
5
5
  SHA512:
6
- metadata.gz: c7ac65c07401d1a198e3e29ae710cf843b1601e0d7b4f24ae3401aa72b36e1b1bdd182e101df25bcafb01078fb8dae1af296b383b5ae77d3136ba84348d5dfc2
7
- data.tar.gz: d4a00643a7461d16198e7a9f9dec6a93f782cb8790a53efc40344a3303a2c37dcbd939b88ab5d9ff95e482593a16c53283ef0acb4cf24161593aba14b9c3812a
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,4 +1,18 @@
1
- ## [0.2.4]
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
+
7
+ ## [0.2.6]
8
+
9
+ - Don't log pods existing before an upgrade
10
+
11
+ ## [0.2.5] 2022-04-21
12
+
13
+ - Return helm status code as script's status code
14
+
15
+ ## [0.2.4] 2022-04-21
2
16
 
3
17
  - Handle `n`, `--namespace` from helm command
4
18
  - Exit if there is failure on helm command while trying to get logs
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_test_logs CHANGED
@@ -12,4 +12,6 @@ helm_pid = Process.spawn "helm test #{ARGV.join(" ")}"
12
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"))
13
13
 
14
14
  Process.wait helm_pid
15
+ helm_status = $CHILD_STATUS.exitstatus
15
16
  `kill #{log_pid}`
17
+ exit helm_status
@@ -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
 
@@ -10,6 +11,9 @@ require "helm_upgrade_logs"
10
11
 
11
12
  @helm_pid = Process.spawn "helm upgrade #{ARGV.join(" ")}"
12
13
 
14
+ pods_before_upgrade = read_pods
15
+ puts "[INFO] Pods before upgrade #{pods_before_upgrade}" if pods_before_upgrade.size.positive?
16
+
13
17
  event_pid = Process.spawn(add_ns("kubectl get events --watch-only=true"))
14
18
  service_pid = Process.spawn(add_ns("kubectl get services --watch-only=true"))
15
19
 
@@ -26,8 +30,10 @@ rescue Errno::ECHILD
26
30
  raise HelmUpgradeLogs::Error, "Failed to find logs before helm finished"
27
31
  end
28
32
 
33
+ FileUtils.mkdir_p "helm_upgrade_logs"
34
+
29
35
  while Process.waitpid(@helm_pid, Process::WNOHANG).nil?
30
- pods = read_pods
36
+ pods = read_pods - pods_before_upgrade
31
37
  if pods != @pods
32
38
  @pods = pods
33
39
  puts "[INFO] Pods: #{pods.join(",")}"
@@ -36,14 +42,39 @@ while Process.waitpid(@helm_pid, Process::WNOHANG).nil?
36
42
  next unless @pod_pids[pod].nil?
37
43
 
38
44
  wait_for_specific_pod_to_log pod
39
- log_pid = Process.spawn(add_ns("kubectl logs #{pod} -f --all-containers --prefix --ignore-errors=true --timestamps=true"))
40
- @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
41
54
  end
42
55
  end
43
56
  sleep 1
44
57
  end
58
+ helm_status = $CHILD_STATUS.exitstatus
45
59
  `kill #{event_pid}`
46
60
  `kill #{service_pid}`
61
+ puts @pod_pids if ENV["helm_upgrade_logs_debug"] == "true"
47
62
  @pod_pids.each do |_pod, pid|
63
+ puts "Terminating #{_pod} #{pid}" if ENV["helm_upgrade_logs_debug"] == "true"
48
64
  `kill #{pid}`
49
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
80
+ exit helm_status
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HelmUpgradeLogs
4
- VERSION = "0.2.4"
4
+ # @return [String] Version of helm upgrade logs
5
+ VERSION = "0.3.0"
5
6
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "open3"
4
+ require 'English'
4
5
  require_relative "helm_upgrade_logs/version"
5
6
 
6
7
  ENV["helm_upgrade_logs_log_start"] ||= "90"
@@ -67,6 +68,13 @@ def add_ns(kube_query)
67
68
  kube_query
68
69
  end
69
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
+
70
78
  module HelmUpgradeLogs
71
79
  class Error < StandardError; end
72
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.4
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-20 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