Skip to content

Commit

Permalink
Update prow job to clean up unused LBs and static IPs (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
siqidong authored Mar 14, 2024
1 parent 18e40d2 commit 840ad64
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions prow/janitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ echo "Cleaning up resources before ${LIMIT_DATE}"

# Set the project id
PROJECT_IDS=("cloudesf-testing" "cloud-api-proxy-testing")
REGIONS=("us-central1" "us-east1")
REGIONS=("us-central1" "us-east1" "us-west1")
for PROJECT in ${PROJECT_IDS[@]}; do
for REGION in ${REGIONS[@]}; do
echo "-------------------------------------------"
echo "cleaning up resources in ${REGION} for ${PROJECT}"

gcloud config set project ${PROJECT}
Expand Down Expand Up @@ -122,8 +123,7 @@ for PROJECT in ${PROJECT_IDS[@]}; do

TARGET_POOLS=$(gcloud compute target-pools list \
--regions="${REGION}" \
--filter="instances:(gke-e2e-cloud-run) \
AND creationTimestamp < ${LIMIT_DATE}" \
--filter="creationTimestamp < ${LIMIT_DATE}" \
--format='value(name)')

for targetpool in $TARGET_POOLS; do
Expand All @@ -138,6 +138,25 @@ for PROJECT in ${PROJECT_IDS[@]}; do
done
echo "Done cleaning up forwarding rules"

### Target Pools ###
# Clean up all target pools that were created older than 1 day
for targetpool in $TARGET_POOLS; do
echo "Deleting target pool ${targetpool}"
gcloud compute target-pools delete $targetpool --region $REGION --quiet
done
echo "Done cleaning up target pools"

### Static IPs ###
# Clean up static IPs that are reserved 1 day ago but not in use.
STATIC_IPS=$(gcloud compute addresses list \
--filter="status=RESERVED AND creationTimestamp < ${LIMIT_DATE}" \
--regions="${REGION}" \
--format="value(name)")
for static_ip in $STATIC_IPS; do
gcloud compute addresses delete ${static_ip} --region $REGION --quiet
done
echo "Done cleaning up unused static ips"

### Endpoints Services ###
ENDPOINTS_SERVICES=$(gcloud endpoints services list \
--filter="serviceName ~ ^e2e-test-" \
Expand Down Expand Up @@ -176,4 +195,5 @@ for PROJECT in ${PROJECT_IDS[@]}; do
echo "Done cleaning up Endpoints Services"
done
done

echo "-------------------------------------------"
echo "All Completed!"

0 comments on commit 840ad64

Please sign in to comment.