Quick and dirty Slack bot that reminds you to remove your GKE clusters.
If you frequently use GKE clusters for development purposes you may catch yourself that sometimes you forget to delete them after you finished working. This may generate unnecessary costs for you or your company.
This tool can help you by listing all running clusters directly to the Slack channel.
Mention your bot user with @
in the desired channel.
To run the application set following environment variables:
GOOGLE_APPLICATION_CREDENTIALS
- path to GCP Service Account (not required while running on Cloud Run)GCP_PROJECT_NAME
SLACK_BOT_USER_ACCESS_TOKEN
SLACK_SIGNING_SECRET
Install dependencies:
pip install -r requirements.txt
Run:
python3 app/cleanup-reminder.py
To create a Slack application in your workspace refer to the documentation.
To configure bot for your Slack channel follow the steps below:
- Create a Slack Application
- Navigate to
OAuth & Permissions
- Add Bot Token Scopes
app_mentions:read
andchat:write
- Install Application to the Workspace to get
Bot User OAuth Access Token
- Add Bot Token Scopes
- Use
Run on Google Cloud
button to start deploying the Application- Chose the project and region
- Set environment variables when asked
GCP_PROJECT_NAME
- the project from which the clusters will be checkedSLACK_BOT_USER_ACCESS_TOKEN
- generated after installing Slack App to the workspaceSLACK_SIGNING_SECRET
- can be found in theBasic Information
section of your Slack Application
NOTE: You may encounter an error like
Error: the service did not become ready in 30s
, do not worry if the service stood up later - Get the service URL in the Cloud Shell by running:
gcloud run services describe gke-cluster-cleanup-reminder --platform managed --region {REGION_YOU_HAVE_CHOSEN} --project {PROJECT_YOU_HAVE_CHOSEN}
- Navigate to
Event Subscriptions
and enable it- Set the Request URL to the URL of your service (the challenge request might need to be retried a few times while the Application spins up)
- Subscribe to
app_mention
bot event and save the changes
- Navigate to
Interactivity & Shortcuts
in your Slack Application- Set request URL to
{SERVICE_URL}/interactive
and save changes
- Set request URL to
- Now you can add bot user to the channel by mentioning it with
@
NOTE: You can adjust the bot name and display name in the
App Home
- (optional) Set a reminder on the channel to mention the bot every day at a specific time. For example:
/remind @channel "Remove your clusters! @{BOT_USER}" every weekday at 3:30pm