-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Autogenerate deployment YAML for cluster sharding
- Loading branch information
mgianluc
committed
Oct 24, 2023
1 parent
1b5cde2
commit 6d5d7fe
Showing
5 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
# Define the YAML file path | ||
yaml_file=$1 | ||
output_file=$2 | ||
|
||
# Create a temporary directory to store the split sections | ||
mkdir -p temp_yaml_sections | ||
|
||
# Initialize variables for section counting and flag to track changes | ||
section_count=0 | ||
in_section=false | ||
|
||
# Iterate through the YAML file | ||
while IFS= read -r line; do | ||
if [[ $line == '---' ]]; then | ||
# Start a new section | ||
in_section=true | ||
section_count=$((section_count + 1)) | ||
current_section_file="temp_yaml_sections/section_${section_count}.yaml" | ||
continue | ||
fi | ||
|
||
if [[ $in_section == true ]]; then | ||
# Replace "shard-key=" with "shard-key='shard1'" | ||
if [[ $line == *"shard-key"* ]]; then | ||
line=$(echo "$line" | sed "s/shard-key=/shard-key={{.SHARD}}/") | ||
fi | ||
|
||
# Replace "name" to contain shard info | ||
if [[ $line == *"name: addon-controller"* ]]; then | ||
line=$(echo "$line" | sed "s/addon-controller/addon-controller-{{.SHARD}}/") | ||
fi | ||
|
||
# Write the line to the current section file | ||
echo "$line" >> "$current_section_file" | ||
fi | ||
done < "$yaml_file" | ||
|
||
# Iterate through the split sections and print those with "kind: Deployment" | ||
for section_file in temp_yaml_sections/*.yaml; do | ||
if grep -q "kind: Deployment" "$section_file"; then | ||
cat "$section_file" > $output_file | ||
fi | ||
done | ||
|
||
# Remove the temporary directory | ||
rm -r temp_yaml_sections |