Skip to content

Commit

Permalink
feat: add prometheus-rules Chart
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDones committed Jan 23, 2025
1 parent e673fe5 commit 2e7959f
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/prometheus-rules/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
7 changes: 7 additions & 0 deletions charts/prometheus-rules/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v2
name: prometheus-rules
description: A Helm chart for Prometheus Operator PrometheusRule custom resources
type: application
version: 0.0.1
maintainers:
- name: 0xDones
20 changes: 20 additions & 0 deletions charts/prometheus-rules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# prometheus-rules

![Version: 0.0.1](https://img.shields.io/badge/Version-0.0.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)

A Helm chart for Prometheus Operator PrometheusRule custom resources

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| defaultAlertLabels | object | `{}` | |
| spec.groups[0].name | string | `"./example.rules"` | |
| spec.groups[0].rules[0].alert | string | `"ExampleAlert"` | |
| spec.groups[0].rules[0].expr | string | `"Vector(1)"` | |
| spec.groups[0].rules[0].for | string | `"5m"` | |
| spec.groups[0].rules[0].labels.severity | string | `"warning"` | |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.14.2](https://github.com/norwoodj/helm-docs/releases/v1.14.2)
66 changes: 66 additions & 0 deletions charts/prometheus-rules/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "prometheus-rules.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 "prometheus-rules.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 "prometheus-rules.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "prometheus-rules.labels" -}}
helm.sh/chart: {{ include "prometheus-rules.chart" . }}
{{ include "prometheus-rules.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "prometheus-rules.selectorLabels" -}}
app.kubernetes.io/name: {{ include "prometheus-rules.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "prometheus-rules.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "prometheus-rules.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{- define "prometheus-rules.defaultAlertLabels" -}}
{{ .Values.defaultAlertLabels | toYaml }}
{{- end }}
33 changes: 33 additions & 0 deletions charts/prometheus-rules/templates/prometheus-rules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: {{ include "prometheus-rules.fullname" . }}
labels:
{{- include "prometheus-rules.labels" . | nindent 4 }}
spec:
groups:
{{- range .Values.spec.groups }}
- name: {{ .name }}
rules:
{{- range .rules }}
- expr: {{ .expr }}
{{- with .for }}
for: {{ . }}
{{- end }}
{{- with .alert }}
alert: {{ . }}
{{- end }}
{{- with .record }}
record: {{ . }}
{{- end }}
annotations: {{- .annotations | toYaml | nindent 8 }}
labels:
{{- $defaultLabels := $.Values.defaultAlertLabels | default (dict) }}
{{- $customLabels := .labels | default (dict) }}
{{- $labels := merge $defaultLabels $customLabels }}
{{- with $labels }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
11 changes: 11 additions & 0 deletions charts/prometheus-rules/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defaultAlertLabels: {}

spec:
groups:
- name: ./example.rules
rules:
- alert: ExampleAlert
expr: Vector(1)
for: 5m
labels:
severity: warning

0 comments on commit 2e7959f

Please sign in to comment.