diff --git a/prow/janitor.sh b/prow/janitor.sh index 3e43de00d..da538ca92 100755 --- a/prow/janitor.sh +++ b/prow/janitor.sh @@ -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} @@ -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 @@ -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-" \ @@ -176,4 +195,5 @@ for PROJECT in ${PROJECT_IDS[@]}; do echo "Done cleaning up Endpoints Services" done done - +echo "-------------------------------------------" +echo "All Completed!" \ No newline at end of file