-
Notifications
You must be signed in to change notification settings - Fork 1
/
upstream-generator.sh
30 lines (24 loc) · 1.16 KB
/
upstream-generator.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
#!/bin/bash
# Number of routes
num_routes=${1:-100}
# Output file name
output_file="expanded-ingresses-$num_routes.yaml"
# Remove existing output file if it exists
[ -e "$output_file" ] && rm "$output_file"
# Start writing the YAML
echo -e "apiVersion: networking.k8s.io/v1\nkind: Ingress" > "$output_file"
# Loop to generate Ingress blocks with parameterized names and paths
for ((i=1; i<=$num_routes; i++)); do
echo -e "metadata:\n annotations:\n konghq.com/strip-path: \"true\"" >> "$output_file"
echo " name: upstream-${i}" >> "$output_file"
echo " namespace: upstream" >> "$output_file"
echo -e "spec:\n ingressClassName: kong\n rules:" >> "$output_file"
echo -e " - http:\n paths:" >> "$output_file"
echo -e " - backend:\n service:\n name: upstream\n port:\n number: 8000" >> "$output_file"
echo " path: /${i}route" >> "$output_file"
echo " pathType: ImplementationSpecific" >> "$output_file"
if [ "$i" -lt "$num_routes" ]; then
echo -e "---\napiVersion: networking.k8s.io/v1\nkind: Ingress" >> "$output_file"
fi
done
echo "Expansion complete. Output file: $output_file"