From a1377478e955d60a18bc53dec383426dd8727bfc Mon Sep 17 00:00:00 2001 From: heavybullets8 Date: Wed, 16 Aug 2023 18:24:15 -0600 Subject: [PATCH] improve restart function --- utils/resources.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/utils/resources.sh b/utils/resources.sh index 39a866e9..644097de 100644 --- a/utils/resources.sh +++ b/utils/resources.sh @@ -8,12 +8,24 @@ pull_replicas() { } restart_app(){ - # There are no good labels to use to identify the deployment, so we have to simply filter out the cnpg deployment for now - dep_names=$(k3s kubectl -n ix-"$app_name" get deploy | grep -vE -- '(-cnpg-)' | sed -e '1d' -e 's/ .*//') - for dep_name in $dep_names; do + # Check if the namespace exists + if ! k3s kubectl get namespace ix-"$app_name" &>/dev/null; then + return 1 + fi + + # Get deployments excluding the cnpg ones + mapfile -t dep_names < <(k3s kubectl -n ix-"$app_name" get deploy | grep -vE -- '(-cnpg-)' | awk 'NR>1 {print $1}') + + # Check if there are any valid deployments to restart + if [[ ${#dep_names[@]} -eq 0 ]]; then + return 1 + fi + + # Restart each deployment + for dep_name in "${dep_names[@]}"; do if ! k3s kubectl -n ix-"$app_name" rollout restart deploy "$dep_name" &>/dev/null; then return 1 fi done return 0 -} +} \ No newline at end of file