This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bugfixes] - Suppress errors - Better verbose message for time to become active in update function - Abort "scale" jobs when starting applications - - Fixes errors when starting various applications
- Loading branch information
1 parent
8789410
commit 2a3bbcc
Showing
7 changed files
with
81 additions
and
26 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
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,22 +1,77 @@ | ||
#!/bin/bash | ||
|
||
abort_job(){ | ||
local app_name=$1 | ||
job_ids="" | ||
|
||
# shellcheck disable=SC2034 | ||
for i in {1..60}; do | ||
job_ids=$(get_running_job_id "$app_name") | ||
|
||
if [[ -n "$job_ids" ]]; then | ||
while IFS= read -r job_id; do | ||
midclt call core.job_abort "$job_id" > /dev/null 2>&1 | ||
done <<< "$job_ids" | ||
return 0 | ||
fi | ||
|
||
sleep 1 | ||
done | ||
return 1 | ||
} | ||
|
||
wait_for_redeploy_methods(){ | ||
local app_name=$1 | ||
local methods="" | ||
|
||
# shellcheck disable=SC2034 | ||
for i in {1..60}; do | ||
methods=$(get_running_methods "$app_name") | ||
|
||
if [[ "$methods" == *"chart.release.redeploy"* && "$methods" == *"chart.release.redeploy_internal"* ]]; then | ||
return 0 | ||
fi | ||
|
||
sleep 1 | ||
done | ||
return 1 | ||
} | ||
|
||
get_running_methods(){ | ||
local app_name=$1 | ||
midclt call core.get_jobs | jq -r --arg app_name "$app_name" \ | ||
'.[] | select( .time_finished == null and .state == "RUNNING" and (.arguments[0] == $app_name)) | .method' | ||
} | ||
|
||
get_running_job_id(){ | ||
local app_name=$1 | ||
midclt call core.get_jobs | jq -r --arg app_name "$app_name" \ | ||
'.[] | select( .time_finished == null and .state == "RUNNING" and (.progress.description | test("Waiting for pods to be scaled to [0-9]+ replica\\(s\\)$")) and (.arguments[0] == $app_name and .method == "chart.release.scale") ) | .id' | ||
} | ||
|
||
start_app(){ | ||
local app_name=$1 | ||
local replica_count=$2 | ||
local replica_count=${2:-$(pull_replicas "$app_name")} | ||
local job_id | ||
|
||
# Check if app is a cnpg instance, or an operator instance | ||
output=$(check_filtered_apps "$app_name") | ||
if echo "$output" | grep -q "${app_name},stopAll-on"; then | ||
if ! cli -c 'app chart_release scale release_name='\""$app_name"\"\ 'scale_options={"replica_count": '"$replica_count}" > /dev/null; then | ||
return 1 | ||
fi | ||
if ! cli -c "app chart_release update chart_release=\"$app_name\" values={\"global\": {\"stopAll\": false}}" > /dev/null; then | ||
if [[ $output == *"${app_name},stopAll-on"* ]]; then | ||
if ! cli -c "app chart_release update chart_release=\"$app_name\" values={\"global\": {\"stopAll\": false}}" > /dev/null 2>&1; then | ||
return 1 | ||
fi | ||
abort_job "$app_name" | ||
job_id=$(midclt call chart.release.scale "$app_name" '{"replica_count": '"$replica_count"'}') || return 1 | ||
wait_for_redeploy_methods "$app_name" | ||
midclt call core.job_abort "$job_id" > /dev/null 2>&1 | ||
elif [[ $output == *"${app_name},stopAll-off"* ]]; then | ||
job_id=$(midclt call chart.release.scale "$app_name" '{"replica_count": '"$replica_count"'}') || return 1 | ||
wait_for_redeploy_methods "$app_name" | ||
midclt call core.job_abort "$job_id" > /dev/null 2>&1 | ||
else | ||
if ! cli -c 'app chart_release scale release_name='\""$app_name"\"\ 'scale_options={"replica_count": '"$replica_count}" > /dev/null; then | ||
if ! cli -c 'app chart_release scale release_name='\""$app_name"\"\ 'scale_options={"replica_count": '"$replica_count}" > /dev/null 2>&1; then | ||
return 1 | ||
fi | ||
fi | ||
return 0 | ||
} | ||
} |
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