helm_upgrade_logs 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +16 -2
- data/exe/helm_upgrade_logs +17 -6
- data/lib/helm_upgrade_logs/version.rb +1 -1
- data/lib/helm_upgrade_logs.rb +21 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5195e2b08d8a4c6838d8cbf16fa070551bed1953008f46873d6f41ac07c829d
|
4
|
+
data.tar.gz: 338bab0411ebc7e0a059b66392a30342187a6a9fb1ba623a3796baee331a5119
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d7b9c585181eef228e5bdaebacbc3d5d1764e6d0bbcb6aeb62db8389482f2011bba423d4d836dae44c8c16d0e2c94cab8352ef60b5376cb884b46ed2e858c75
|
7
|
+
data.tar.gz: 1417cbbe9bcbcc02501d62c30eac1b6d13b9ee8bbe060f577e2342d188539e215ea73c32d25a072bb3f401a29fd3436a5a8de524ebdd73fce829d820eed459a3
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## [0.2.3] - 2022-04-20
|
2
|
+
|
3
|
+
- Configuration on initial wait for pods logs and subsequent wait limits
|
4
|
+
|
5
|
+
## [0.2.2] - 2022-04-20
|
6
|
+
|
7
|
+
- Wait for logs on each pod having a process for logging each pod
|
8
|
+
|
1
9
|
## [0.2.0] - 2022-04-20
|
2
10
|
|
3
11
|
- Monitoring pods don't filter managed by helm as some pods don't have that with selectorLabels
|
data/README.md
CHANGED
@@ -20,7 +20,9 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
This gem is purely about an `exe` to wrap around `helm` commands and to log
|
23
|
+
This gem is purely about an `exe` to wrap around `helm` commands and to log events and pod logs that happen as
|
24
|
+
part of that release while it is being released.
|
25
|
+
|
24
26
|
Once installed, install/upgrade a helm chart with
|
25
27
|
|
26
28
|
```bash
|
@@ -29,17 +31,29 @@ helm_upgrade_logs --install redis bitnami/redis --set auth.enabled=false --versi
|
|
29
31
|
|
30
32
|
After the `helm_upgrade_logs` command put any options that would normally add after `helm upgrade`.
|
31
33
|
|
34
|
+
This library waits for logs to start in pods for 90 seconds or controlled by environment variable `helm_upgrade_logs_log_start`.
|
35
|
+
After that it waits 35 seconds for logs to start in pods after the first one.
|
36
|
+
This is controlled by environment variable `helm_upgrade_logs_pod_start`
|
37
|
+
|
32
38
|
To test a chart showing it logs, in a similar way run
|
33
39
|
```bash
|
34
40
|
helm_test_logs redis
|
35
41
|
```
|
36
42
|
|
37
|
-
|
43
|
+
### Aside bash script
|
44
|
+
|
45
|
+
This also has a bash script which can be used directly although it will probably not work on CI
|
46
|
+
and also does not close background processes so not ideal.
|
47
|
+
|
48
|
+
However if you do want to try it, to install `nginx` from the chart `bitnami/nginx` run
|
38
49
|
|
39
50
|
```
|
40
51
|
curl -s https://raw.githubusercontent.com/SamuelGarrattIqa/helm_upgrade_logs/main/bin/helm_upgrade_logs.sh | bash -s -- --install nginx bitnami/nginx
|
41
52
|
```
|
42
53
|
|
54
|
+
## TODO
|
55
|
+
* Make library handle `n`, `--namespace` from helm command
|
56
|
+
|
43
57
|
## Development
|
44
58
|
|
45
59
|
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/exe/helm_upgrade_logs
CHANGED
@@ -15,17 +15,28 @@ service_pid = Process.spawn 'kubectl get services --watch-only=true'
|
|
15
15
|
wait_for_pod_to_log
|
16
16
|
|
17
17
|
@pods = []
|
18
|
+
@pod_pids = {}
|
18
19
|
|
19
20
|
while Process.waitpid(helm_pid, Process::WNOHANG) == nil do
|
20
21
|
pods = get_pods
|
21
22
|
if pods != @pods
|
22
23
|
@pods = pods
|
23
24
|
puts "[INFO] Pods: #{pods.join(',')}"
|
24
|
-
|
25
|
-
@
|
25
|
+
# Could change this each to Parallel.each
|
26
|
+
@pods.each do |pod|
|
27
|
+
if @pod_pids[pod].nil?
|
28
|
+
wait_for_specific_pod_to_log pod
|
29
|
+
log_pid = Process.spawn "kubectl logs #{pod} -f --all-containers --prefix --ignore-errors=true --timestamps=true"
|
30
|
+
@pod_pids[pod] = log_pid
|
31
|
+
end
|
32
|
+
end
|
26
33
|
end
|
27
|
-
sleep
|
34
|
+
sleep 1
|
28
35
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
36
|
+
`kill #{event_pid}`
|
37
|
+
`kill #{service_pid}`
|
38
|
+
@pod_pids.each do |pod, pid|
|
39
|
+
`kill #{pid}`
|
40
|
+
end
|
41
|
+
|
42
|
+
|
data/lib/helm_upgrade_logs.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
require 'open3'
|
4
4
|
require_relative "helm_upgrade_logs/version"
|
5
5
|
|
6
|
+
ENV['helm_upgrade_logs_log_start'] ||= '90'
|
7
|
+
ENV['helm_upgrade_logs_pod_start'] ||= '35'
|
8
|
+
|
6
9
|
# Approach not ideal as it will for all containers to be ready and want to stream logs before that
|
7
10
|
def wait_for_container_ready
|
8
11
|
wait_pid = Process.spawn 'kubectl wait --for=condition=ContainersReady pod --selector "app.kubernetes.io/managed-by=Helm" --timeout=30s'
|
@@ -12,16 +15,29 @@ end
|
|
12
15
|
# Wait for pods with logs to be present
|
13
16
|
# Not ideal due to https://github.com/kubernetes/kubernetes/issues/28746
|
14
17
|
def wait_for_pod_to_log
|
15
|
-
|
18
|
+
ENV['helm_upgrade_logs_log_start'].to_i.times do |i|
|
19
|
+
sleep 1
|
20
|
+
stdout, stderr, _ = Open3.capture3 "kubectl logs -lapp.kubernetes.io/instance=#{$release_name}"
|
21
|
+
if stderr.empty? && !stdout.strip.empty?
|
22
|
+
puts '[INFO] Pods with logs found'
|
23
|
+
break
|
24
|
+
else
|
25
|
+
puts "[INFO] Waiting for pod logs: #{stderr}" if i % 3 == 0
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def wait_for_specific_pod_to_log(pod_name)
|
31
|
+
ENV['helm_upgrade_logs_pod_start'].to_i.times do |i|
|
16
32
|
sleep 1
|
17
|
-
stdout, stderr, _ = Open3.capture3 "kubectl logs
|
33
|
+
stdout, stderr, _ = Open3.capture3 "kubectl logs #{pod_name}"
|
18
34
|
if stderr.empty? && !stdout.strip.empty?
|
19
|
-
puts
|
35
|
+
puts "[INFO] Pod #{pod_name} with logs found"
|
20
36
|
break
|
21
37
|
else
|
22
|
-
puts "Waiting for pod logs: #{stderr}"
|
38
|
+
puts "[INFO] Waiting for pod #{pod_name} logs: #{stderr}" if i % 2 == 0
|
23
39
|
end
|
24
|
-
|
40
|
+
end
|
25
41
|
end
|
26
42
|
|
27
43
|
def get_pods
|