-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchecker.sh
More file actions
executable file
·185 lines (160 loc) · 4.59 KB
/
checker.sh
File metadata and controls
executable file
·185 lines (160 loc) · 4.59 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env bash
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly INVERTED='\033[7m'
readonly BOLD='\033[1m'
readonly NC='\033[0m' # No Color
# DEFAULTS
helmLint=false
directories=()
helmVersion=latest
exitImmediatelyIfErr="set -e"
doNotExitImmediatelyIfErr="set +e"
function show_help() {
echo " Addon checking tool"
echo " Usage:"
echo " checker.sh [flags]"
echo
echo " Flags:"
echo " -h --help helm for the script"
echo " --helm-lint set to perform helm lint operation"
echo " --directories specify the list of addon repository separated by ;"
echo " --helm-version specify the Helm version. Default set to latest."
echo
echo " Example of usage:"
echo " checker.sh --helm-lint --directories ./addons/showcase;./addons/stable --helm-version v2.10.0"
}
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case ${key} in
-h|-\?|--help)
show_help
exit 0
;;
--helm-lint)
helmLint=true
shift
;;
--directories)
directories=(${2//;/ })
shift
shift
;;
--helm-version)
helmVersion="$2"
shift
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
function validateInputParams() {
if [ ${#directories[@]} -eq 0 ]; then
echo -e "\n\t--directories parameter is required\n"
show_help
exit 1
fi
}
function executeCmd() {
local cmd=$1
local exitErr=0
echo -e "\n${BOLD}Executing: ${cmd}${NC}"
local OUT_COLOR=${GREEN}
# To prevent getting lost of new line characters, see: https://unix.stackexchange.com/a/164548
IFS=
out=$(eval "${cmd}")
if [ $? -eq 1 ];
then
OUT_COLOR=${RED}
exitErr=1
fi
echo -e "${OUT_COLOR}"
echo ${out}
echo -e "${NC}"
return ${exitErr}
}
function checkAddons() {
local errOccurred=0
for directory in ${directories[@]}
do
echo -e "${INVERTED}Checking addons in directory ${directory}${NC}"
for addon in ${directory}/*/; do
for addonVersion in ${addon}*/; do
executeCmd "scripts/helm_checker.sh ${addonVersion}"
if [ $? -eq 1 ];
then
errOccurred=1
fi
done
done
done
if [ ${errOccurred} -eq 1 ];
then
exit 1
fi
}
function installHelm() {
if [ command -v helm >/dev/null 2>&1 ]; then
echo -e "${INVERTED}Helm has been installed.\n"
else
echo -e "${INVERTED}Installing Helm...\n${NC}"
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
fi
}
function installYq() {
if [ command -v yq >/dev/null 2>&1 ]; then
echo -e "${INVERTED}yq has been installed.\n"
else
version=$(curl -Ls https://github.com/mikefarah/yq/releases|grep /mikefarah/yq/releases/tag/ | sed -E 's/.*\/mikefarah\/yq\/releases\/tag\/(v[0-9\.]{1,}(-rc.[0-9]{1,})?)".*/\1/g' | head -1)
curl -fsSL https://github.com/mikefarah/yq/releases/download/$version/yq_linux_$(dpkg-architecture -q DEB_BUILD_ARCH) -o /usr/local/bin/yq
chmod +x /usr/local/bin/yq
fi
}
function lintHelmChartsIfRequested() {
if [ "$helmLint" = false ];
then
exit 0
fi
eval ${exitImmediatelyIfErr}
installHelm
eval ${doNotExitImmediatelyIfErr}
local errOccurred=0
echo -e "${INVERTED}Linting Helm Charts...${NC}"
for directory in ${directories[@]}
do
for addon in ${directory}/*/; do
for chart in ${addon}*/chart/*/; do
if [ ! -e ${chart}/Chart.lock ]; then
helm dependency update ${chart}
fi
for plan in ${addon}*/plans/*/; do
if [ -e ${plan}values.yaml ]
then
helmCmd="helm lint ${chart} --values ${plan}values.yaml"
else
helmCmd="helm lint ${chart}"
fi
executeCmd "${helmCmd}"
if [ $? -eq 1 ];
then
errOccurred=1
fi
done
done
done
done
if [ ${errOccurred} -eq 1 ];
then
exit 1
fi
}
installYq
validateInputParams
checkAddons
lintHelmChartsIfRequested