diff --git a/.gitignore b/.gitignore index 0ef6c55..436c3fb 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ jsconfig.json ### Misc ### config.toml .goreleaser.yml -.DS_Store \ No newline at end of file +.DS_Store +/calert/*.tgz diff --git a/calert/.helmignore b/calert/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/calert/.helmignore @@ -0,0 +1,22 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/calert/Chart.yaml b/calert/Chart.yaml new file mode 100644 index 0000000..a4c9bcf --- /dev/null +++ b/calert/Chart.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +appVersion: 1.0.0 +description: A Helm chart for the calert webhook used for Prometheus to Google Chat integration +name: calert +version: 1.0.0 +icon: https://github.com/mr-karan/calert/raw/master/images/logo.png +home: https://github.com/mr-karan/calert +sources: +- https://github.com/mr-karan/calert +maintainers: +- name: Karan Sharma + email: karansharma1295@gmail.com diff --git a/calert/README.md b/calert/README.md new file mode 100644 index 0000000..173c177 --- /dev/null +++ b/calert/README.md @@ -0,0 +1,65 @@ +# Calert Helm chart + +calert pushes Alertmanager notifications to Google Chat via webhook integration. + + +To install the chart with the release name `calert`, in the namespace `clu-inf-all`, using the Google Hangouts Chat webhooks listed in the file `calert_values.yaml`: + +```console +$ helm install incubator/calert --values=calert_values.yaml --name=calert --namespace=clu-inf-all +``` + +calert_values.yaml + +```yaml +configmap: + rooms: | + + [app.chat.cluster001-alerts] + notification_url = "https://chat.googleapis.com/v1/spaces/xxx/messages?key=abc-xyz&token=token-unique-key%3D" + + [app.chat.cluster002-alerts] + notification_url = "https://chat.googleapis.com/v1/spaces/xxx/messages?key=abc-xyz&token=token-unique-key%3D" +``` + +## Configuration + +| Parameter | Description | Default | +|:--------------------------------------------|:-----------------------------------------------------------------|:--------------------------------| +| `image.repository` | Docker image repository | mrkaran/calert | +| `image.tag` | Docker image tag | 1.0.0-stable | +| `image.pullPolicy` | Docker image pull policy | Always | +| `replicaCount` | Number of pod replicas | 1 | +| `configmap.server.address` | Port that the app listens to in the pod | ":6000" | +| `configmap.server.socket` | Socket that the app listens to in the pod | "/tmp/calert.sock" | +| `configmap.server.name` | Name for the server instance | "calert" | +| `configmap.server.read_timeout` | Read timeout in milliseconds | "8000" | +| `configmap.server.write_timeout` | Write timeout in milliseconds | "8000" | +| `configmap.server.keepalive_timeout` | Keepalive timeout in milliseconds | "300000" | +| `configmap.app.template_file` | Application template file | "message.tmpl" | +| `configmap.app.http_client.max_idle_conns` | Client max idele connections | "100" | +| `configmap.app.http_client.request_timeout` | Client request timeout in milliseconds | "8000" | +| `configmap.rooms` | List of webhooks to send to. See `calert_values.yaml` above | [app.chat.alertManagerTestRoom] | +| `service.type` | Service type | ClusterIP | +| `service.port` | Should be same as `configmap.server.address` but without the `:` | 6000 | + + +## Alertmanager configuration +NOTE: Currently this chart has only been tested with the `prometheus-operator` chart, so that is the only configuration described below: + +The following changes should be made in the Alertmanager section of the `prometheus-operator` values file: + +```yaml +alertmanager: + config: + route: + routes: + - match: + severity: critical + receiver: google-chat + group_by: [alertname] + receivers: + - name: 'google-chat' + webhook_configs: + - url: "http://calert.clu-inf-all.svc.cluster.local:6000/create?room_name=" +``` diff --git a/calert/templates/NOTES.txt b/calert/templates/NOTES.txt new file mode 100644 index 0000000..5c9a20d --- /dev/null +++ b/calert/templates/NOTES.txt @@ -0,0 +1,15 @@ +1. Get the application URL by running these commands: +{{- if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "calert.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "calert.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "calert.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "calert.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:{{ .Values.service.port }} to use your application" + kubectl port-forward $POD_NAME {{ .Values.service.port }}:{{ .Values.service.port }} +{{- end }} diff --git a/calert/templates/_helpers.tpl b/calert/templates/_helpers.tpl new file mode 100644 index 0000000..c9b9b04 --- /dev/null +++ b/calert/templates/_helpers.tpl @@ -0,0 +1,45 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "calert.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "calert.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "calert.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "calert.labels" -}} +app.kubernetes.io/name: {{ include "calert.name" . }} +helm.sh/chart: {{ include "calert.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} diff --git a/calert/templates/configmap.yaml b/calert/templates/configmap.yaml new file mode 100644 index 0000000..49d82a9 --- /dev/null +++ b/calert/templates/configmap.yaml @@ -0,0 +1,34 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "calert.fullname" . }}-config + labels: + app: {{ template "calert.name" . }} + chart: {{ template "calert.chart" . }} + heritage: {{ .Release.Service }} + release: {{ .Release.Name }} +data: + config.toml: | + # All timeouts and durations are in milliseconds. + + [server] + address = {{ .Values.configmap.server.address | quote }} + socket = {{ .Values.configmap.server.socket | quote }} + name = {{ .Values.configmap.server.name | quote }} + + # WARNING If these timeouts are less than 1s, + # the server connection breaks. + read_timeout={{ .Values.configmap.server.read_timeout }} + write_timeout={{ .Values.configmap.server.write_timeout }} + keepalive_timeout={{ .Values.configmap.server.keepalive_timeout }} + + [app] + template_file = {{ .Values.configmap.app.template_file | quote }} + + [app.http_client] + max_idle_conns = {{ .Values.configmap.app.http_client.max_idle_conns }} + request_timeout = {{ .Values.configmap.app.http_client.request_timeout }} + + {{- with .Values.configmap.rooms }} + {{ tpl . $ | indent 4 }} + {{- end }} diff --git a/calert/templates/deployment.yaml b/calert/templates/deployment.yaml new file mode 100644 index 0000000..bf3f830 --- /dev/null +++ b/calert/templates/deployment.yaml @@ -0,0 +1,73 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "calert.fullname" . }} + labels: +{{ include "calert.labels" . | indent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "calert.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "calert.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.service.port }} + protocol: TCP + volumeMounts: + - mountPath: /etc/calert/ + name: config-dir + livenessProbe: + httpGet: + httpHeaders: + - name: X-Causation-ID + value: kube-health + path: "/ping" + port: {{ .Values.service.port }} + initialDelaySeconds: 10 + periodSeconds: 60 + timeoutSeconds: 3 + readinessProbe: + httpGet: + httpHeaders: + - name: X-Causation-ID + value: kube-health + path: "/ping" + port: {{ .Values.service.port }} + initialDelaySeconds: 10 + periodSeconds: 60 + timeoutSeconds: 3 + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: config-dir + configMap: + name: calert-config + items: + - key: config.toml + path: config.toml + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/calert/templates/service.yaml b/calert/templates/service.yaml new file mode 100644 index 0000000..e02c7e2 --- /dev/null +++ b/calert/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "calert.fullname" . }} + labels: +{{ include "calert.labels" . | indent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.service.port }} + protocol: TCP + selector: + app.kubernetes.io/name: {{ include "calert.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/calert/values.yaml b/calert/values.yaml new file mode 100644 index 0000000..9e451dd --- /dev/null +++ b/calert/values.yaml @@ -0,0 +1,57 @@ +# Default values for calert. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +configmap: + # All timeouts and durations are in milliseconds. + server: + address: ":6000" + socket: "/tmp/calert.sock" + name: "calert" + # WARNING If these timeouts are less than 1s, the server connection breaks. + read_timeout: "8000" + write_timeout: "8000" + keepalive_timeout: "300000" + app: + template_file: "message.tmpl" + http_client: + max_idle_conns: "100" + request_timeout: "8000" + rooms: | + + [app.chat.alertManagerTestRoom] + notification_url = "https://chat.googleapis.com/v1/spaces/xxx/messages?key=abc-xyz&token=token-unique-key%3D" + + [app.chat.awesomeRoomTwo] + notification_url = "https://chat.googleapis.com/v1/spaces/xxx/messages?key=abc-xyz&token=token-unique-key%3D" + +replicaCount: 1 + +image: + repository: mrkaran/calert + tag: 1.0.0-stable + pullPolicy: Always + +nameOverride: "" +fullnameOverride: "" + +service: + type: ClusterIP + port: 6000 + +ingress: + enabled: false + +resources: + limits: + cpu: 20m + memory: 48Mi + requests: + cpu: 5m + memory: 24Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {}