helm_upgrade_logs 0.1.4 → 0.1.7

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: 864a01e8bcbdeac4562c86337446da6a9f95915ced886c546f3914eccaca9bf9
4
- data.tar.gz: 806925901b5506f6294c5c211bd8c2df91294118441273b02af469f70938f792
3
+ metadata.gz: 612089e7637694fdb0bca10be78d1cda044a99c3925a436867f0c7efd7ab5813
4
+ data.tar.gz: 0c83667889b979ca3bcd7ccf54d74ffe5c16e750de625977c117cbd53d25b536
5
5
  SHA512:
6
- metadata.gz: 3bb83e455d0a989793547053ffbd46ad6be6fca3354405acf0d6f71c2a3ebafd9ef3a63e50efc6c8df079e163d1d7ed29757d9620459ea2798fe69deb4b2caa0
7
- data.tar.gz: a2750e80477d1024c8b05a277f3ed34541c1f7860d61640ec6873f66a37e11bf652864d3c1df1603e2b6a96de227c9de31c852b70ba2593dc410cdead1c3dc3f
6
+ metadata.gz: 1edb515198878e0f9602001bc08ba9018d657b4c1efc569a0b2e46c57ba10395a81a578cd0c57ae300ab6aee01d4e2dcd62550c1203cb64cb66cd8de3f7d7d4f
7
+ data.tar.gz: 652c953b9d59e33a58d54d880a86be9058822ca286266735016d0a1a8fffa7fc41fc51537aca66db7d24e9531fb47009336c245ed32900caec141164fbc47805
@@ -53,5 +53,7 @@ jobs:
53
53
  # run: sleep 70
54
54
  - name: Add bitnami repo
55
55
  run: helm repo add bitnami https://charts.bitnami.com/bitnami
56
- - name: Install through gem exe
56
+ - name: Install bitnami
57
57
  run: ./exe/helm_upgrade_logs --install nginx bitnami/nginx --wait --debug --set service.type=ClusterIP --set replicaCount=2
58
+ - name: Install Redis
59
+ run: ./exe/helm_upgrade_logs --install redis bitnami/redis --set auth.enabled=false --version 14.0.2 --wait
data/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
- ## [Unreleased]
1
+ ## [0.2.0] - 2022-04-20
2
+
3
+ - Monitor helm upgrade command and periodically reload getting logs when new pods appear
4
+
5
+ ## [0.1.6] - 2022-04-17
6
+
7
+ - Add `helm_test_logs` exe to check logs during `helm test`
8
+ - Add `pod-running-timeout` of 300s to try and pick up logs that might take a while to appear
9
+
10
+ ## [0.1.5] - 2022-04-16
11
+
12
+ - Only look at logs for release name
2
13
 
3
14
  ## [0.1.4] - 2022-04-16
4
15
 
data/README.md CHANGED
@@ -20,10 +20,24 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Still not working in a proper sense of a gem but the following kinda works if you want to install a release called `nginx` from the chart `bitnami/nginx`.
23
+ This gem is purely about an `exe` to wrap around `helm` commands and to log helpful commands.
24
+ Once installed, install/upgrade a helm chart with
24
25
 
26
+ ```bash
27
+ helm_upgrade_logs --install redis bitnami/redis --set auth.enabled=false --version 14.0.2 --wait
25
28
  ```
26
- curl -s https://gitlab.com/samuel-garratt/helm_upgrade_logs/-/raw/master/bin/helm_upgrade_logs.sh | bash -s -- --install nginx bitnami/nginx
29
+
30
+ After the `helm_upgrade_logs` command put any options that would normally add after `helm upgrade`.
31
+
32
+ To test a chart showing it logs, in a similar way run
33
+ ```bash
34
+ helm_test_logs redis
35
+ ```
36
+
37
+ This also has a bash script which can be used directly. E.g., to install `nginx` from the chart `bitnami/nginx`.
38
+
39
+ ```
40
+ curl -s https://raw.githubusercontent.com/SamuelGarrattIqa/helm_upgrade_logs/main/bin/helm_upgrade_logs.sh | bash -s -- --install nginx bitnami/nginx
27
41
  ```
28
42
 
29
43
  ## Development
@@ -34,7 +48,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
34
48
 
35
49
  ## Contributing
36
50
 
37
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/helm_upgrade_logs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://gitlab.com/samuel-garratt/helm_upgrade_logs/blob/master/CODE_OF_CONDUCT.md).
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SamuelGarrattIqa/helm_upgrade_logs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/SamuelGarrattIqa/helm_upgrade_logs/blob/main/CODE_OF_CONDUCT.md).
38
52
 
39
53
  ## License
40
54
 
@@ -42,4 +56,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
42
56
 
43
57
  ## Code of Conduct
44
58
 
45
- Everyone interacting in the HelmUpgradeLogs project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/samuel-garratt/helm_upgrade_logs/blob/master/CODE_OF_CONDUCT.md).
59
+ Everyone interacting in the HelmUpgradeLogs project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/SamuelGarrattIqa/helm_upgrade_logs/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
5
+ require 'helm_upgrade_logs'
6
+
7
+ $release_name = ARGV.find { |arg| !arg.start_with?('-') }
8
+
9
+ helm_pid = Process.spawn "helm test #{ARGV.join(' ')}"
10
+
11
+ log_pid = Process.spawn "kubectl logs -lapp.kubernetes.io/managed-by=Helm,app.kubernetes.io/instance=#{$release_name} -f --all-containers --prefix --ignore-errors=true --max-log-requests=20 --timestamps=true"
12
+
13
+ Process.wait helm_pid
14
+ puts `kill #{log_pid}`
@@ -5,36 +5,27 @@ require 'open3'
5
5
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
6
6
  require 'helm_upgrade_logs'
