Code Monkey home page Code Monkey logo

cats-love-money's Introduction

Cats Love Money πŸˆβ€β¬›

Set of scripts to terminate various GCP resources to save cash and cats.

Currently we support deleting:

  • Cloud Composer instances
  • GKE clusters
  • Cloud Compute instances
  • Cloud Compute disks
  • Cloud Dataproc clusters

The script by default deletes all resources older than one day. If you want to exclude the resource from being deleted you need to set a please-do-not-kill-me label on it.

Usage

Triggering manually

To use this tool manually do:

pip install -r requirements.txt
python main.py

Scheduling on GCP

You may consider deploying this script as a cloud function that will be then triggered on schedule using cloud scheduler. To do this execute:

TOPIC="delete_gcp_resources"
gcloud pubsub topics create "${TOPIC}"

gcloud functions deploy delete_gcp_resources \
    --runtime="python38" \
    --trigger-topic="${TOPIC}" \
    --timeout="500s"

gcloud scheduler jobs create pubsub delete_gcp_resources \
    --schedule="0 2 * * *" \
    --topic="${TOPIC}"
    --message-body="trigger"

or simply do

./deploy.sh

We are using Pub/Sub instead of http trigger as cloud workflows seems to have some hard times with permissions when invoking cloud functions.

cats-love-money's People

Contributors

turbaszek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cats-love-money's Issues

Delete coomposer from all regions

Hello,

Currently, the script looks at all possible Compute regions and checks if there is a Cloud Composer instance there, even if the region is not officially supported by Cloud Composer. This can be done much easier if we use Assets Inventory.

gcloud alpha asset list --project polidea-airflow --asset-types=composer.googleapis.com/Environment

This is equivalent to an HTTP request:

==== request start ====
uri: https://cloudasset.googleapis.com/v1p5beta1/projects/polidea-airflow/assets?alt=json&assetTypes=composer.googleapis.com%2FEnvironment&contentType=CONTENT_TYPE_UNSPECIFIED
method: GET
== headers start ==
b'X-Goog-User-Project': b'polidea-airflow'
b'accept': b'application/json'
b'accept-encoding': b'gzip, deflate'
b'authorization': --- Token Redacted ---
b'content-length': b'0'
b'user-agent': b'google-cloud-sdk gcloud/320.0.0 command/gcloud.alpha.asset.list invocation-id/b8260cf3f01f4a68b01784f6d1f43a3b environment/None environment-version/None interactive/True from-script/False python/3.7.2 term/xterm-256color (Macintosh; Intel Mac OS X 20.2.0)'
== headers end ==
== body start ==

== body end ==
==== request end ====

Best regards,
Kamil BreguΕ‚a

Remove more resources types

  • automl
  • bigquery_dts
  • bigquery
  • bigtable
  • cloud_build
  • cloud_memorystore
  • cloud_sql
  • cloud_storage_transfer_service
  • compute
  • datacatalog
  • dataflow
  • datafusion
  • dataprep
  • dataproc
  • datastore
  • dlp
  • functions
  • gcs
  • gcs_helper
  • kubernetes_engine
  • life_sciences
  • mlengine
  • memorystore memcached
  • memorystore redis #7
  • natural_language
  • pubsub
  • spanner #8
  • speech_to_text
  • tasks
  • text_to_speech
  • translate_speech
  • translate
  • video_intelligence
  • vision

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.