-
Notifications
You must be signed in to change notification settings - Fork 262
Add automated GCP resource cleanup script and Cloud Build pipeline #5039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @simrankaurb, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new, automated system for cleaning up unused or aged resources within a GCP project. It provides a robust bash script capable of targeting a wide array of resource types, complemented by a Cloud Build pipeline for scheduled execution and a flexible exclusion mechanism to prevent accidental deletion of important assets. The primary goal is to help manage cloud costs and maintain a tidy project environment by regularly removing ephemeral resources. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a comprehensive cleanup script for GCP resources, along with a Cloud Build configuration to run it periodically. The script is well-structured with good safety mechanisms like a dry-run mode, an exclusion file, and protection of dependent resources. My review focuses on improving the script's robustness, security, and maintainability. I've identified an area in the TPU resource handling that uses fragile parsing and can be significantly improved. I've also made suggestions to enhance the retry logic in the Cloud Build job and to refactor duplicated code for better long-term maintainability.
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a comprehensive cleanup script for GCP resources and a Cloud Build pipeline to automate it. The script is well-structured with good dependency checking and safety mechanisms like dry-run mode and an exclusion file. The hierarchical protection logic, which protects dependencies of excluded resources, is a great feature.
My review focuses on improving the script's robustness and maintainability. I've identified a few areas for improvement:
- Correcting potential bugs related to word-splitting when processing resource lists.
- Making the parsing of
gcloudoutput more reliable by switching from CSV to TSV. - Enhancing script safety with
set -euo pipefail. - Improving the reusability of the Cloud Build pipeline by parameterizing the hardcoded GCS bucket name.
These changes should make the cleanup process more reliable and the automation easier to adapt for different environments.
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a comprehensive and much-needed automated cleanup system for GCP resources. The script is well-structured, with clear phasing and robust dependency handling to prevent errors during deletion. The hierarchical protection logic, which automatically protects sub-resources of excluded items, is particularly well-designed. The inclusion of a Cloud Build pipeline with retry logic and a safe-by-default DRY_RUN mode is excellent.
My review focuses on improving the script's security and robustness by addressing the use of eval and potential race conditions in IAM modifications. I've also suggested a minor improvement to the Cloud Build configuration for better maintainability. Overall, this is a fantastic contribution to the project's operational health.
e9fc707 to
2ea8d26
Compare
This PR adds a new cleanup script designed to identify and remove stale GCP resources while strictly protecting active or explicitly exempted infrastructure. The solution is split into two primary components:
tools/cleanup.sh: A Bash script that orchestrates the discovery and deletion of various GCP resources (Compute Engine, GKE, TPU, VPC, etc.) based on age and protection rules.tools/cloud-build/project-cleanup.yaml: A Cloud Build configuration to automate the execution of the cleanup script with built-in retry logic and environment variable management.Key Features
cleanup-exemption-datefollowed by a validYYYY-MM-DDdate will be skipped until that date has passed.What this Pull Request is doing
This PR establishes a "garbage collection" system for the project's GCP environment. It solves the problem of resource leakage (and subsequent costs) by:
gcloudcommands in a specific order to avoid dependency errors.Submission Checklist
NOTE: Community submissions can take up to 2 weeks to be reviewed.
Please take the following actions before submitting this pull request.