7
7
 
8
- # Approach not ideal as it will for all containers to be ready and want to stream logs before that
9
- def wait_for_container_ready
10
- wait_pid = Process.spawn 'kubectl wait --for=condition=ContainersReady pod --selector "app.kubernetes.io/managed-by=Helm" --timeout=30s'
11
- Process.wait wait_pid
12
- end
13
-
14
- # Wait for pods with logs to be present
15
- # Not ideal due to https://github.com/kubernetes/kubernetes/issues/28746
16
- def wait_for_pod
17
- 90.times {
18
- sleep 1
19
- stdout, stderr, _ = Open3.capture3 "kubectl logs -lapp.kubernetes.io/managed-by=Helm"
20
- if stderr.empty? && !stdout.strip.empty?
21
- puts 'Pods with logs found'
22
- break
23
- else
24
- puts "Waiting for pod logs: #{stderr}"
25
- end
26
- }
27
- end
8
+ $release_name = ARGV.find { |arg| !arg.start_with?('-') }
28
9
 
29
10
  helm_pid = Process.spawn "helm upgrade #{ARGV.join(' ')}"
30
11
 
31
12
  event_pid = Process.spawn 'kubectl get events --watch-only=true'
32
13
  service_pid = Process.spawn 'kubectl get services --watch-only=true'
33
14
 
34
- wait_for_pod
35
- log_pid = Process.spawn 'kubectl logs -lapp.kubernetes.io/managed-by=Helm -f --all-containers --prefix --pod-running-timeout=20s --ignore-errors=true --max-log-requests=20 --timestamps=true'
15
+ wait_for_pod_to_log
36
16
 
37
- Process.wait helm_pid
38
- puts `kill #{log_pid}`
17
+ @pods = []
18
+
19
+ while Process.waitpid(helm_pid, Process::WNOHANG) == nil do
20
+ pods = get_pods
21
+ if pods != @pods
22
+ @pods = pods
23
+ puts "[INFO] Pods: #{pods.join(',')}"
24
+ puts `kill #{@log_pid}` if @log_pid
25
+ @log_pid = Process.spawn "kubectl logs -lapp.kubernetes.io/managed-by=Helm,app.kubernetes.io/instance=#{$release_name} -f --all-containers --prefix --ignore-errors=true --max-log-requests=20 --timestamps=true --since=0s"
26
+ end
27
+ sleep 2.5
28
+ end
29
+ puts `kill #{@log_pid}`
39
30
  puts `kill #{event_pid}`
40
31
  puts `kill #{service_pid}`
data/get_pods.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'open3'
2
+
3
+ $release_name = 'redis'
4
+ stdout, stderr, _ = Open3.capture3 "kubectl get pods -lapp.kubernetes.io/managed-by=Helm,app.kubernetes.io/instance=#{$release_name} -o name"
5
+ if stderr.empty?
6
+ puts stdout.lines.join(',')
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HelmUpgradeLogs
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.7"
5
5
  end
@@ -1,7 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'open3'
3
4
  require_relative "helm_upgrade_logs/version"
4
5
 
6
+ # Approach not ideal as it will for all containers to be ready and want to stream logs before that
7
+ def wait_for_container_ready
8
+ wait_pid = Process.spawn 'kubectl wait --for=condition=ContainersReady pod --selector "app.kubernetes.io/managed-by=Helm" --timeout=30s'
9
+ Process.wait wait_pid
10
+ end
11
+
12
+ # Wait for pods with logs to be present
13
+ # Not ideal due to https://github.com/kubernetes/kubernetes/issues/28746
14
+ def wait_for_pod_to_log
15
+ 90.times {
16
+ sleep 1
17
+ stdout, stderr, _ = Open3.capture3 "kubectl logs -lapp.kubernetes.io/managed-by=Helm,app.kubernetes.io/instance=#{$release_name}"
18
+ if stderr.empty? && !stdout.strip.empty?
19
+ puts 'Pods with logs found'
20
+ break
21
+ else
22
+ puts "Waiting for pod logs: #{stderr}"
23
+ end
24
+ }
25
+ end
26
+
27
+ def get_pods
28
+ stdout, stderr, _ = Open3.capture3 "kubectl get pods -lapp.kubernetes.io/managed-by=Helm,app.kubernetes.io/instance=#{$release_name} -o name"
29
+ if stderr.empty?
30
+ stdout.lines.collect { |pod| pod.strip }
31
+ else
32
+ []
33
+ end
34
+ end
35
+
5
36
  module HelmUpgradeLogs
6
37
  class Error < StandardError; end
7
38
  # Your code goes here...
metadata CHANGED
@@ -1,20 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helm_upgrade_logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.7
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-16 00:00:00.000000000 Z
11
+ date: 2022-04-20 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
15
15
  email:
16
16
  - samuel.garratt@sentify.co
17
17
  executables:
18
+ - helm_test_logs
18
19
  - helm_upgrade_logs
19
20
  extensions: []
20
21
  extra_rdoc_files: []
@@ -38,7 +39,9 @@ files:
38
39
  - bin/helm_upgrade_logs.sh
39
40
  - bin/setup
40
41
  - bin/start_kind.sh
42
+ - exe/helm_test_logs
41
43
  - exe/helm_upgrade_logs
44
+ - get_pods.rb
42
45
  - helm_upgrade_logs.gemspec
43
46
  - lib/helm_upgrade_logs.rb
44
47
  - lib/helm_upgrade_logs/version.rb