-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtools.sh
More file actions
63 lines (47 loc) · 1.37 KB
/
tools.sh
File metadata and controls
63 lines (47 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
NAMESPACE="np-keyston"
OUTPUT_FILE="obervability_tools_versions.json"
echo "collecting tool versions for observability statefulsets in namespace: $NAMESPACE"
echo "{" > "$OUTPUT_FILE"
statefulsets=(
"grafana-statefulset"
"np-loki-chunks-cache"
"np-loki-compactor"
"np-loki-index-gateway"
"np-loki-ingester-zone-a"
"np-loki-ingester-zone-b"
"np-loki-ingester-zone-c"
"np-loki-results-cache"
"np-loki-ruler"
"np-redpanda"
"np-tempo-ingester"
"np-tempo-memcached"
"np-victoriametrics-victoria-metrics-single-server"
)
for i in "${!statefulsets[@]}"; do
statefulset="${statefulsets[$i]}"
IMAGE=$(kubectl get statefulset "$statefulset" -n "NAMESPACE" -o jsonpath='{.spec.template.spec.containers[*].image}' 2> /dev/null)
if [ -n "$IMAGE"]; then
#extract the version tag from the image (everything after colon)
VERSION=$(echo "$IMAGE" | awk -F: '{if (NF>1) print $NF; else print "latest"}')
else
IMAGE="Not Found"
VERSION="Not Found"
fi
#Add comma only if it's not the latest element
if [ "$i" -lt $((${#statefulsets[@]} - 1))]; then
COMMA=","
else
COMMA=""
fi
cat <<EOF >>"$OUTPUT_FILE"
{
"statefulset": "$statefulset",
"image": "$IMAGE"
"version": "$VERSION"
}$COMMA
EOF
done
echo " ]" >> "OUTPUT_FILE"
echo " }" >> "OUTPUT_FILE"
echo "Tool versions have been consolidated into $OUTPUT_FILE"