Skip to content

Commit 7eb4068

Browse files
committed
Speedup jsonnet generation by them running in parallel
Previously, jsonnet to yaml conversion was done sequentially and this took quite some time. The patch speeds that up by running them in parallel . The number of jobs to run in parallel is determined by the number of CPU cores (thus requires nproc to be in path). Signed-off-by: Sunil Thaha <[email protected]>
1 parent 0be07c1 commit 7eb4068

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

hack/build-jsonnet.sh

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,26 @@ while IFS= read -r line; do
2222
files+=("$line")
2323
done < <(jq -r 'keys[]' "${TMP}/main.json")
2424

25-
for file in "${files[@]}"
26-
do
27-
dir=$(dirname "${file}")
28-
path="${prefix}/${dir}"
29-
mkdir -p "${path}"
30-
# convert file name from camelCase to snake-case
31-
fullfile=$(echo "${file}" | sed 's/\(.\)\([A-Z]\)/\1-\2/g' | tr '[:upper:]' '[:lower:]')
32-
jq -r ".[\"${file}\"]" "${TMP}/main.json" | gojsontoyaml > "${prefix}/${fullfile}.yaml"
25+
maxProc=$(nproc || echo 4)
26+
27+
# process all files in parallel
28+
for file in "${files[@]}"; do
29+
{
30+
dir=$(dirname "${file}")
31+
path="${prefix}/${dir}"
32+
mkdir -p "${path}"
33+
34+
# convert file name from camelCase to snake-case
35+
fullfile=$(echo "${file}" | sed 's/\(.\)\([A-Z]\)/\1-\2/g' | tr '[:upper:]' '[:lower:]')
36+
jq -r ".[\"${file}\"]" "${TMP}/main.json" | gojsontoyaml > "${prefix}/${fullfile}.yaml"
37+
}&
38+
39+
# wait for at least one of the jobs to finish if there are more than maxProc jobs
40+
while [[ $(jobs -r | wc -l ) -ge "$maxProc" ]]; do wait -n; done
3341
done
42+
# wait for all jobs to finish
43+
wait
44+
3445

3546
# shellcheck disable=SC1003
3647
# Produce dashboard definitions in format understandable by CVO (it doesn't accept ConfigMapList)

0 commit comments

Comments
 (0)