-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-helm-chart-versions.sh
executable file
·48 lines (37 loc) · 1.47 KB
/
check-helm-chart-versions.sh
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
#!/bin/bash
source .check.lib.sh
check_programs_available kubectl jq helm awk
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
function versioncheck() {
local app=$1
local chart=$2
local repoURL=$3
local version=$4
# Add the repository if it is not already added
helm repo add temp-repo "$repoURL" > /dev/null 2>&1
helm repo update > /dev/null 2>&1
# Get the latest version of the chart
local latestInfo
latestInfo=$(helm search repo temp-repo/"$chart" | awk 'NR==2 {print $1, $2}')
local latestVersion=$(echo "$latestInfo" | awk '{print $2}')
# Remove the temporary repository
helm repo remove temp-repo > /dev/null 2>&1
# Remove leading 'v' if it exists
latestVersion=${latestVersion#v}
if [[ "${latestVersion#v}" != "$version" ]]; then
echo -e "${RED}Outdated${NC}: $app ($repoURL $chart): ${RED}$version${NC} [$latestVersion]"
else
echo -e "${GREEN}OK${NC}: $app ($repoURL $chart): ${GREEN}$version${NC}"
fi
}
export -f versioncheck
kubectl get -n argocd applications.argoproj.io -o json | \
jq '.items.[] ' |
jq '{name: .metadata.name, source: ([.spec.source] + .spec.sources).[] | {chart: .chart, repoURL: .repoURL, version: .targetRevision } }' |
jq 'select(.source.chart != null)' |
jq -r '"\(.name) \(.source.chart) \(.source.repoURL) \(.source.version)"' |
while read -r app chart repoURL version; do
versioncheck "$app" "$chart" "$repoURL" "$version"
done