Skip to content

Commit

Permalink
chore: debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Sep 26, 2024
1 parent 116a828 commit 6fbb47a
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions legacy/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1619,9 +1619,70 @@ previousStepEnd=${currentStepEnd}
CURRENT_DEPLOYMENTS=$(kubectl -n ${NAMESPACE} get deployments -l "lagoon.sh/service-type" -l "lagoon.sh/service" --no-headers | cut -d " " -f 1 | xargs)
CURRENT_PVCS=$(kubectl -n ${NAMESPACE} get pvc -l "lagoon.sh/service-type" --no-headers | cut -d " " -f 1 | xargs)
CURRENT_SERVICES=$(kubectl -n ${NAMESPACE} get services -l "lagoon.sh/service-type" -l "lagoon.sh/service" --no-headers | cut -d " " -f 1 | xargs)

CURRENT_MARIADB_CONSUMERS=$(kubectl -n ${NAMESPACE} get mariadbconsumers -l "lagoon.sh/service-type" -l "lagoon.sh/service" --no-headers | cut -d " " -f 1 | xargs)
CURRENT_POSTGRES_CONSUMERS=$(kubectl -n ${NAMESPACE} get postgresqlconsumers -l "lagoon.sh/service-type" -l "lagoon.sh/service" --no-headers | cut -d " " -f 1 | xargs)
CURRENT_MONGODB_CONSUMERS=$(kubectl -n ${NAMESPACE} get mongodbconsumers -l "lagoon.sh/service-type" -l "lagoon.sh/service" --no-headers | cut -d " " -f 1 | xargs)

# using the build-deploy-tool identify the deployments, volumes, and services that this build has created
LAGOON_DEPLOYMENTS_TO_JSON=$(build-deploy-tool identify lagoon-services --images /kubectl-build-deploy/images.yaml | jq -r )

echo "${LAGOON_DEPLOYMENTS_TO_JSON}"
MATCHED_MARIADB=false
DELETE_MARIADB=()
for EXIST_CONSUMERS in ${CURRENT_MARIADB_CONSUMERS}; do
for DBAAS_ENTRY in "${DBAAS[@]}"
do
IFS=':' read -ra DBAAS_ENTRY_SPLIT <<< "$DBAAS_ENTRY"
SERVICE_NAME=${DBAAS_ENTRY_SPLIT[0]}
if [ "${EXIST_CONSUMERS}" == "${SERVICE_NAME}" ]; then
MATCHED_MARIADB=true
continue
fi
done
if [ "${MATCHED_MARIADB}" != "true" ]; then
DELETE_MARIADB+=($EXIST_CONSUMERS)
fi
MATCHED_MARIADB=false
done


MATCHED_POSTGRES=false
DELETE_POSTGRES=()
for EXIST_CONSUMERS in ${CURRENT_POSTGRES_CONSUMERS}; do
for DBAAS_ENTRY in "${DBAAS[@]}"
do
IFS=':' read -ra DBAAS_ENTRY_SPLIT <<< "$DBAAS_ENTRY"
SERVICE_NAME=${DBAAS_ENTRY_SPLIT[0]}
if [ "${EXIST_CONSUMERS}" == "${SERVICE_NAME}" ]; then
MATCHED_POSTGRES=true
continue
fi
done
if [ "${MATCHED_POSTGRES}" != "true" ]; then
DELETE_POSTGRES+=($EXIST_CONSUMERS)
fi
MATCHED_POSTGRES=false
done

MATCHED_MONGODB=false
DELETE_MONGODB=()
for EXIST_CONSUMERS in ${CURRENT_MONGODB_CONSUMERS}; do
for DBAAS_ENTRY in "${DBAAS[@]}"
do
IFS=':' read -ra DBAAS_ENTRY_SPLIT <<< "$DBAAS_ENTRY"
SERVICE_NAME=${DBAAS_ENTRY_SPLIT[0]}
if [ "${EXIST_CONSUMERS}" == "${SERVICE_NAME}" ]; then
MATCHED_MONGODB=true
continue
fi
done
if [ "${MATCHED_MONGODB}" != "true" ]; then
DELETE_MONGODB+=($EXIST_CONSUMERS)
fi
MATCHED_MONGODB=false
done

# check the current deployments in the environment against what the build has created and mark anything that isnt in this build as needing removal
MATCHED_DEPLOYMENT=false
DELETE_DEPLOYMENT=()
Expand Down Expand Up @@ -1719,6 +1780,39 @@ if [[ ${#DELETE_DEPLOYMENT[@]} -ne 0 ]] || [[ ${#DELETE_SERVICE[@]} -ne 0 ]]|| [
echo ">> Would remove pvc ${DD}"
fi
done
for DD in ${DELETE_MARIADB[@]}
do
if [ "$(featureFlag CLEANUP_REMOVED_LAGOON_SERVICES)" = enabled ]; then
echo ">> Removing mariadbconsumer ${DD}"
if kubectl -n ${NAMESPACE} get mariadbconsumers ${DD} &> /dev/null; then
kubectl -n ${NAMESPACE} delete mariadbconsumer ${DD}
fi
else
echo ">> Would remove mariadbconsumer ${DD}"
fi
done
for DD in ${DELETE_POSTGRES[@]}
do
if [ "$(featureFlag CLEANUP_REMOVED_LAGOON_SERVICES)" = enabled ]; then
echo ">> Removing postgresqlconsumer ${DD}"
if kubectl -n ${NAMESPACE} get postgresqlconsumers ${DD} &> /dev/null; then
kubectl -n ${NAMESPACE} delete postgresqlconsumer ${DD}
fi
else
echo ">> Would remove postgresqlconsumer ${DD}"
fi
done
for DD in ${DELETE_MONGODB[@]}
do
if [ "$(featureFlag CLEANUP_REMOVED_LAGOON_SERVICES)" = enabled ]; then
echo ">> Removing mongodbconsumer ${DD}"
if kubectl -n ${NAMESPACE} get mongodbconsumers ${DD} &> /dev/null; then
kubectl -n ${NAMESPACE} delete mongodbconsumer ${DD}
fi
else
echo ">> Would remove mongodbconsumer ${DD}"
fi
done
# finalize the service cleanup
currentStepEnd="$(date +"%Y-%m-%d %H:%M:%S")"
patchBuildStep "${buildStartTime}" "${previousStepEnd}" "${currentStepEnd}" "${NAMESPACE}" "unusedServiceCleanupComplete" "Unused Service Cleanup" "true"
Expand Down

0 comments on commit 6fbb47a

Please sign in to comment.