Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
firecloud-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gallant, Jason
firecloud-tools
Commits
b8fee3a5
Unverified
Commit
b8fee3a5
authored
7 years ago
by
jmthibault79
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
LEO-207: Bash script for cleaning up abandoned Dataproc clusters (#25)
parent
c1033a56
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/cleanup_clusters/README.md
+11
-0
11 additions, 0 deletions
scripts/cleanup_clusters/README.md
scripts/cleanup_clusters/cleanup_clusters.sh
+65
-0
65 additions, 0 deletions
scripts/cleanup_clusters/cleanup_clusters.sh
with
76 additions
and
0 deletions
scripts/cleanup_clusters/README.md
0 → 100644
+
11
−
0
View file @
b8fee3a5
## List and delete Dataproc clusters across projects
This script will query Google projects for old Dataproc clusters and optionally call deletion APIs.
Prerequisites: the
[
Google Cloud SDK
](
https://cloud.google.com/sdk/
)
and a Firecloud Test Domain Admin or Quality
Domain Admin user. Before running this script, log in as that user:
`gcloud auth login <email>`
Usage (from the main directory):
```
./cleanup_clusters/cleanup_clusters.sh [list|delete]```
`list` will print out the list of old clusters but not delete them. `delete` will actually delete them.
This diff is collapsed.
Click to expand it.
scripts/cleanup_clusters/cleanup_clusters.sh
0 → 100755
+
65
−
0
View file @
b8fee3a5
#!/usr/bin/env bash
ACTION
=
$1
if
[[
"
$ACTION
"
!=
"list"
&&
"
$ACTION
"
!=
"delete"
]]
then
echo
"***ERROR***"
echo
"Please choose 'list' or 'delete' actions and try again."
echo
"***ERROR***"
exit
1
fi
TEST_ADMIN_SUFFIX
=
'@test.firecloud.org'
QUALITY_ADMIN_SUFFIX
=
'@quality.firecloud.org'
USER
=
$(
gcloud auth list |
grep
'*'
|
tr
-s
' '
|
cut
-f2
-d
' '
)
echo
"You are currently logged in as
$USER
"
if
[[
"
$USER
"
!=
*
"
$TEST_ADMIN_SUFFIX
"
&&
"
$USER
"
!=
*
"
$QUALITY_ADMIN_SUFFIX
"
]]
then
echo
"***ERROR***"
echo
"This script is intended for running only by test-domain and quality-domain admins."
echo
"Please run 'gcloud auth login' with an email ending in
$TEST_ADMIN_SUFFIX
or
$QUALITY_ADMIN_SUFFIX
and try again."
echo
"***ERROR***"
exit
2
fi
# Leonardo only creates clusters in this region
CLUSTER_REGION
=
'us-central1'
for
proj
in
`
gcloud projects list
--format
=
'table(NAME)[no-heading]'
`
do
# does this project have dataproc enabled? calling 'gcloud dataproc' will error if not
DATAPROC
=
$(
gcloud services list
--enabled
--format
=
'table(NAME)[no-heading]'
--project
$proj
|
grep
dataproc.googleapis.com
)
ERR
=
$?
if
[
$ERR
-eq
0
]
then
for
cluster
in
`
gcloud dataproc clusters list
--region
$CLUSTER_REGION
--format
=
'table(NAME)[no-heading]'
--project
$proj
`
do
# get the UTC time of the last status change for this cluster
LAST_STATUS
=
$(
gcloud dataproc clusters describe
--format
=
'table(STATUS.stateStartTime)[no-heading]'
--project
$proj
--region
us-central1
$cluster
|
cut
-f1
-d
'.'
)
# NOTE! this assumes the BSD date command on OS X. Will likely need tweaks for GNU date on Linux.
SECONDS_AGO
=
$((
`
date
+%s
`
-
`
date
-j
-u
-f
'%Y-%m-%dT%H:%M:%S'
$LAST_STATUS
+%s
`
))
DAYS_AGO
=
$((
$SECONDS_AGO
/
(
60
*
60
*
24
)
))
# $((evaluation)) truncates integers, so this means "within the last day"
if
[
$DAYS_AGO
-eq
0
]
then
echo
"Not deleting cluster
$cluster
in
$proj
... last updated less than one full day ago"
else
if
[[
"
$ACTION
"
==
"delete"
]]
then
echo
"Deleting old cluster
$cluster
in
$proj
... last updated
$DAYS_AGO
days ago"
yes
| gcloud dataproc clusters delete
--async
--region
$CLUSTER_REGION
--project
$proj
$cluster
echo
else
echo
"Would delete old cluster
$cluster
in
$proj
... last updated
$DAYS_AGO
days ago"
fi
fi
done
fi
done
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment