From 7349402b3e1003bfe086cc644fb2ab65b935d89e Mon Sep 17 00:00:00 2001 From: dellnoantechnp Date: Fri, 1 Mar 2024 14:08:01 +0800 Subject: [PATCH] bugfix: Update PrometheusAlert version 1.2.0 Update template-dd --- charts/prometheusalert/Chart.yaml | 2 +- .../templates/AlertmanagerConfig.yaml | 29 +++++ charts/prometheusalert/templates/NOTES.txt | 9 +- charts/prometheusalert/templates/_helpers.tpl | 11 ++ .../prometheusalert/templates/deployment.yaml | 2 +- charts/prometheusalert/values.yaml | 116 +++++++++++++++++- 6 files changed, 164 insertions(+), 5 deletions(-) create mode 100644 charts/prometheusalert/templates/AlertmanagerConfig.yaml diff --git a/charts/prometheusalert/Chart.yaml b/charts/prometheusalert/Chart.yaml index 9c59c61..fb5f0f4 100644 --- a/charts/prometheusalert/Chart.yaml +++ b/charts/prometheusalert/Chart.yaml @@ -18,4 +18,4 @@ maintainers: sources: - https://github.com/feiyu563/PrometheusAlert type: application -version: 1.1.6 \ No newline at end of file +version: 1.2.0 \ No newline at end of file diff --git a/charts/prometheusalert/templates/AlertmanagerConfig.yaml b/charts/prometheusalert/templates/AlertmanagerConfig.yaml new file mode 100644 index 0000000..daccb1c --- /dev/null +++ b/charts/prometheusalert/templates/AlertmanagerConfig.yaml @@ -0,0 +1,29 @@ +{{- with .Values.AlertmanagerConfig }} +{{- if .enabled -}} +{{- $fullName := include "prometheusalert.fullname" $ -}} +apiVersion: monitoring.coreos.com/v1alpha1 +kind: AlertmanagerConfig +metadata: + name: {{ $fullName }} + labels: + {{- include "prometheusalert.labels" $ | nindent 4 }} + {{- if .labels }} + {{ .labels | toYaml }} + {{- end }} +spec: + {{- if .inhibitRules }} + inhibitRules: + {{- .inhibitRules | toYaml | nindent 4 }} + {{- end }} + {{- if .muteTimeIntervals }} + muteTimeIntervals: + {{- .muteTimeIntervals | toYaml | nindent 4 }} + {{- end }} + receivers: + {{- .receivers | toYaml | nindent 4 }} + {{- if .route }} + route: + {{- .route | toYaml | nindent 4 }} + {{- end }} +{{- end }} +{{- end }} diff --git a/charts/prometheusalert/templates/NOTES.txt b/charts/prometheusalert/templates/NOTES.txt index c0da867..7da438a 100644 --- a/charts/prometheusalert/templates/NOTES.txt +++ b/charts/prometheusalert/templates/NOTES.txt @@ -19,11 +19,16 @@ echo "Visit http://127.0.0.1:8080 to use your application" kubectl port-forward $POD_NAME 8080:80 {{- end }} -2.visit it in k8s cluster by: +2. visit it in k8s cluster by: {{ template "prometheusalert.fullname" . }}.{{ .Release.Namespace }}:{{ .Values.service.port }} 3. import init.sql to mysql / postgresql on first installation complete: mysql prometheusalert < kubectl get cm {{ template "prometheusalert.name" . }} -o jsonpath='{.data.init\.sql}' -4.how to use it: +4. how to use it: Please visit https://github.com/feiyu563/PrometheusAlert to get help! + +{{- if .Values.AlertmanagerConfig.enabled }} +5. Check AlertmanagerConfig resource: + kubectl get -n {{ include "AlertmanagerConfig.namespace" }} AlertmanagerConfig {{ template "prometheusalert.fullname" . }} -o yaml +{{- end }} \ No newline at end of file diff --git a/charts/prometheusalert/templates/_helpers.tpl b/charts/prometheusalert/templates/_helpers.tpl index 1b9b627..fa9c0ec 100644 --- a/charts/prometheusalert/templates/_helpers.tpl +++ b/charts/prometheusalert/templates/_helpers.tpl @@ -43,3 +43,14 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} app.kubernetes.io/managed-by: {{ .Release.Service }} {{- end -}} + +{{/* +AlertmanagerConfig namespace +*/}} +{{- define "AlertmanagerConfig.namespace" -}} +{{- if .Values.AlertmanagerConfig.namespace }} +{{ .Values.AlertmanagerConfig.namespace }} +{{- else -}} +{{ .Release.Namespace }} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/prometheusalert/templates/deployment.yaml b/charts/prometheusalert/templates/deployment.yaml index 5c4521f..a096ee0 100644 --- a/charts/prometheusalert/templates/deployment.yaml +++ b/charts/prometheusalert/templates/deployment.yaml @@ -3,7 +3,7 @@ kind: Deployment metadata: name: {{ template "prometheusalert.fullname" . }} labels: -{{ include "prometheusalert.labels" . | indent 4 }} + {{- include "prometheusalert.labels" . | nindent 4 }} spec: replicas: {{ .Values.replicaCount }} selector: diff --git a/charts/prometheusalert/values.yaml b/charts/prometheusalert/values.yaml index bb7d8ba..21cba45 100644 --- a/charts/prometheusalert/values.yaml +++ b/charts/prometheusalert/values.yaml @@ -14,6 +14,7 @@ image: pullPolicy: IfNotPresent nameOverride: "" + fullnameOverride: "" service: @@ -38,11 +39,124 @@ resources: cpu: 10m memory: 128Mi +## @param affinity Affinity for pod assignment +## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity +## Note: podAffinityPreset, podAntiAffinityPreset, and nodeAffinityPreset will be ignored when it's set +## +affinity: {} + +## @param nodeSelector Node labels for pod assignment +## Ref: https://kubernetes.io/docs/user-guide/node-selection/ +## nodeSelector: {} +## @param tolerations Tolerations for pod assignment +## Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ +## tolerations: [] -affinity: {} +## @param receivers for AlertmanagerConfig receivers +## Ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/user-guides/alerting.md#using-alertmanagerconfig-resources +AlertmanagerConfig: + enabled: false + + ## @param namespace, if you Crd Alertmanager has alertmanagerConfigNamespaceSelector, you need to set correct namespace. + ## if you don't set alertmanagerConfigNamespaceSelector, you need to set prometheus-operator same namespace. + namespace: {} + + ## @param labels, if you Crd Alertmanager has alertmanagerConfigSelector, you need to set this. + labels: {} + + ## @param inhibitRules List of inhibition rules. The rules will only apply to alerts matching the resource's namespace. + ## Prometheus Ref: https://prometheus.io/docs/alerting/latest/configuration/#inhibit_rule + ## Crd Doc Ref: https://doc.crds.dev/github.com/prometheus-operator/kube-prometheus/monitoring.coreos.com/AlertmanagerConfig/v1alpha1@v0.13.0#spec-inhibitRules + ## Example: + ## - equal: + ## - namespace + ## - alertname + ## sourceMatch: + ## - name: severity + ## matchType: "=" + ## value: "high" + ## targetMatch: + ## - name: severity + ## matchType: "=" + ## value: "warning" + ## - name: severity + ## matchType: "=" + ## value: "info" + inhibitRules: [] + + ## @param mutiTimeIntervals List of MuteTimeInterval specifying when the routes should be muted. + ## Prometheus Ref: https://prometheus.io/docs/alerting/latest/configuration/#time_interval + ## Crd Doc Ref: https://doc.crds.dev/github.com/prometheus-operator/kube-prometheus/monitoring.coreos.com/AlertmanagerConfig/v1alpha1@v0.13.0 + ## Example: + ## - name: holidays + ## timeIntervals: + ## - daysOfMonth: + ## - start: 1 + ## end: 31 + ## months: + ## - january + ## - "may:august" + ## - "12" # "1" "2" is permit, "3" is invalid value, regex pattern "december|[1-12]", it's have a bug. + ## years: + ## - "2020:2022" + ## - "2023" + ## weekdays: + ## - "monday:friday" + ## - "wednesday" + ## times: + ## - startTime: "09:00" + ## endTime: "17:00" + muteTimeIntervals: [] + + ## @param receivers List of receivers. + ## Ref: https://doc.crds.dev/github.com/prometheus-operator/kube-prometheus/monitoring.coreos.com/AlertmanagerConfig/v1alpha1@v0.13.0#spec-receivers + ## Example: + ## - name: example-prometheusAlert + ## webhookConfigs: + ## - url: "http://prometheusalert.monitoring.svc.cluster.local:8080/prometheusalert?type=fs&tpl=prometheus-fs&alertgroup=demo" + ## urlSecret: + ## name: example-urlSecret + ## key: url + ## optional: false + ## sendResolved: true + ## httpConfig: + ## followRedirects: true + ## basicAuth: + ## username: + ## key: username + ## name: example-auth-secret + ## optional: true + ## password: + ## key: passwd + ## name: example-auth-secret + ## optional: true + receivers: [] + + ## @param routes The Alertmanager route definition for alerts matching the resource’s namespace. It will be added to the generated Alertmanager configuration as a first-level route. + ## Ref: https://doc.crds.dev/github.com/prometheus-operator/kube-prometheus/monitoring.coreos.com/AlertmanagerConfig/v1alpha1@v0.13.0#spec-route + ## Example: + ## groupBy: + ## - namespace + ## - alertname + ## matchers: + ## - name: label-name + ## value: label-value + ## groupWait: 30s + ## groupInterval: 5m + ## repeatInterval: 8h + ## receiver: example-prometheusAlert + ## routes: + ## - receiver: example-prometheusAlert + ## match: + ## severity: warning + ## activeTimeIntervals: + ## - holidays + ## muteTimeIntervals: + ## - holidays + route: [] config: app_conf: |