-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tope Emmanuel
committed
Oct 6, 2023
1 parent
9091355
commit 27d0fbf
Showing
6 changed files
with
79 additions
and
328 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,166 +1,79 @@ | ||
# Input variables | ||
pr_number=${1} | ||
pr_name=${2} | ||
minimun_ing_num=1 | ||
maximun_ing_num=20 | ||
|
||
##########################new code starts###################################### | ||
|
||
# check_existing_ingress "${numbers_from_ings1[@]}" | ||
check_existing_ingress() { | ||
local current="get-school-experience-review-pr-2973.test.teacherservices.cloud" | ||
|
||
get_all_relevant_ingresses() { | ||
# Find if it is already in the list of ingresses | ||
INGS=($(kubectl get ing -n git-development -o json | \ | ||
ings=($(kubectl get ing -n git-development -o json | \ | ||
jq -r '.items[] | select(.metadata.name | startswith("get-school-experience-review-pr")) | .metadata.name')) | ||
|
||
ings1_list=() | ||
|
||
for ((i = 0; i < ${#INGS[@]}; i += 1)); do | ||
itemname="${INGS[i]}" | ||
ings1_list+=("$itemname") # Add itemname to the list | ||
if [ "$itemname" == "$current" ]; then | ||
echo "Found existing ${itemname} ${backend_service} " | ||
fi | ||
ings_list=() | ||
for ((i = 0; i < ${#ings[@]}; i += 1)); do | ||
itemname="${ings[i]}" | ||
ings_list+=("$itemname") # Add itemname to the list | ||
done | ||
|
||
echo "ings1_list from the function is: ${ings1_list[@]}" | ||
echo "${ings_list[@]}" | ||
} | ||
|
||
extract_numbers_from_list() { | ||
local input_strings=("$@") | ||
local prefix="review-get-into-teaching-app-" | ||
local suffix="-internal" | ||
local numbers=() | ||
|
||
for input_string in "${input_strings[@]}"; do | ||
if [[ "$input_string" =~ "${prefix}([0-9]+)${suffix}" ]]; then | ||
numbers+=("${BASH_REMATCH[1]}") | ||
else | ||
numbers+=("Number not found") | ||
fi | ||
done | ||
|
||
echo "${numbers[@]}" | ||
check_existing_dsi_ingress() { | ||
# Find if it is already in the list of existing linked DSI ingresses | ||
servicename="get-school-experience-review-pr-${pr_number}" | ||
ings=($(kubectl get ing -o=custom-columns='NAME:.metadata.name,SVCs:..service.name' -n git-development | grep "${servicename}" | grep -v "${pr_name}")) | ||
echo "$ings" | ||
} | ||
|
||
get_ings1_list() { | ||
# Find if it is already in the list of ingresses | ||
INGS=($(kubectl get ing -n git-development -o json | \ | ||
jq -r '.items[] | select(.metadata.name | startswith("get-school-experience-review-pr")) | .metadata.name, .spec.rules[0].http.paths[0].backend.service.name')) | ||
|
||
ings1_list=() | ||
|
||
for ((i = 1; i < ${#INGS[@]}; i += 1)); do | ||
ings1_list+=("${INGS[i]}") | ||
done | ||
|
||
echo "${ings1_list[@]}" | ||
} | ||
|
||
number_exists_in_list() { | ||
local number_to_check="$1" | ||
shift | ||
local number_list=("$@") | ||
|
||
for number in "${number_list[@]}"; do | ||
if [ "$number_to_check" -eq "$number" ]; then | ||
return 0 # Number found | ||
fi | ||
done | ||
|
||
return 1 # Number not found | ||
} | ||
|
||
# Example usage: | ||
extract_numbers_from_list() { | ||
local input_strings=("$@") | ||
local prefix="get-school-experience-review-pr-" | ||
local suffix=".test.teacherservices.cloud" | ||
local numbers=() | ||
|
||
for input_string in "${input_strings[@]}"; do | ||
if [[ "$input_string" =~ "${prefix}([0-9]+)${suffix}" ]]; then | ||
numbers+=("${BASH_REMATCH[1]}") | ||
else | ||
numbers+=("Number not found") | ||
fi | ||
done | ||
|
||
echo "${numbers[@]}" | ||
} | ||
|
||
number_exists_in_list() { | ||
local number_to_check="$1" | ||
shift | ||
local number_list=("$@") | ||
|
||
for number in "${number_list[@]}"; do | ||
if [ "$number_to_check" -eq "$number" ]; then | ||
return 0 # Number found | ||
fi | ||
done | ||
|
||
return 1 # Number not found | ||
} | ||
|
||
# Example usage with extract_numbers_from_list and number_exists_in_list | ||
# string_list=("review-get-into-teaching-app-2619-internal" "review-get-into-teaching-app-2685-internal" "review-get-into-teaching-app-2632-internal") | ||
|
||
# # Extract numbers from the string list | ||
# numbers_from_list=($(extract_numbers_from_list "${string_list[@]}")) | ||
|
||
# Number to find | ||
number_to_find=$pr_number | ||
|
||
# Check if the number exists in the extracted list | ||
# if number_exists_in_list "$number_to_find" "${numbers_from_list[@]}"; then | ||
# echo "$number_to_find exists in the list." | ||
# else | ||
# echo "$number_to_find does not exist in the list." | ||
# fi | ||
|
||
|
||
# Get the INGS[1] values | ||
# ings1_list=$(check_existing_ingress) | ||
#echo "ings1_list is $ings1_list" | ||
# # Use ings1_list as input to extract_numbers_from_list | ||
#numbers_from_ings1=$(extract_numbers_from_list "${ings1_list[@]}") | ||
# echo "=============================================================" | ||
# echo "numbers_from_ings1 is $numbers_from_ings1" | ||
|
||
# # Call the check_existing_ingress function with numbers_from_ings1 as input | ||
|
||
|
||
# Call the function | ||
#check_existing_ingress | ||
extract_numbers_from_list() { | ||
local input_strings=("$@") | ||
local all_existing_ings=("$@") | ||
local pattern="get-school-experience-review-pr-([0-9]+)\.test\.teacherservices\.cloud" | ||
local numbers=() | ||
|
||
for input_string in "${input_strings[@]}"; do | ||
local all_existing_review_ings=() | ||
for input_string in "${all_existing_ings[@]}"; do | ||
if [[ "$input_string" =~ $pattern ]]; then | ||
numbers+=("${BASH_REMATCH[1]}") | ||
all_existing_review_ings+=("${BASH_REMATCH[1]}") | ||
else | ||
numbers+=("Number not found") | ||
all_existing_review_ings+=("Number not found") | ||
fi | ||
done | ||
|
||
echo "${numbers[@]}" | ||
echo "${all_existing_review_ings[@]}" | ||
} | ||
|
||
# Example usage with the input strings | ||
input_strings=( | ||
"get-school-experience-review-pr-2972.test.teacherservices.cloud" | ||
"get-school-experience-review-pr-2973.test.teacherservices.cloud" | ||
"get-school-experience-review-pr-777.test.teacherservices.cloud" | ||
) | ||
|
||
# Extract numbers from the input strings | ||
numbers_from_list=($(extract_numbers_from_list "${input_strings[@]}")) | ||
|
||
# Print the extracted numbers | ||
for number in "${numbers_from_list[@]}"; do | ||
echo "$number" | ||
done | ||
|
||
|
||
# ############################END NEW CODE#################################### | ||
# check if there is an existing linked ingress | ||
existing_ing=($(check_existing_dsi_ingress)) | ||
|
||
next_ingress="" | ||
if [ -z "$existing_ing" ]; then | ||
# get all existing ingresses | ||
ings_list_result=($(get_all_relevant_ingresses)) | ||
|
||
# extract the number part of the ingresses from ingress lists | ||
numbers_from_ings=($(extract_numbers_from_list "${ings_list_result[@]}")) | ||
available_numbers=() | ||
unavailable_numbers=() | ||
all_possible_ings_pr_num=() | ||
for ((i = $minimun_ing_num; i <= $maximun_ing_num; i++)); do | ||
all_possible_ings_pr_num+=("$i") | ||
done | ||
for possible_ings_pr_num in "${all_possible_ings_pr_num[@]}"; do | ||
found=false | ||
for ((i = 0; i < ${#numbers_from_ings[@]}; i += 1)); do | ||
itemname="${numbers_from_ings[i]}" | ||
if [ "$itemname" == "$possible_ings_pr_num" ]; then | ||
unavailable_numbers+=("$possible_ings_pr_num") | ||
found=true | ||
break | ||
fi | ||
done | ||
if [ "$found" = false ]; then | ||
available_numbers+=("$possible_ings_pr_num") | ||
fi | ||
done | ||
if [ ${#available_numbers[@]} -gt 0 ]; then | ||
sorted_numbers=($(printf "%s\n" "${available_numbers[@]}" | sort -n)) | ||
selectednumber=${sorted_numbers[0]} | ||
next_ingress="get-school-experience-review-pr-$selectednumber.test.teacherservices.cloud" | ||
else | ||
next_ingress="" | ||
fi | ||
else | ||
next_ingress="$existing_ing" | ||
fi | ||
echo "$next_ingress" |
Oops, something went wrong.