@@ -96,7 +96,7 @@ install_argocd_cli() {
9696 VERSION=$( curl -L -s https://raw.githubusercontent.com/argoproj/argo-cd/stable/VERSION)
9797 echo " [INFO] Latest version: $VERSION "
9898 curl -sSL -o argocd-linux-amd64 \
99- https://github.com/argoproj/argo-cd/releases/download/v${VERSION} /argocd-linux-amd64
99+ https://github.com/argoproj/argo-cd/releases/download/v" ${VERSION} " /argocd-linux-amd64
100100 sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
101101 rm -f argocd-linux-amd64
102102 echo " [INFO] argocd CLI installed successfully."
@@ -196,13 +196,15 @@ check_and_fix_crd_version_mismatch() {
196196 local app_name=" $1 "
197197
198198 # Get application status
199- local status=$( kubectl get applications.argoproj.io " $app_name " -n " $NS " -o json 2> /dev/null)
199+ local status
200+ status=$( kubectl get applications.argoproj.io " $app_name " -n " $NS " -o json 2> /dev/null)
200201 if [[ -z " $status " ]]; then
201202 return 1
202203 fi
203204
204205 # Check for CRD version mismatch errors in sync messages
205- local version_mismatch=$( echo " $status " | jq -r '
206+ local version_mismatch
207+ version_mismatch=$( echo " $status " | jq -r '
206208 .status.conditions[]? |
207209 select(.type == "ComparisonError" or .type == "SyncError") |
208210 select(.message | contains("could not find version") or contains("Version") and contains("is installed")) |
@@ -214,8 +216,10 @@ check_and_fix_crd_version_mismatch() {
214216 echo " $version_mismatch "
215217
216218 # Extract CRD details from error message
217- local crd_group=$( echo " $version_mismatch " | grep -oP ' [a-z0-9.-]+\.[a-z]+(?=/[A-Z])' | head -1)
218- local crd_kind=$( echo " $version_mismatch " | grep -oP ' /[A-Z][a-zA-Z]+' | sed ' s|/||' | head -1)
219+ local crd_group
220+ crd_group=$( echo " $version_mismatch " | grep -oP ' [a-z0-9.-]+\.[a-z]+(?=/[A-Z])' | head -1)
221+ local crd_kind
222+ crd_kind=$( echo " $version_mismatch " | grep -oP ' /[A-Z][a-zA-Z]+' | sed ' s|/||' | head -1)
219223
220224 if [[ -n " $crd_group " && -n " $crd_kind " ]]; then
221225 # Try to find and list the CRD
@@ -254,20 +258,24 @@ check_and_handle_failed_sync() {
254258 local full_app=" ${NS} /${app_name} "
255259
256260 # Get application status
257- local status=$( kubectl get applications.argoproj.io " $app_name " -n " $NS " -o json 2> /dev/null)
261+ local status
262+ status=$( kubectl get applications.argoproj.io " $app_name " -n " $NS " -o json 2> /dev/null)
258263 if [[ -z " $status " ]]; then
259264 return 1
260265 fi
261266
262- local sync_phase=$( echo " $status " | jq -r ' .status.operationState.phase // "Unknown"' )
263- local sync_status=$( echo " $status " | jq -r ' .status.sync.status // "Unknown"' )
267+ local sync_phase
268+ sync_phase=$( echo " $status " | jq -r ' .status.operationState.phase // "Unknown"' )
269+ # local sync_status
270+ # sync_status=$(echo "$status" | jq -r '.status.sync.status // "Unknown"')
264271
265272 # Check if sync failed
266273 if [[ " $sync_phase " == " Failed" || " $sync_phase " == " Error" ]]; then
267274 echo " $( red) [FAILED-SYNC] Application $app_name has failed sync (phase=$sync_phase )$( reset) "
268275
269276 # Check for failed jobs/CRDs
270- local failed_resources=$( echo " $status " | jq -r '
277+ local failed_resources
278+ failed_resources=$( echo " $status " | jq -r '
271279 .status.resources[]? |
272280 select(.kind == "Job" or .kind == "CustomResourceDefinition") |
273281 select(.health.status == "Degraded" or .health.status == "Missing" or .health.status == null) |
@@ -459,7 +467,7 @@ sync_not_green_apps_once() {
459467 echo " $( yellow) [INFO] Attempt ${attempt} /${APP_MAX_RETRIES} , elapsed: 0s$( reset) "
460468
461469 # Check if app requires server-side apply
462- if [[ " $SERVER_SIDE_APPS " =~ " $name " ]]; then
470+ if [[ " $SERVER_SIDE_APPS " =~ $name ]]; then
463471 echo " $( yellow) [INFO] Stopping any ongoing operations for $name before force sync...$( reset) "
464472 argocd app terminate-op " $full_app " --grpc-web 2> /dev/null || true
465473 sleep 2
@@ -489,13 +497,13 @@ sync_not_green_apps_once() {
489497 continue
490498 fi
491499
492- timed_out=false
500+ # timed_out=false
493501 while true ; do
494502 now_ts=$( date +%s)
495503 elapsed=$(( now_ts - start_ts ))
496504 if (( elapsed >= APP_MAX_WAIT )) ; then
497505 echo " $( red) [TIMEOUT] $full_app did not become Healthy+Synced within ${APP_MAX_WAIT} s.$( reset) "
498- timed_out=true
506+ # timed_out=true
499507 break
500508 fi
501509 status=$( kubectl get applications.argoproj.io " $name " -n " $NS " -o json 2> /dev/null)
@@ -527,7 +535,7 @@ sync_not_green_apps_once() {
527535 # Check if sync operation failed
528536 if [[ " $operation_phase " == " Failed" || " $operation_phase " == " Error" ]]; then
529537 echo " $( red) [ERROR] $full_app sync operation failed with phase=$operation_phase at [$( get_timestamp) ]$( reset) "
530- timed_out=true
538+ # timed_out=true
531539 break
532540 fi
533541
@@ -627,13 +635,13 @@ sync_not_green_apps_once() {
627635 continue
628636 fi
629637
630- timed_out=false
638+ # timed_out=false
631639 while true ; do
632640 now_ts=$( date +%s)
633641 elapsed=$(( now_ts - start_ts ))
634642 if (( elapsed >= APP_MAX_WAIT )) ; then
635643 echo " $( red) [TIMEOUT] $full_app did not become Healthy+Synced within ${APP_MAX_WAIT} s.$( reset) "
636- timed_out=true
644+ # timed_out=true
637645 break
638646 fi
639647 status=$( kubectl get applications.argoproj.io " root-app" -n " $NS " -o json 2> /dev/null)
@@ -761,7 +769,7 @@ sync_all_apps_exclude_root() {
761769 echo " $( yellow) [INFO] Attempt ${attempt} /${APP_MAX_RETRIES} , elapsed: 0s$( reset) "
762770
763771 # Check if app requires server-side apply
764- if [[ " $SERVER_SIDE_APPS " =~ " $name " ]]; then
772+ if [[ " $SERVER_SIDE_APPS " =~ $name ]]; then
765773 echo " $( yellow) [INFO] Stopping any ongoing operations for $name before force sync...$( reset) "
766774 argocd app terminate-op " $full_app " --grpc-web 2> /dev/null || true
767775 sleep 2
@@ -791,13 +799,13 @@ sync_all_apps_exclude_root() {
791799 continue
792800 fi
793801
794- timed_out=false
802+ # timed_out=false
795803 while true ; do
796804 now_ts=$( date +%s)
797805 elapsed=$(( now_ts - start_ts ))
798806 if (( elapsed >= APP_MAX_WAIT )) ; then
799807 echo " $( red) [TIMEOUT] $full_app did not become Healthy+Synced within ${APP_MAX_WAIT} s.$( reset) "
800- timed_out=true
808+ # timed_out=true
801809 break
802810 fi
803811 status=$( kubectl get applications.argoproj.io " $name " -n " $NS " -o json 2> /dev/null)
@@ -829,7 +837,7 @@ sync_all_apps_exclude_root() {
829837 # Check if sync operation failed
830838 if [[ " $operation_phase " == " Failed" || " $operation_phase " == " Error" ]]; then
831839 echo " $( red) [ERROR] $full_app sync operation failed with phase=$operation_phase $( reset) "
832- timed_out=true
840+ # timed_out=true
833841 break
834842 fi
835843
@@ -945,13 +953,13 @@ sync_root_app_only() {
945953 continue
946954 fi
947955
948- timed_out=false
956+ # timed_out=false
949957 while true ; do
950958 now_ts=$( date +%s)
951959 elapsed=$(( now_ts - start_ts ))
952960 if (( elapsed >= APP_MAX_WAIT )) ; then
953961 echo " $( red) [TIMEOUT] $full_app did not become Healthy+Synced within ${APP_MAX_WAIT} s.$( reset) "
954- timed_out=true
962+ # timed_out=true
955963 break
956964 fi
957965 status=$( kubectl get applications.argoproj.io " root-app" -n " $NS " -o json 2> /dev/null)
@@ -963,7 +971,7 @@ sync_root_app_only() {
963971 # Check if sync operation failed
964972 if [[ " $operation_phase " == " Failed" || " $operation_phase " == " Error" ]]; then
965973 echo " $( red) [ERROR] $full_app sync operation failed with phase=$operation_phase $( reset) "
966- timed_out=true
974+ # timed_out=true
967975 break
968976 fi
969977
@@ -1228,19 +1236,19 @@ check_sync_success() {
12281236# ============================================================
12291237# GLOBAL TIMEOUT WATCHDOG
12301238# ============================================================
1231- SCRIPT_START_TS=$( date +%s)
1239+ # SCRIPT_START_TS=$(date +%s)
12321240
12331241# Global retry loop
12341242global_retry=1
1235- sync_success=false
1243+ # sync_success=false
12361244
12371245while (( global_retry <= GLOBAL_SYNC_RETRIES )) ; do
12381246 print_header " GLOBAL SYNC ATTEMPT ${global_retry} /${GLOBAL_SYNC_RETRIES} "
12391247
12401248 execute_full_sync
12411249
12421250 if check_sync_success; then
1243- sync_success=true
1251+ # sync_success=true
12441252 print_header " Sync Script Completed Successfully"
12451253 exit 0
12461254 fi
0 commit comments