Skip to content

Commit 0142eb7

Browse files
Merge pull request #1908 from sthaha/improve-jsonnet-gen
Speedup jsonnet generation by running in parallel
2 parents b44d7f3 + 7eb4068 commit 0142eb7

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)