From 6fbb47a0ac1537ab8fc4b7c54980f282cbc53b93 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 26 Sep 2024 12:49:31 +1000 Subject: [PATCH] chore: debugging --- legacy/build-deploy-docker-compose.sh | 94 +++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 16bc7858..815667aa 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -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=() @@ -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"