Skip to content

Commit

Permalink
fix: cronjob cleanup use matching function instead of regex (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon authored Oct 17, 2023
1 parent c071ed1 commit 1882d5d
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions legacy/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1690,19 +1690,26 @@ set -x
##############################################

CURRENT_CRONJOBS=$(kubectl -n ${NAMESPACE} get cronjobs --no-headers | cut -d " " -f 1 | xargs)

IFS=' ' read -a SPLIT_CURRENT_CRONJOBS <<< $CURRENT_CRONJOBS

for SINGLE_NATIVE_CRONJOB in ${SPLIT_CURRENT_CRONJOBS[@]}
do
re="\<^$SINGLE_NATIVE_CRONJOB$\>"
text=$( IFS=' '; echo "${NATIVE_CRONJOB_CLEANUP_ARRAY[*]}")
if [[ "$text" =~ $re ]]; then
#echo "Single cron found: ${SINGLE_NATIVE_CRONJOB}"
continue
else
#echo "Single cron missing: ${SINGLE_NATIVE_CRONJOB}"
kubectl -n ${NAMESPACE} delete cronjob ${SINGLE_NATIVE_CRONJOB}
MATCHED_CRONJOB=false
DELETE_CRONJOBS=()
# NATIVE_CRONJOB_CLEANUP_ARRAY is calculated in a prior step, when cronjobs are generated by the build-deploy-tool, this will need to be re-calculated using the tool
for SINGLE_NATIVE_CRONJOB in $CURRENT_CRONJOBS; do
for CLEANUP_NATIVE_CRONJOB in $NATIVE_CRONJOB_CLEANUP_ARRAY; do
if [ "${SINGLE_NATIVE_CRONJOB}" == "${CLEANUP_NATIVE_CRONJOB}" ]; then
MATCHED_CRONJOB=true
continue
fi
done
if [ "${MATCHED_CRONJOB}" != "true" ]; then
DELETE_CRONJOBS+=($SINGLE_NATIVE_CRONJOB)
fi
MATCHED_CRONJOB=false
done
for DC in ${!DELETE_CRONJOBS[@]}; do
# delete any cronjobs if they were removed
if kubectl -n ${NAMESPACE} get cronjob ${DELETE_CRONJOBS[$DC]} &> /dev/null; then
echo ">> Removing cronjob ${DELETE_CRONJOBS[$DC]} because it was removed"
kubectl -n ${NAMESPACE} delete cronjob ${DELETE_CRONJOBS[$DC]}
fi
done

Expand Down

0 comments on commit 1882d5d

Please sign in to comment.