forked from signalfx/splunk-otel-collector-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender-examples.sh
executable file
·102 lines (88 loc) · 3.24 KB
/
render-examples.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
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
#!/bin/bash
# Purpose: Renders Kubernetes manifests from Helm charts for various examples in parallel.
# Notes:
# - Renders all examples using Helm template.
# - Uses the default example values file located in each example directory and optionally additional values files passed as parameters.
# - Supports parallel rendering of examples for efficiency.
#
# Parameters:
# $@: Additional values files to be applied on top of the default example values file for each Helm chart rendering (optional).
#
# Usage Examples:
# ./render-examples.sh
# ./render-examples.sh extra-values.yaml
# ./render-examples.sh values1.yaml values2.yaml
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
render_task() {
example_dir=$1
rendered_manifests_dir="${example_dir}rendered_manifests"
default_values_yaml=$(ls "${example_dir}" | grep -m 1 'values.yaml')
if [ -z "$default_values_yaml" ]; then
echo "No default values.yaml found in ${example_dir}"
exit 1
fi
# Initialize helm values with the default values file
helm_values=("--values" "${example_dir}${default_values_yaml}")
# Append additional values files if provided
for value_file in "${values_files[@]}"; do
helm_values+=("--values" "${value_file}")
done
# Clear out all rendered manifests
rm -rf "${rendered_manifests_dir}"
# Generate rendered files
out=$(helm template \
--namespace default \
"${helm_values[@]}" \
--output-dir "${rendered_manifests_dir}" \
default helm-charts/splunk-otel-collector)
if [ $? -ne 0 ]; then
echo "$default_values_yaml FAIL - helm template: $out"
exit 1
fi
# Move the chart renders
cp -rp "${rendered_manifests_dir}/splunk-otel-collector/templates/"* "$rendered_manifests_dir"
if [ $? -ne 0 ]; then
echo "${default_values_yaml} FAIL - Move the chart renders"
exit 1
fi
# Move any subchart renders
if [ -d "${rendered_manifests_dir}/splunk-otel-collector/charts/" ]; then
subcharts_dir="${rendered_manifests_dir}/splunk-otel-collector/charts"
subcharts_di=$(find "${subcharts_dir}" -type d -maxdepth 1 -mindepth 1 -exec basename \{\} \;)
for subchart in ${subcharts_di}; do
mkdir -p "${rendered_manifests_dir}/${subchart}"
mv "${subcharts_dir}/${subchart}/templates/"* "${rendered_manifests_dir}/${subchart}"
if [ $? -ne 0 ]; then
echo "${default_values_yaml} FAIL - Move subchart renders"
exit 1
fi
done
fi
echo "${default_values_yaml} SUCCESS"
}
# Collect additional values files passed as arguments
values_files=("$@")
for example_dir in $SCRIPT_DIR/*/; do
render_task "${example_dir}" &
done
wait # Let all the render tasks finish
for example_dir in $SCRIPT_DIR/*/; do
rendered_manifests_dir="${example_dir}rendered_manifests"
if [ ! -d "${rendered_manifests_dir}" ]; then
echo "Examples were rendered, failure occurred"
exit 1
else
# Temporary space cleanup
if ls "${example_dir}" | grep -q ".norender."; then
rm -rf "${rendered_manifests_dir}"
else
rm -rf "${rendered_manifests_dir}/splunk-otel-collector"
fi
if [ $? -ne 0 ]; then
echo "${default_values_yaml} FAIL - Temporary space cleanup"
exit 1
fi
fi
done
echo "Examples were rendered successfully"
exit 0