Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup fix #778

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions deployment/k8s-config/scripts/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,44 @@
# The script can be executed in its current directory by typing:
# ./cleanup.sh

echo "START"
# To DEBUG first:
# CLEANUP_DEBUG=1 ./cleanup.sh

echo "START $(date -u +"%Y%m%dT%H%M%S")"

if [[ "${CLEANUP_DEBUG}" == "1" ]]
then
echo "DEBUG MODE"
fi

types="service ingressroute middleware"
for type in $types;
do
kubectl -n skaha-workload get $type |
kubectl -n skaha-workload get --no-headers=true $type |
while IFS= read -r line
# for each service session
do
# obtain various info on the session
name=`echo $line | awk '{print $1}'`
id=`echo $name | awk -F- '{print $4}'`
id=`echo $name | awk -F- '{print $NF}'`

# check if there is a corresponding pod
out=`kubectl -n skaha-workload get pods | grep -e "$id"`
out=`kubectl -n skaha-workload get pods --ignore-not-found=true -l canfar-net-sessionID="${id}"`
if [[ -z "$out" && -n "$id" ]]
then
CMD="kubectl -n skaha-workload delete $type $name"
echo "${CMD}"

# no corresponding pod, delete orphaned session
kubectl -n skaha-workload delete $type $name
if [[ -z "${CLEANUP_DEBUG}" ]]
then
${CMD}
fi
elif [[ "${CLEANUP_DEBUG}" == "1" ]]
then
echo "Nothing to do for Session ${id}"
fi
done
done

echo "END"
echo "END"
Loading