Giter Club home page Giter Club logo

gke-notification-handler's Introduction

gke-notification-handler

A Cloud Function that will parse GKE cluster upgrade notifications (and upgrade available notifications) and send them to Slack.

This is a Python script meant to run in a GCP Cloud Function.

The two files here main.py and requirements.txt can be compiled into a zip file called main.py.zip and placed in a GCS bucket for retrieval by the function. Optionally, you can configure a source repo.

Setup

You'll need a Slack application with an incoming webhook token that has permission to post in whichever channel you'd like to receive these notifications.

You're free to tweak this as needed to make it work for your use case.

Environment Variables

  • SEND_UPGRADE_AVAILABLE_NOTIFICATIONS - if set to enabled, notifications will be sent regarding UpgradeAvailableEvent types. This can be verbose and annoying, so it is configurable.
  • SLACK_WEBHOOK_URL - should contain the webhook for sending to Slack.

Dependencies and Examples

  • You must have a Pub/Sub topic available to handle notifications from a given GKE cluster:
resource "google_pubsub_topic" "gke_cluster_upgrade_notifications" {
  name    = "gke-cluster-upgrade-notifications"
  project = "example-1234"

  labels = {
    ...
  }

  message_storage_policy {
    allowed_persistence_regions = [
      "region",
    ]
  }
}

Alternatively, you can create this in the UI or via gcloud.

  • You must also configure your cluster to send notifications to the topic when upgrade events are triggered. This is currently available for configuration via Terraform in the google-beta provider:
resource "google_container_cluster" "cluster" {
  provider = google-beta

  ...

  notification_config {
    pubsub {
      enabled = true
      topic   = "name-of-pubsub-topic"
    }
  }
}

Alternatively, you can enable this on a cluster via gcloud. More context available here.

  • Finally, you'll need to deploy the Cloud Function:
resource "google_cloudfunctions_function" "gke_cluster_upgrade_notifications" {
  name        = "gke-cluster-upgrade-notifications"
  description = "Sends notifications to Slack for GKE cluster upgrade notifications."
  runtime     = "python38"

  available_memory_mb   = 128
  entry_point           = "notify_slack"
  ingress_settings      = "ALLOW_INTERNAL_ONLY"
  source_archive_bucket = "gcs-bucket-name"
  source_archive_object = "main.py.zip"
  timeout               = 30

  environment_variables = {
    SLACK_WEBHOOK_URL = "foo"
  }

  event_trigger {
    event_type = "google.pubsub.topic.publish"
    resource   = google_pubsub_topic.gke_cluster_upgrade_notifications.id
    failure_policy {
      retry = true
    }
  }

  labels = {
    ...
  }
}

Alternatively, you can create this in the UI or via gcloud. You can interpet the important bits from the example above.

Note: The Terraform examples are only provided as a starting point.

gke-notification-handler's People

Contributors

echoboomer avatar

Watchers

James Cloos avatar

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.