-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmco-config-lint-script.sh
executable file
·66 lines (57 loc) · 1.88 KB
/
mco-config-lint-script.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# Attempts to implement a shellcheck linter for the configs that live within the MCO repo, but are not owned by the MCO developers.
# Currently does not work so well for the templatized configs.
set -uo pipefail
# Gather all the YAML files which do not have Golang templates embedded within them.
non_templatized_script_files="$(rg -g "*.yaml" --files-without-match -F "{{" ./templates | xargs rg --files-with-matches -F '#!/bin/bash' | sort)"
for file in $non_templatized_script_files; do
# Extract the path from the file
script_file="$(yq eval '.path' "$file")"
echo "----- In $script_file -----"
# Extract the script and pipe it into shellcheck
# https://github.com/koalaman/shellcheck
yq eval '.contents.inline' "$file" | shellcheck -
printf "\n"
done
read -r -d '' mock_data << EOM
{
"LBConfig": {
"LbPort": "8080",
"ApiPort": "7070"
},
"NonVirtualIP": "127.0.0.1",
"Network": {
"MTUMigration": {
"Machine": {
"To": "a-machine"
}
}
},
"NetworkType": "OVNKubernetes",
"Proxy": {
"HTTPProxy": "127.0.0.2:8080",
"HTTPSProxy": "127.0.0.3:8443",
"NoProxy": ""
},
"Images": {
"baremetalRuntimeCfgImage": "baremetal-runtime-cfg-image"
},
"DNS": {
"Spec": {
"BaseDomain": ".openshift"
}
}
}
EOM
echo "$mock_data" > "mock_data.json"
templatized_script_files="$(rg -g '*.yaml' --files-with-matches -F '{{' ./templates | xargs rg --files-with-matches -F '#!/bin/bash' | sort)"
for file in $templatized_script_files; do
echo "----- In $file -----"
gomplate -c '.=mock_data.json' -f "$file" -d '.=mock_data.json' \
--plugin=onPremPlatformAPIServerInternalIP=./print.sh \
--plugin=onPremPlatformIngressIP=./print.sh
script_file="$(echo "$rendered" | yq eval '.path' -)"
echo "----- In $script_file -----"
echo "$rendered" | yq eval '.contents.inline' - | shellcheck -
printf "\n"
done