helm_upgrade_logs 0.1.0 → 0.1.3
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 +58 -0
- data/.gitignore +1 -0
- data/.idea/helm_upgrade_logs.iml +1 -0
- data/README.md +9 -7
- data/bin/helm_upgrade_logs.sh +230 -0
- data/bin/start_kind.sh +75 -0
- data/exe/helm_upgrade_logs +13 -225
- data/lib/helm_upgrade_logs/version.rb +1 -1
- metadata +5 -3
- data/.idea/workspace.xml +0 -78
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e1693edf80c97ce84e886a2dda47c1207768e259d2b805ad48a005aebf162c3
|
4
|
+
data.tar.gz: a22c8c807b6fc7142d105f17c3481d8c166519e223cc02cb3663f28ac27c2708
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3a5490f5fe25c03051980d54b750cb8ba23402cf0a8c168e2230d8b7be5235c74f9d2160860de1270c0641b1465020a7ce9a3d61b4ec0758fbd0e88ed01c9f2
|
7
|
+
data.tar.gz: 9fc06039f972617e254b788ae850fe36d386176cac5ceceb585b113e9cc76e842558ee2460d0ac5f349469eaef2615d350958aec0aca72e603ef6b4cac5e2fb6
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: HelmUpgradeLogs
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
permissions:
|
17
|
+
contents: read
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
test:
|
21
|
+
|
22
|
+
runs-on: ubuntu-latest
|
23
|
+
strategy:
|
24
|
+
matrix:
|
25
|
+
ruby-version: ['3.0']
|
26
|
+
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v3
|
29
|
+
- name: Start KIND cluster
|
30
|
+
run: bash -f bin/start_kind.sh
|
31
|
+
- name: Waiting for KIND cluster to get ready
|
32
|
+
run: sleep 70
|
33
|
+
- name: Add bitnami repo
|
34
|
+
run: helm repo add bitnami https://charts.bitnami.com/bitnami
|
35
|
+
- name: Install through gem exe
|
36
|
+
run: ./exe/helm_upgrade_logs --install nginx bitnami/nginx --wait --debug --set service.type=ClusterIP --replicaCount=2
|
37
|
+
# - name: Check pods
|
38
|
+
# run: kubectl get pods --all-namespaces
|
39
|
+
# - name: Check Events
|
40
|
+
# run: kubectl get events --all-namespaces
|
41
|
+
#
|
42
|
+
# - name: Check logs
|
43
|
+
# run: kubectl logs -lapp.kubernetes.io/managed-by=Helm -f
|
44
|
+
# - name: helm upgrade install
|
45
|
+
# run: helm upgrade --install nginx bitnami/nginx --wait --debug --set service.type=ClusterIP
|
46
|
+
# continue-on-error: true
|
47
|
+
# - name: Check pods
|
48
|
+
# run: sleep 15 && kubectl get pods --all-namespaces
|
49
|
+
# - name: Check Events
|
50
|
+
# run: sleep 7 && kubectl get events --all-namespaces
|
51
|
+
# - name: Run from local
|
52
|
+
# run: bash bin/helm_upgrade_logs.sh --install nginx2 bitnami/nginx --wait --debug --set service.type=ClusterIP
|
53
|
+
|
54
|
+
# - name: Helm upgrade with logs
|
55
|
+
# run: curl -s https://raw.githubusercontent.com/SamuelGarrattIqa/helm_upgrade_logs/main/exe/helm_upgrade_logs | bash -s -- --install nginx2 bitnami/nginx --wait
|
56
|
+
|
57
|
+
# - name: Run tests
|
58
|
+
# run: bundle exec rake
|
data/.gitignore
CHANGED
data/.idea/helm_upgrade_logs.iml
CHANGED
@@ -12,6 +12,7 @@
|
|
12
12
|
<orderEntry type="jdk" jdkName="RVM: ruby-3.0.0" jdkType="RUBY_SDK" />
|
13
13
|
<orderEntry type="sourceFolder" forTests="false" />
|
14
14
|
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, RVM: ruby-3.0.0) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.11, RVM: ruby-3.0.0) [gem]" level="application" />
|
15
16
|
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, RVM: ruby-3.0.0) [gem]" level="application" />
|
16
17
|
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.21.0, RVM: ruby-3.0.0) [gem]" level="application" />
|
17
18
|
<orderEntry type="library" scope="PROVIDED" name="parser (v3.1.0.0, RVM: ruby-3.0.0) [gem]" level="application" />
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# Helm Upgrade Logs
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Idea is to show logs of pods and events while doing a kubernetes helm install or upgrade.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,11 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
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`.
|
24
|
+
|
25
|
+
```
|
26
|
+
curl -s https://gitlab.com/samuel-garratt/helm_upgrade_logs/-/raw/master/bin/helm_upgrade_logs.sh | bash -s -- --install nginx bitnami/nginx
|
27
|
+
```
|
26
28
|
|
27
29
|
## Development
|
28
30
|
|
@@ -32,7 +34,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
34
|
|
33
35
|
## Contributing
|
34
36
|
|
35
|
-
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://
|
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).
|
36
38
|
|
37
39
|
## License
|
38
40
|
|
@@ -40,4 +42,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
40
42
|
|
41
43
|
## Code of Conduct
|
42
44
|
|
43
|
-
Everyone interacting in the HelmUpgradeLogs project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://
|
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).
|
@@ -0,0 +1,230 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -euo pipefail
|
4
|
+
|
5
|
+
if [[ -n "${DOTFILES_DEBUG:-}" ]]; then
|
6
|
+
set -x
|
7
|
+
fi
|
8
|
+
|
9
|
+
function ensure_path_entry() {
|
10
|
+
local entries=("$@")
|
11
|
+
|
12
|
+
for entry in "${entries[@]}"; do
|
13
|
+
if [[ ":${PATH}:" != *":${entry}:"* ]]; then
|
14
|
+
export PATH="${entry}:${PATH}"
|
15
|
+
fi
|
16
|
+
done
|
17
|
+
}
|
18
|
+
|
19
|
+
function log_color() {
|
20
|
+
local color_code="$1"
|
21
|
+
shift
|
22
|
+
|
23
|
+
printf "\033[${color_code}m%s\033[0m\n" "$*" >&2
|
24
|
+
}
|
25
|
+
|
26
|
+
function log_red() {
|
27
|
+
log_color "0;31" "$@"
|
28
|
+
}
|
29
|
+
|
30
|
+
function log_blue() {
|
31
|
+
log_color "0;34" "$@"
|
32
|
+
}
|
33
|
+
|
34
|
+
function log_green() {
|
35
|
+
log_color "1;32" "$@"
|
36
|
+
}
|
37
|
+
|
38
|
+
function log_yellow() {
|
39
|
+
log_color "1;33" "$@"
|
40
|
+
}
|
41
|
+
|
42
|
+
function log_task() {
|
43
|
+
log_blue "🔃" "$@"
|
44
|
+
}
|
45
|
+
|
46
|
+
function log_manual_action() {
|
47
|
+
log_red "⚠️" "$@"
|
48
|
+
}
|
49
|
+
|
50
|
+
function log_c() {
|
51
|
+
log_yellow "👉" "$@"
|
52
|
+
}
|
53
|
+
|
54
|
+
function c() {
|
55
|
+
log_c "$@"
|
56
|
+
"$@"
|
57
|
+
}
|
58
|
+
|
59
|
+
function c_exec() {
|
60
|
+
log_c "$@"
|
61
|
+
exec "$@"
|
62
|
+
}
|
63
|
+
|
64
|
+
function log_error() {
|
65
|
+
log_red "❌" "$@"
|
66
|
+
}
|
67
|
+
|
68
|
+
function log_info() {
|
69
|
+
log_red "ℹ️" "$@"
|
70
|
+
}
|
71
|
+
|
72
|
+
function error() {
|
73
|
+
log_error "$@"
|
74
|
+
exit 1
|
75
|
+
}
|
76
|
+
|
77
|
+
function sudo() {
|
78
|
+
if ! command sudo --non-interactive true 2>/dev/null; then
|
79
|
+
log_manual_action "Root privileges are required, please enter your password below"
|
80
|
+
command sudo --validate
|
81
|
+
fi
|
82
|
+
command sudo "$@"
|
83
|
+
}
|
84
|
+
|
85
|
+
function is_apt_package_installed() {
|
86
|
+
local package="$1"
|
87
|
+
|
88
|
+
dpkg -l "${package}" &>/dev/null
|
89
|
+
}
|
90
|
+
|
91
|
+
function not_during_test() {
|
92
|
+
if [[ "${DOTFILES_TEST:-}" == "true" ]]; then
|
93
|
+
log_info "Skipping '${*}' because we are in test mode"
|
94
|
+
else
|
95
|
+
"${@}"
|
96
|
+
fi
|
97
|
+
}
|
98
|
+
|
99
|
+
# https://stackoverflow.com/a/53640320/12156188
|
100
|
+
function service_exists() {
|
101
|
+
local n=$1
|
102
|
+
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then
|
103
|
+
return 0
|
104
|
+
else
|
105
|
+
return 1
|
106
|
+
fi
|
107
|
+
}
|
108
|
+
|
109
|
+
################################################################
|
110
|
+
## ABOVE is script_libray
|
111
|
+
## BELOW is helm install debug
|
112
|
+
################################################################
|
113
|
+
|
114
|
+
mkdir helm_upgrade_log_tmp
|
115
|
+
watching_pods_logs_file=$(mktemp helm_upgrade_log_tmp/helm-upgrade-logs.watching-pods-logs.XXXXXX)
|
116
|
+
watching_pods_events_file=$(mktemp helm_upgrade_log_tmp/helm-upgrade-logs.watching-pods-events.XXXXXX)
|
117
|
+
|
118
|
+
function cleanup() {
|
119
|
+
rm -f "${watching_pods_logs_file}" "${watching_pods_events_file}" || true
|
120
|
+
jobs -pr | xargs -r kill
|
121
|
+
}
|
122
|
+
|
123
|
+
trap cleanup EXIT
|
124
|
+
|
125
|
+
function prefix_output() {
|
126
|
+
local prefix="$1"
|
127
|
+
local color_code="$2"
|
128
|
+
shift 2
|
129
|
+
|
130
|
+
local sed_replace
|
131
|
+
sed_replace=$(printf "\033[${color_code}m%s: &\033[0m" "${prefix}")
|
132
|
+
|
133
|
+
# shellcheck disable=SC2312
|
134
|
+
"$@" &> >(sed "s,^.*$,${sed_replace}," >&2)
|
135
|
+
}
|
136
|
+
|
137
|
+
function watch_pods() {
|
138
|
+
local release="$1"
|
139
|
+
|
140
|
+
sleep 3 # Prevent flodding the logs with the initial output
|
141
|
+
prefix_output "pods" "1;32" c kubectl get pods \
|
142
|
+
--watch \
|
143
|
+
--selector "app.kubernetes.io/managed-by=Helm,app.kubernetes.io/instance=${release}"
|
144
|
+
}
|
145
|
+
|
146
|
+
function watch_pod_logs() {
|
147
|
+
local pod="$1"
|
148
|
+
|
149
|
+
if grep -q "^${pod}$" "${watching_pods_logs_file}"; then
|
150
|
+
return
|
151
|
+
fi
|
152
|
+
|
153
|
+
echo "${pod}" >>"${watching_pods_logs_file}"
|
154
|
+
|
155
|
+
prefix_output "pod ${pod} logs" "0;34" c kubectl logs \
|
156
|
+
--all-containers \
|
157
|
+
--prefix \
|
158
|
+
--follow \
|
159
|
+
"${pod}" || true
|
160
|
+
|
161
|
+
# remove from watch list (it may be added again)
|
162
|
+
sed -i "/^${pod}$/d" "${watching_pods_logs_file}"
|
163
|
+
}
|
164
|
+
|
165
|
+
function watch_pod_events() {
|
166
|
+
local pod="$1"
|
167
|
+
|
168
|
+
if grep -q "^${pod}$" "${watching_pods_events_file}"; then
|
169
|
+
return
|
170
|
+
fi
|
171
|
+
|
172
|
+
echo "${pod}" >>"${watching_pods_events_file}"
|
173
|
+
|
174
|
+
prefix_output "pod ${pod} events" "0;35" c kubectl get events \
|
175
|
+
--watch-only \
|
176
|
+
--field-selector involvedObject.name="${pod}" || true
|
177
|
+
|
178
|
+
# remove from watch list (it may be added again)
|
179
|
+
sed -i "/^${pod}$/d" "${watching_pods_events_file}"
|
180
|
+
}
|
181
|
+
|
182
|
+
function watch_pods_logs_and_events() {
|
183
|
+
local release="$1"
|
184
|
+
|
185
|
+
sleep 5 # Prevent flodding the logs with the initial output
|
186
|
+
while true; do
|
187
|
+
local args=(
|
188
|
+
--selector "app.kubernetes.io/managed-by=Helm,app.kubernetes.io/instance=${release}"
|
189
|
+
--output jsonpath='{.items[*].metadata.name}'
|
190
|
+
)
|
191
|
+
|
192
|
+
for pod in $(
|
193
|
+
kubectl get pods "${args[@]}"
|
194
|
+
); do
|
195
|
+
watch_pod_events "${pod}" &
|
196
|
+
done
|
197
|
+
|
198
|
+
for pod in $(
|
199
|
+
kubectl get pods \
|
200
|
+
--field-selector=status.phase=Running \
|
201
|
+
"${args[@]}"
|
202
|
+
); do
|
203
|
+
watch_pod_logs "${pod}" &
|
204
|
+
done
|
205
|
+
|
206
|
+
sleep 1
|
207
|
+
done
|
208
|
+
}
|
209
|
+
|
210
|
+
function get_first_non_option() {
|
211
|
+
for arg in "$@"; do
|
212
|
+
if [[ "${arg}" != "-"* ]]; then
|
213
|
+
echo "${arg}"
|
214
|
+
return
|
215
|
+
fi
|
216
|
+
done
|
217
|
+
}
|
218
|
+
|
219
|
+
release="$(get_first_non_option "$@")"
|
220
|
+
|
221
|
+
c helm upgrade "$@" --wait &
|
222
|
+
pid="$!"
|
223
|
+
|
224
|
+
watch_pods "${release}" &
|
225
|
+
|
226
|
+
watch_pods_logs_and_events "${release}" &
|
227
|
+
|
228
|
+
wait "${pid}"
|
229
|
+
kill $(jobs -p)
|
230
|
+
rm -rf helm_upgrade_log_tmp
|
data/bin/start_kind.sh
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
#/bin/bash
|
2
|
+
set +x
|
3
|
+
set -e
|
4
|
+
|
5
|
+
###########################################################################
|
6
|
+
# Usage: bash -f ./start.sh
|
7
|
+
# Supported Options -
|
8
|
+
# --kind-cluster-name=<Kind Cluster Name> (default INTEGRATION_TEST_CLUSTER)
|
9
|
+
# --kind-version (default v0.7.0)
|
10
|
+
# --kubectl-version (default v1.18.0)
|
11
|
+
# --helm-version (default v3.2.0)
|
12
|
+
###########################################################################
|
13
|
+
|
14
|
+
# All Supported Arguments
|
15
|
+
ARGUMENT_LIST=(
|
16
|
+
"kind-cluster-name"
|
17
|
+
"kind-version"
|
18
|
+
"kubectl-version"
|
19
|
+
"helm-version"
|
20
|
+
)
|
21
|
+
|
22
|
+
# Read Arguments
|
23
|
+
opts=$(getopt \
|
24
|
+
--longoptions "$(printf "%s:," "${ARGUMENT_LIST[@]}")" \
|
25
|
+
--name "$(basename "$0")" \
|
26
|
+
--options "" \
|
27
|
+
-- "$@"
|
28
|
+
)
|
29
|
+
|
30
|
+
# Assign Values from Arguments
|
31
|
+
eval set --$opts
|
32
|
+
while [[ $# -gt 0 ]]; do
|
33
|
+
case "$1" in
|
34
|
+
--kind-cluster-name)
|
35
|
+
CLUSTER_NAME=$2
|
36
|
+
shift 2
|
37
|
+
;;
|
38
|
+
--kind-version)
|
39
|
+
KIND_VERSION=$2
|
40
|
+
shift 2
|
41
|
+
;;
|
42
|
+
--kubectl-version)
|
43
|
+
KUBECTL_VERSION=$2
|
44
|
+
shift 2
|
45
|
+
;;
|
46
|
+
--helm-version)
|
47
|
+
HELM_VERSION=$2
|
48
|
+
shift 2
|
49
|
+
;;
|
50
|
+
*)
|
51
|
+
break
|
52
|
+
;;
|
53
|
+
esac
|
54
|
+
done
|
55
|
+
|
56
|
+
# Assign Deafults
|
57
|
+
CLUSTER_NAME=${CLUSTER_NAME:-"testcluster"} # NOT USING THIS. Does not provide benefit for 1 cluster on kind
|
58
|
+
KIND_VERSION=${KIND_VERSION:-v0.11.0}
|
59
|
+
KUBECTL_VERSION=${KUBECTL_VERSION:-v1.20.4}
|
60
|
+
HELM_VERSION=${HELM_VERSION:-v3.8.0}
|
61
|
+
|
62
|
+
echo $(date -u) "[INFO] Downloading Kubectl ..."
|
63
|
+
curl -LO https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl
|
64
|
+
chmod +x ./kubectl
|
65
|
+
|
66
|
+
echo $(date -u) "[INFO] Downloading KIND ..."
|
67
|
+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-$(uname)-amd64
|
68
|
+
chmod +x ./kind
|
69
|
+
|
70
|
+
echo $(date -u) "[INFO] Downloading helm ..."
|
71
|
+
wget https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz
|
72
|
+
tar -zxvf helm-${HELM_VERSION}-linux-amd64.tar.gz
|
73
|
+
|
74
|
+
echo $(date -u) "[INFO] Creating a KIND cluster ..."
|
75
|
+
./kind create cluster
|
data/exe/helm_upgrade_logs
CHANGED
@@ -1,229 +1,17 @@
|
|
1
|
-
#!/bin/
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
|
4
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
5
|
+
require 'helm_upgrade_logs'
|
4
6
|
|
5
|
-
|
6
|
-
set -x
|
7
|
-
fi
|
7
|
+
helm_pid = Process.spawn "helm upgrade #{ARGV.join(' ')}"
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
event_pid = Process.spawn 'kubectl get events --watch-only=true'
|
10
|
+
service_pid = Process.spawn 'kubectl get services --watch-only=true'
|
11
|
+
sleep 5
|
12
|
+
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'
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
done
|
17
|
-
}
|
18
|
-
|
19
|
-
function log_color() {
|
20
|
-
local color_code="$1"
|
21
|
-
shift
|
22
|
-
|
23
|
-
printf "\033[${color_code}m%s\033[0m\n" "$*" >&2
|
24
|
-
}
|
25
|
-
|
26
|
-
function log_red() {
|
27
|
-
log_color "0;31" "$@"
|
28
|
-
}
|
29
|
-
|
30
|
-
function log_blue() {
|
31
|
-
log_color "0;34" "$@"
|
32
|
-
}
|
33
|
-
|
34
|
-
function log_green() {
|
35
|
-
log_color "1;32" "$@"
|
36
|
-
}
|
37
|
-
|
38
|
-
function log_yellow() {
|
39
|
-
log_color "1;33" "$@"
|
40
|
-
}
|
41
|
-
|
42
|
-
function log_task() {
|
43
|
-
log_blue "🔃" "$@"
|
44
|
-
}
|
45
|
-
|
46
|
-
function log_manual_action() {
|
47
|
-
log_red "⚠️" "$@"
|
48
|
-
}
|
49
|
-
|
50
|
-
function log_c() {
|
51
|
-
log_yellow "👉" "$@"
|
52
|
-
}
|
53
|
-
|
54
|
-
function c() {
|
55
|
-
log_c "$@"
|
56
|
-
"$@"
|
57
|
-
}
|
58
|
-
|
59
|
-
function c_exec() {
|
60
|
-
log_c "$@"
|
61
|
-
exec "$@"
|
62
|
-
}
|
63
|
-
|
64
|
-
function log_error() {
|
65
|
-
log_red "❌" "$@"
|
66
|
-
}
|
67
|
-
|
68
|
-
function log_info() {
|
69
|
-
log_red "ℹ️" "$@"
|
70
|
-
}
|
71
|
-
|
72
|
-
function error() {
|
73
|
-
log_error "$@"
|
74
|
-
exit 1
|
75
|
-
}
|
76
|
-
|
77
|
-
function sudo() {
|
78
|
-
if ! command sudo --non-interactive true 2>/dev/null; then
|
79
|
-
log_manual_action "Root privileges are required, please enter your password below"
|
80
|
-
command sudo --validate
|
81
|
-
fi
|
82
|
-
command sudo "$@"
|
83
|
-
}
|
84
|
-
|
85
|
-
function is_apt_package_installed() {
|
86
|
-
local package="$1"
|
87
|
-
|
88
|
-
dpkg -l "${package}" &>/dev/null
|
89
|
-
}
|
90
|
-
|
91
|
-
function not_during_test() {
|
92
|
-
if [[ "${DOTFILES_TEST:-}" == "true" ]]; then
|
93
|
-
log_info "Skipping '${*}' because we are in test mode"
|
94
|
-
else
|
95
|
-
"${@}"
|
96
|
-
fi
|
97
|
-
}
|
98
|
-
|
99
|
-
# https://stackoverflow.com/a/53640320/12156188
|
100
|
-
function service_exists() {
|
101
|
-
local n=$1
|
102
|
-
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then
|
103
|
-
return 0
|
104
|
-
else
|
105
|
-
return 1
|
106
|
-
fi
|
107
|
-
}
|
108
|
-
|
109
|
-
################################################################
|
110
|
-
## ABOVE is script_libray
|
111
|
-
## BELOW is helm install debug
|
112
|
-
################################################################
|
113
|
-
|
114
|
-
mkdir helm_upgrade_log_tmp
|
115
|
-
watching_pods_logs_file=$(mktemp helm_upgrade_log_tmp/helm-upgrade-logs.watching-pods-logs.XXXXXX)
|
116
|
-
watching_pods_events_file=$(mktemp helm_upgrade_log_tmp/helm-upgrade-logs.watching-pods-events.XXXXXX)
|
117
|
-
|
118
|
-
function cleanup() {
|
119
|
-
rm -f "${watching_pods_logs_file}" "${watching_pods_events_file}" || true
|
120
|
-
jobs -pr | xargs -r kill
|
121
|
-
}
|
122
|
-
|
123
|
-
trap cleanup EXIT
|
124
|
-
|
125
|
-
function prefix_output() {
|
126
|
-
local prefix="$1"
|
127
|
-
local color_code="$2"
|
128
|
-
shift 2
|
129
|
-
|
130
|
-
local sed_replace
|
131
|
-
sed_replace=$(printf "\033[${color_code}m%s: &\033[0m" "${prefix}")
|
132
|
-
|
133
|
-
# shellcheck disable=SC2312
|
134
|
-
"$@" &> >(sed "s,^.*$,${sed_replace}," >&2)
|
135
|
-
}
|
136
|
-
|
137
|
-
function watch_pods() {
|
138
|
-
local release="$1"
|
139
|
-
|
140
|
-
sleep 3 # Prevent flodding the logs with the initial output
|
141
|
-
prefix_output "pods" "1;32" c kubectl get pods \
|
142
|
-
--watch \
|
143
|
-
--selector "app.kubernetes.io/managed-by=Helm,app.kubernetes.io/instance=${release}"
|
144
|
-
}
|
145
|
-
|
146
|
-
function watch_pod_logs() {
|
147
|
-
local pod="$1"
|
148
|
-
|
149
|
-
if grep -q "^${pod}$" "${watching_pods_logs_file}"; then
|
150
|
-
return
|
151
|
-
fi
|
152
|
-
|
153
|
-
echo "${pod}" >>"${watching_pods_logs_file}"
|
154
|
-
|
155
|
-
prefix_output "pod ${pod} logs" "0;34" c kubectl logs \
|
156
|
-
--all-containers \
|
157
|
-
--prefix \
|
158
|
-
--follow \
|
159
|
-
"${pod}" || true
|
160
|
-
|
161
|
-
# remove from watch list (it may be added again)
|
162
|
-
sed -i "/^${pod}$/d" "${watching_pods_logs_file}"
|
163
|
-
}
|
164
|
-
|
165
|
-
function watch_pod_events() {
|
166
|
-
local pod="$1"
|
167
|
-
|
168
|
-
if grep -q "^${pod}$" "${watching_pods_events_file}"; then
|
169
|
-
return
|
170
|
-
fi
|
171
|
-
|
172
|
-
echo "${pod}" >>"${watching_pods_events_file}"
|
173
|
-
|
174
|
-
prefix_output "pod ${pod} events" "0;35" c kubectl get events \
|
175
|
-
--watch-only \
|
176
|
-
--field-selector involvedObject.name="${pod}" || true
|
177
|
-
|
178
|
-
# remove from watch list (it may be added again)
|
179
|
-
sed -i "/^${pod}$/d" "${watching_pods_events_file}"
|
180
|
-
}
|
181
|
-
|
182
|
-
function watch_pods_logs_and_events() {
|
183
|
-
local release="$1"
|
184
|
-
|
185
|
-
sleep 5 # Prevent flodding the logs with the initial output
|
186
|
-
while true; do
|
187
|
-
local args=(
|
188
|
-
--selector "app.kubernetes.io/managed-by=Helm,app.kubernetes.io/instance=${release}"
|
189
|
-
--output jsonpath='{.items[*].metadata.name}'
|
190
|
-
)
|
191
|
-
|
192
|
-
for pod in $(
|
193
|
-
kubectl get pods "${args[@]}"
|
194
|
-
); do
|
195
|
-
watch_pod_events "${pod}" &
|
196
|
-
done
|
197
|
-
|
198
|
-
for pod in $(
|
199
|
-
kubectl get pods \
|
200
|
-
--field-selector=status.phase=Running \
|
201
|
-
"${args[@]}"
|
202
|
-
); do
|
203
|
-
watch_pod_logs "${pod}" &
|
204
|
-
done
|
205
|
-
|
206
|
-
sleep 1
|
207
|
-
done
|
208
|
-
}
|
209
|
-
|
210
|
-
function get_first_non_option() {
|
211
|
-
for arg in "$@"; do
|
212
|
-
if [[ "${arg}" != "-"* ]]; then
|
213
|
-
echo "${arg}"
|
214
|
-
return
|
215
|
-
fi
|
216
|
-
done
|
217
|
-
}
|
218
|
-
|
219
|
-
release="$(get_first_non_option "$@")"
|
220
|
-
|
221
|
-
c helm upgrade "$@" --wait &
|
222
|
-
pid="$!"
|
223
|
-
|
224
|
-
watch_pods "${release}" &
|
225
|
-
|
226
|
-
watch_pods_logs_and_events "${release}" &
|
227
|
-
|
228
|
-
wait "${pid}"
|
229
|
-
rm -rf helm_upgrade_log_tmp
|
14
|
+
Process.wait helm_pid
|
15
|
+
puts `kill #{log_pid}`
|
16
|
+
puts `kill #{event_pid}`
|
17
|
+
puts `kill #{service_pid}`
|
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.1.
|
4
|
+
version: 0.1.3
|
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-
|
11
|
+
date: 2022-04-15 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
|
@@ -19,13 +19,13 @@ executables:
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
+
- ".github/workflows/test.yml"
|
22
23
|
- ".gitignore"
|
23
24
|
- ".gitlab-ci.yml"
|
24
25
|
- ".idea/helm_upgrade_logs.iml"
|
25
26
|
- ".idea/misc.xml"
|
26
27
|
- ".idea/modules.xml"
|
27
28
|
- ".idea/vcs.xml"
|
28
|
-
- ".idea/workspace.xml"
|
29
29
|
- ".rspec"
|
30
30
|
- ".rubocop.yml"
|
31
31
|
- CHANGELOG.md
|
@@ -35,7 +35,9 @@ files:
|
|
35
35
|
- README.md
|
36
36
|
- Rakefile
|
37
37
|
- bin/console
|
38
|
+
- bin/helm_upgrade_logs.sh
|
38
39
|
- bin/setup
|
40
|
+
- bin/start_kind.sh
|
39
41
|
- exe/helm_upgrade_logs
|
40
42
|
- helm_upgrade_logs.gemspec
|
41
43
|
- lib/helm_upgrade_logs.rb
|
data/.idea/workspace.xml
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<project version="4">
|
3
|
-
<component name="ChangeListManager">
|
4
|
-
<list default="true" id="da917fa3-f5ef-4365-9d07-5ed3fa5f86fb" name="Default Changelist" comment="">
|
5
|
-
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
6
|
-
<change beforePath="$PROJECT_DIR$/.idea/helm_upgrade_logs.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/helm_upgrade_logs.iml" afterDir="false" />
|
7
|
-
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
8
|
-
<change beforePath="$PROJECT_DIR$/helm_upgrade_logs.gemspec" beforeDir="false" afterPath="$PROJECT_DIR$/helm_upgrade_logs.gemspec" afterDir="false" />
|
9
|
-
<change beforePath="$PROJECT_DIR$/spec/helm_upgrade_logs_spec.rb" beforeDir="false" afterPath="$PROJECT_DIR$/spec/helm_upgrade_logs_spec.rb" afterDir="false" />
|
10
|
-
</list>
|
11
|
-
<option name="SHOW_DIALOG" value="false" />
|
12
|
-
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
13
|
-
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
14
|
-
<option name="LAST_RESOLUTION" value="IGNORE" />
|
15
|
-
</component>
|
16
|
-
<component name="Git.Settings">
|
17
|
-
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
18
|
-
</component>
|
19
|
-
<component name="ProjectId" id="27mcv3bOSxXTerfL7qGu8qJxnE6" />
|
20
|
-
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
21
|
-
<component name="ProjectViewState">
|
22
|
-
<option name="hideEmptyMiddlePackages" value="true" />
|
23
|
-
<option name="showExcludedFiles" value="true" />
|
24
|
-
<option name="showLibraryContents" value="true" />
|
25
|
-
</component>
|
26
|
-
<component name="PropertiesComponent">
|
27
|
-
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
28
|
-
<property name="WebServerToolWindowFactoryState" value="false" />
|
29
|
-
</component>
|
30
|
-
<component name="ServiceViewManager">
|
31
|
-
<option name="viewStates">
|
32
|
-
<list>
|
33
|
-
<serviceView>
|
34
|
-
<treeState>
|
35
|
-
<expand />
|
36
|
-
<select />
|
37
|
-
</treeState>
|
38
|
-
</serviceView>
|
39
|
-
</list>
|
40
|
-
</option>
|
41
|
-
</component>
|
42
|
-
<component name="SpringUtil" SPRING_PRE_LOADER_OPTION="true" RAKE_SPRING_PRE_LOADER_OPTION="true" RAILS_SPRING_PRE_LOADER_OPTION="true" />
|
43
|
-
<component name="SvnConfiguration">
|
44
|
-
<configuration />
|
45
|
-
</component>
|
46
|
-
<component name="TaskManager">
|
47
|
-
<task active="true" id="Default" summary="Default task">
|
48
|
-
<changelist id="da917fa3-f5ef-4365-9d07-5ed3fa5f86fb" name="Default Changelist" comment="" />
|
49
|
-
<created>1649928928769</created>
|
50
|
-
<option name="number" value="Default" />
|
51
|
-
<option name="presentableId" value="Default" />
|
52
|
-
<updated>1649928928769</updated>
|
53
|
-
<workItem from="1649928930827" duration="666000" />
|
54
|
-
</task>
|
55
|
-
<servers />
|
56
|
-
</component>
|
57
|
-
<component name="TypeScriptGeneratedFilesManager">
|
58
|
-
<option name="version" value="1" />
|
59
|
-
</component>
|
60
|
-
<component name="WindowStateProjectService">
|
61
|
-
<state width="1398" height="318" key="GridCell.Tab.0.bottom" timestamp="1649928978709">
|
62
|
-
<screen x="0" y="0" width="1440" height="900" />
|
63
|
-
</state>
|
64
|
-
<state width="1398" height="318" key="GridCell.Tab.0.bottom/0.0.1440.900@0.0.1440.900" timestamp="1649928978709" />
|
65
|
-
<state width="1398" height="318" key="GridCell.Tab.0.center" timestamp="1649928978707">
|
66
|
-
<screen x="0" y="0" width="1440" height="900" />
|
67
|
-
</state>
|
68
|
-
<state width="1398" height="318" key="GridCell.Tab.0.center/0.0.1440.900@0.0.1440.900" timestamp="1649928978707" />
|
69
|
-
<state width="1398" height="318" key="GridCell.Tab.0.left" timestamp="1649928978706">
|
70
|
-
<screen x="0" y="0" width="1440" height="900" />
|
71
|
-
</state>
|
72
|
-
<state width="1398" height="318" key="GridCell.Tab.0.left/0.0.1440.900@0.0.1440.900" timestamp="1649928978706" />
|
73
|
-
<state width="1398" height="318" key="GridCell.Tab.0.right" timestamp="1649928978708">
|
74
|
-
<screen x="0" y="0" width="1440" height="900" />
|
75
|
-
</state>
|
76
|
-
<state width="1398" height="318" key="GridCell.Tab.0.right/0.0.1440.900@0.0.1440.900" timestamp="1649928978708" />
|
77
|
-
</component>
|
78
|
-
</project>
|