Skip to content

Commit c8bb07f

Browse files
committed
refactor: use collector
1 parent 24feedf commit c8bb07f

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

legacy/build-deploy-docker-compose.sh

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ buildStartTime="$(date +"%Y-%m-%d %H:%M:%S")"
198198
### COLLECT INFORMATION
199199
##############################################
200200
# run the collector
201-
# @TODO: uncomment when collector is introduced
202-
# @TODO: don't run the collector yet, leave this as placeholder to prevent possible introduction of issues
203-
# ENVIRONMENT_DATA=$(build-deploy-tool collect environment)
201+
ENVIRONMENT_DATA=$(build-deploy-tool collect environment)
204202
# echo "$ENVIRONMENT_DATA" | jq -r '.deployments.items[]?.name'
205203
# echo "$ENVIRONMENT_DATA" | jq -r '.cronjobs.items[]?.name'
206204
# echo "$ENVIRONMENT_DATA" | jq -r '.ingress.items[]?.name'
@@ -1654,22 +1652,13 @@ previousStepEnd=${currentStepEnd}
16541652
### CLEANUP services which have been removed from docker-compose.yaml
16551653
##############################################s
16561654

1657-
# collect the current deployments, volumes, and services in the environment
1658-
CURRENT_DEPLOYMENTS=$(kubectl -n ${NAMESPACE} get deployments -l "lagoon.sh/service-type" -l "lagoon.sh/service" --no-headers | cut -d " " -f 1 | xargs)
1659-
CURRENT_PVCS=$(kubectl -n ${NAMESPACE} get pvc -l "lagoon.sh/service-type" --no-headers | cut -d " " -f 1 | xargs)
1660-
CURRENT_SERVICES=$(kubectl -n ${NAMESPACE} get services -l "lagoon.sh/service-type" -l "lagoon.sh/service" --no-headers | cut -d " " -f 1 | xargs)
1661-
1662-
CURRENT_MARIADB_CONSUMERS=$(kubectl -n ${NAMESPACE} get mariadbconsumers -l "lagoon.sh/service-type" -l "lagoon.sh/service" --no-headers | cut -d " " -f 1 | xargs)
1663-
CURRENT_POSTGRES_CONSUMERS=$(kubectl -n ${NAMESPACE} get postgresqlconsumers -l "lagoon.sh/service-type" -l "lagoon.sh/service" --no-headers | cut -d " " -f 1 | xargs)
1664-
CURRENT_MONGODB_CONSUMERS=$(kubectl -n ${NAMESPACE} get mongodbconsumers -l "lagoon.sh/service-type" -l "lagoon.sh/service" --no-headers | cut -d " " -f 1 | xargs)
1665-
16661655
# using the build-deploy-tool identify the deployments, volumes, and services that this build has created
16671656
LAGOON_DEPLOYMENTS_TO_JSON=$(build-deploy-tool identify lagoon-services --images /kubectl-build-deploy/images.yaml | jq -r )
16681657

16691658
echo "${LAGOON_DEPLOYMENTS_TO_JSON}"
16701659
MATCHED_MARIADB=false
16711660
DELETE_MARIADB=()
1672-
for EXIST_CONSUMERS in ${CURRENT_MARIADB_CONSUMERS}; do
1661+
for EXIST_CONSUMERS in $(echo "$ENVIRONMENT_DATA" | jq -r '.mariadbconsumers.items[]?.name'); do
16731662
for DBAAS_ENTRY in "${DBAAS[@]}"
16741663
do
16751664
IFS=':' read -ra DBAAS_ENTRY_SPLIT <<< "$DBAAS_ENTRY"
@@ -1688,7 +1677,7 @@ done
16881677

16891678
MATCHED_POSTGRES=false
16901679
DELETE_POSTGRES=()
1691-
for EXIST_CONSUMERS in ${CURRENT_POSTGRES_CONSUMERS}; do
1680+
for EXIST_CONSUMERS in $(echo "$ENVIRONMENT_DATA" | jq -r '.postgresqlconsumers.items[]?.name'); do
16921681
for DBAAS_ENTRY in "${DBAAS[@]}"
16931682
do
16941683
IFS=':' read -ra DBAAS_ENTRY_SPLIT <<< "$DBAAS_ENTRY"
@@ -1706,7 +1695,7 @@ done
17061695

17071696
MATCHED_MONGODB=false
17081697
DELETE_MONGODB=()
1709-
for EXIST_CONSUMERS in ${CURRENT_MONGODB_CONSUMERS}; do
1698+
for EXIST_CONSUMERS in $(echo "$ENVIRONMENT_DATA" | jq -r '.mongodbconsumers.items[]?.name'); do
17101699
for DBAAS_ENTRY in "${DBAAS[@]}"
17111700
do
17121701
IFS=':' read -ra DBAAS_ENTRY_SPLIT <<< "$DBAAS_ENTRY"
@@ -1725,7 +1714,7 @@ done
17251714
# check the current deployments in the environment against what the build has created and mark anything that isnt in this build as needing removal
17261715
MATCHED_DEPLOYMENT=false
17271716
DELETE_DEPLOYMENT=()
1728-
for EXIST_DEPLOYMENT in ${CURRENT_DEPLOYMENTS}; do
1717+
for EXIST_DEPLOYMENT in $(echo "$ENVIRONMENT_DATA" | jq -r '.deployments.items[]?.name'); do
17291718
for DEPLOYMENT in $(echo "$LAGOON_DEPLOYMENTS_TO_JSON" | jq -rc '.deployments[]?')
17301719
do
17311720
if [ "${EXIST_DEPLOYMENT}" == "${DEPLOYMENT}" ]; then
@@ -1741,7 +1730,7 @@ done
17411730
# check the current volumes in the environment against what the build has created and mark anything that isnt in this build as needing removal
17421731
MATCHED_VOLUME=false
17431732
DELETE_VOLUME=()
1744-
for EXIST_PVC in ${CURRENT_PVCS}; do
1733+
for EXIST_PVC in $(echo "$ENVIRONMENT_DATA" | jq -r '.pvcs.items[]?.name'); do
17451734
for VOLUME in $(echo "$LAGOON_DEPLOYMENTS_TO_JSON" | jq -rc '.volumes[]?')
17461735
do
17471736
if [ "${EXIST_PVC}" == "${VOLUME}" ]; then
@@ -1757,7 +1746,7 @@ done
17571746
# check the current services in the environment against what the build has created and mark anything that isnt in this build as needing removal
17581747
MATCHED_SERVICE=false
17591748
DELETE_SERVICE=()
1760-
for EXIST_SERVICE in ${CURRENT_SERVICES}; do
1749+
for EXIST_SERVICE in $(echo "$ENVIRONMENT_DATA" | jq -r '.services.items[]?.name'); do
17611750
for SERVICE in $(echo "$LAGOON_DEPLOYMENTS_TO_JSON" | jq -rc '.services[]?')
17621751
do
17631752
if [ "${EXIST_SERVICE}" == "${SERVICE}" ]; then
@@ -1771,6 +1760,14 @@ for EXIST_SERVICE in ${CURRENT_SERVICES}; do
17711760
MATCHED_SERVICE=false
17721761
done
17731762

1763+
# echo "$ENVIRONMENT_DATA" | jq -r '.cronjobs.items[]?.name'
1764+
# echo "$ENVIRONMENT_DATA" | jq -r '.ingress.items[]?.name'
1765+
# echo "$ENVIRONMENT_DATA" | jq -r '.secrets.items[]?.name'
1766+
# echo "$ENVIRONMENT_DATA" | jq -r '.schedulesv1.items[]?.name'
1767+
# echo "$ENVIRONMENT_DATA" | jq -r '.schedulesv1alpha1.items[]?.name'
1768+
# echo "$ENVIRONMENT_DATA" | jq -r '.prebackuppodsv1.items[]?.name'
1769+
# echo "$ENVIRONMENT_DATA" | jq -r '.prebackuppodsv1alpha1.items[]?.name'
1770+
17741771
if [[ ${#DELETE_DEPLOYMENT[@]} -ne 0 ]] || [[ ${#DELETE_SERVICE[@]} -ne 0 ]] || [[ ${#DELETE_VOLUME[@]} -ne 0 ]] || [[ ${#DELETE_MARIADB[@]} -ne 0 ]] || [[ ${#DELETE_POSTGRES[@]} -ne 0 ]] || [[ ${#DELETE_MONGODB[@]} -ne 0 ]]; then
17751772
# only show the service cleanup section if there is anything to actually clean up
17761773
beginBuildStep "Unused Service Cleanup" "unusedServiceCleanup"

0 commit comments

Comments
 (0)