Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
improve restart function
Browse files Browse the repository at this point in the history
  • Loading branch information
Heavybullets8 committed Aug 17, 2023
1 parent 9b217f7 commit a137747
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions utils/resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit a137747

Please sign in to comment.