Skip to content

Commit

Permalink
chore: Increases project list limit for clean-up Github action (#1673)
Browse files Browse the repository at this point in the history
* get all list of projects

* use normal org instead of network one for config tests

* delete endpoints

* Revert "use normal org instead of network one for config tests"

This reverts commit 4401ad7.

* use org id to get all projects

* extract method to delete private endpoints

* remove leftover

* fix shell linter

* delete private endpoints after checking if the project has clusters

* adjusting env. vars.

* no need to check if env.vars exist because binding will fail
  • Loading branch information
lantoli committed Nov 28, 2023
1 parent 238884d commit be70c97
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/cleanup-test-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
- name: Cleanup cloud-dev
shell: bash
env:
MONGODB_ATLAS_PUBLIC_API_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }}
MONGODB_ATLAS_PRIVATE_API_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }}
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }}
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }}
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }}
MONGODB_ATLAS_OPS_MANAGER_URL: ${{vars.MONGODB_ATLAS_BASE_URL}}
MONGODB_ATLAS_BASE_URL: ${{vars.MONGODB_ATLAS_BASE_URL}}
PROJECT_TO_NOT_DELETE: ${{vars.MONGODB_ATLAS_ACCTEST_TRIGGER_PROJECT_ID_CLOUD_DEV}}
run: ./scripts/cleanup-test-env.sh
cleanup-test-env-network:
Expand All @@ -46,9 +46,9 @@ jobs:
- name: Cleanup test env network
shell: bash
env:
MONGODB_ATLAS_PUBLIC_API_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV_NETWORK }}
MONGODB_ATLAS_PRIVATE_API_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV_NETWORK }}
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV_NETWORK }}
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV_NETWORK }}
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV_NETWORK }}
MONGODB_ATLAS_OPS_MANAGER_URL: ${{vars.MONGODB_ATLAS_BASE_URL}}
MONGODB_ATLAS_BASE_URL: ${{vars.MONGODB_ATLAS_BASE_URL}}
PROJECT_TO_NOT_DELETE: ${{vars.MONGODB_ATLAS_PROJECT_ID_CLOUD_DEV_NETWORK}}
run: ./scripts/cleanup-test-env.sh
29 changes: 28 additions & 1 deletion scripts/cleanup-test-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,31 @@

set -Eeou pipefail

delete_endpoint() {
provider=$1
count=$(atlas privateEndpoints "${provider}" list --projectId "${clean_project_id}" -o=go-template="{{len .}}")
retVal=$?
if [ $retVal -ne 0 ]; then
count=0
fi
if [ "${count}" != "0" ]; then
echo "Project ${clean_project_id} contains ${provider} endpoints, will start deleting"
id=$(atlas privateEndpoints "${provider}" list --projectId "${clean_project_id}" -o=go-template="{{(index . 0).Id}}")
atlas privateEndpoints "${provider}" delete "${id}" --force --projectId "${clean_project_id}"
fi
}

projectToSkip="${PROJECT_TO_NOT_DELETE:-NONE}"


export MCLI_OPS_MANAGER_URL="${MONGODB_ATLAS_BASE_URL}"
export MCLI_PRIVATE_API_KEY="${MONGODB_ATLAS_PRIVATE_KEY}"
export MCLI_PUBLIC_API_KEY="${MONGODB_ATLAS_PUBLIC_KEY}"
export MCLI_ORG_ID="${MONGODB_ATLAS_ORG_ID}"
org_id="${MONGODB_ATLAS_ORG_ID}"

# Get all project Ids inside the organization
projects=$(atlas project ls -o json)
projects=$(atlas project ls --limit 500 --orgId "${org_id}" -o json)

echo "${projects}" | jq -c '.results[].id' | while read -r id; do
# Trim the quotes from the id
Expand All @@ -35,6 +56,12 @@ echo "${projects}" | jq -c '.results[].id' | while read -r id; do
continue
fi

set +e
delete_endpoint "aws"
delete_endpoint "gcp"
delete_endpoint "azure"
set -e

echo "Deleting projectId ${clean_project_id}"
# This command can fail if project has a cluster, a private endpoint, or general failure. The echo command always succeeds so the subshell will succeed and continue
(
Expand Down

0 comments on commit be70c97

Please sign in to comment.