From 013ea578d81c4906b2fbac5b0e90d5da46d19730 Mon Sep 17 00:00:00 2001 From: Robert Choi Date: Fri, 8 Mar 2019 13:35:33 +0900 Subject: [PATCH] add prometheus-bot chart This PS adds prometheus-bot chart to send prometheus alerts to telegram messenger Change-Id: If832945d126572d821ae631d10d39d6671f46101 Story: 2005155 --- prometheus-bot/Chart.yaml | 21 +++++ prometheus-bot/requirements.yaml | 18 ++++ prometheus-bot/templates/deployment.yaml | 75 ++++++++++++++++ .../templates/secret-telegram-token.yaml | 24 +++++ prometheus-bot/templates/service.yaml | 44 +++++++++ prometheus-bot/values.yaml | 90 +++++++++++++++++++ 6 files changed, 272 insertions(+) create mode 100644 prometheus-bot/Chart.yaml create mode 100644 prometheus-bot/requirements.yaml create mode 100644 prometheus-bot/templates/deployment.yaml create mode 100644 prometheus-bot/templates/secret-telegram-token.yaml create mode 100644 prometheus-bot/templates/service.yaml create mode 100644 prometheus-bot/values.yaml diff --git a/prometheus-bot/Chart.yaml b/prometheus-bot/Chart.yaml new file mode 100644 index 00000000..aa9a4c50 --- /dev/null +++ b/prometheus-bot/Chart.yaml @@ -0,0 +1,21 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +description: A helm chart to deploy prometheus-bot that sends prometheus alerts to telegram. +name: prometheus-bot +version: 0.1.0 +sources: + - https://github.com/inCaller/prometheus_bot + - https://git.openstack.org/openstack/openstack-helm-addons +maintainers: + - name: Openstack-Helm Authors diff --git a/prometheus-bot/requirements.yaml b/prometheus-bot/requirements.yaml new file mode 100644 index 00000000..53782e69 --- /dev/null +++ b/prometheus-bot/requirements.yaml @@ -0,0 +1,18 @@ +# Copyright 2017 The Openstack-Helm Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +dependencies: + - name: helm-toolkit + repository: http://localhost:8879/charts + version: 0.1.0 diff --git a/prometheus-bot/templates/deployment.yaml b/prometheus-bot/templates/deployment.yaml new file mode 100644 index 00000000..4f446959 --- /dev/null +++ b/prometheus-bot/templates/deployment.yaml @@ -0,0 +1,75 @@ +{{/* +Copyright 2017 The Openstack-Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/}} + +{{- $envAll := . }} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: prometheus-bot + annotations: + labels: +{{ tuple $envAll "prometheus-bot" "server" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} +spec: + replicas: {{ .Values.pod.replicas.server }} + selector: + matchLabels: +{{ tuple $envAll "prometheus-bot" "server" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 6 }} + template: + metadata: + labels: +{{ tuple $envAll "prometheus-bot" "server" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} + spec: + hostNetwork: true + affinity: +{{ tuple $envAll "prometheus-bot" "server" | include "helm-toolkit.snippets.kubernetes_pod_anti_affinity" | indent 8 }} + nodeSelector: + {{ .Values.labels.server.node_selector_key }}: {{ .Values.labels.server.node_selector_value }} + terminationGracePeriodSeconds: {{ .Values.pod.lifecycle.termination_grace_period.prometheus_bot.timeout | default "30" }} + containers: + - name: prometheus-bot +{{ tuple $envAll "prometheus_bot" | include "helm-toolkit.snippets.image" | indent 10 }} +{{ tuple $envAll $envAll.Values.pod.resources.server | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} + securityContext: + runAsUser: 0 + command: + - /prometheus_bot + - -c + - config.yaml + ports: + - name: web + containerPort: {{ tuple "server" "internal" "webhook" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} + readinessProbe: + tcpSocket: + port: {{ tuple "server" "internal" "webhook" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} + initialDelaySeconds: 15 + periodSeconds: 10 + livenessProbe: + tcpSocket: + port: {{ tuple "server" "internal" "webhook" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} + initialDelaySeconds: 180 + periodSeconds: 60 + timeoutSeconds: 5 + volumeMounts: + - name: secret-telegram-token + mountPath: /config.yaml + subPath: config.yaml + readOnly: true + volumes: + - name: secret-telegram-token + secret: + secretName: telegram-token + defaultMode: 0444 diff --git a/prometheus-bot/templates/secret-telegram-token.yaml b/prometheus-bot/templates/secret-telegram-token.yaml new file mode 100644 index 00000000..e70da202 --- /dev/null +++ b/prometheus-bot/templates/secret-telegram-token.yaml @@ -0,0 +1,24 @@ +{{/* +Copyright 2017-2018 The Openstack-Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/}} + +apiVersion: v1 +kind: Secret +metadata: + name: telegram-token +stringData: + config.yaml: | + telegram_token: {{ .Values.telegram_token }} +type: Opaque diff --git a/prometheus-bot/templates/service.yaml b/prometheus-bot/templates/service.yaml new file mode 100644 index 00000000..acd1d84f --- /dev/null +++ b/prometheus-bot/templates/service.yaml @@ -0,0 +1,44 @@ +{{/* +Copyright 2017 The Openstack-Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/}} + +{{- $envAll := . }} +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ tuple "server" "internal" . | include "helm-toolkit.endpoints.hostname_short_endpoint_lookup" }} +spec: + ports: + {{ if .Values.network.node_port.enabled }} + - name: web + protocol: TCP + nodePort: {{ .Values.network.node_port.port }} + port: {{ tuple "server" "internal" "webhook" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} + targetPort: {{ tuple "server" "internal" "webhook" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} + {{ else }} + - name: web + protocol: TCP + port: {{ tuple "server" "internal" "webhook" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} + targetPort: {{ tuple "server" "internal" "webhook" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} + {{ end }} + selector: +{{ tuple $envAll "prometheus-bot" "server" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} + {{ if .Values.network.node_port.enabled }} + type: NodePort + {{ if .Values.network.external_policy_local }} + externalTrafficPolicy: Local + {{ end }} + {{ end }} diff --git a/prometheus-bot/values.yaml b/prometheus-bot/values.yaml new file mode 100644 index 00000000..75f981f2 --- /dev/null +++ b/prometheus-bot/values.yaml @@ -0,0 +1,90 @@ +# Copyright 2017 The Openstack-Helm Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Default values for horizon. +# This is a YAML-formatted file. +# Declare name/value pairs to be passed into your templates. +# name: value + +images: + tags: + prometheus_bot: docker.io/sktdev/prometheus-bot:latest + dep_check: quay.io/stackanetes/kubernetes-entrypoint:v0.3.1 + image_repo_sync: docker.io/docker:17.07.0 + pull_policy: "IfNotPresent" + local_registry: + active: false + exclude: + - dep_check + - image_repo_sync + +labels: + server: + node_selector_key: openstack-control-plane + node_selector_value: enabled + +network: + external_policy_local: false + node_port: + enabled: false + port: 33000 + +pod: + affinity: + anti: + type: + default: preferredDuringSchedulingIgnoredDuringExecution + topologyKey: + default: kubernetes.io/hostname + mounts: + replicas: + server: 1 + lifecycle: + upgrades: + deployments: + revision_history: 3 + pod_replacement_strategy: RollingUpdate + rolling_update: + max_unavailable: 1 + max_surge: 3 + disruption_budget: + prometheus_bot: + min_available: 0 + termination_grace_period: + prometheus_bot: + timeout: 30 + resources: + enabled: false + server: + requests: + memory: "256Mi" + cpu: "200m" + limits: + memory: "1024Mi" + cpu: "2000m" + +# typically overridden by environmental +# values, but should include all endpoints +# required by this chart +endpoints: + cluster_domain_suffix: cluster.local + server: + name: prometheus-bot + hosts: + default: prometheus-bot + port: + webhook: + default: 9087 + +telegram_token: ''