diff --git a/charts/universal-chart/CHANGELOG.md b/charts/universal-chart/CHANGELOG.md index b2c05bf..0425155 100644 --- a/charts/universal-chart/CHANGELOG.md +++ b/charts/universal-chart/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## 3.3.0 - Jun 13, 2022 +* feat: add PrometheusRule support and tests + ## 3.2.0 - May 2, 2022 * feat: add HPA support and tests diff --git a/charts/universal-chart/Chart.yaml b/charts/universal-chart/Chart.yaml index c6a1e5d..f6ae3b2 100644 --- a/charts/universal-chart/Chart.yaml +++ b/charts/universal-chart/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 description: Nixys universal Helm chart for deploy your apps to Kubernetes name: universal-chart -version: 3.2.0 +version: 3.3.0 maintainers: - name: Roman Andreev email: r.andreev@nixys.ru diff --git a/charts/universal-chart/README.md b/charts/universal-chart/README.md index 0ef8daf..51ceea6 100644 --- a/charts/universal-chart/README.md +++ b/charts/universal-chart/README.md @@ -424,25 +424,50 @@ Secret `data` object is a map where value can be a string, json or base64 encode `hpas` is map of HPA parameters, where key is a name -| Name | Description | Value | -|------------------|-------------------------------------------------------------------------|-------------------------| -| `labels` | Extra HPA labels | `{}` | -| `annotations` | Extra HPA annotations | `{}` | -| `apiVersion` | apiVersion for HPA object | `"autoscaling/v2beta1"` | -| `minReplicas` | minimum replicas for HPA | `2` | -| `maxReplicas` | maximum replicas for HPA | `3` | -| `scaleTargetRef` | Required [scaleTargetRef](#hpa-scaletargetref-object-parameters) object | | -| `targetCPU` | target CPU utilization percentage | `""` | -| `targetMemory` | target memory utilization percentage | `""` | -| `metrics` | list of custom metrics | `[]` | +| Name | Description | Value | +|------------------|---------------------------------------------------------------------------|-------------------------| +| `labels` | Extra HPA labels | `{}` | +| `annotations` | Extra HPA annotations | `{}` | +| `apiVersion` | apiVersion for HPA object | `"autoscaling/v2beta1"` | +| `minReplicas` | minimum replicas for HPA | `2` | +| `maxReplicas` | maximum replicas for HPA | `3` | +| `scaleTargetRef` | (REQUIRED) [scaleTargetRef](#hpa-scaletargetref-object-parameters) object | | +| `targetCPU` | target CPU utilization percentage | `""` | +| `targetMemory` | target memory utilization percentage | `""` | +| `metrics` | list of custom metrics | `[]` | ### HPA `scaleTargetRef` object parameters -| Name | Description | Value | -|------------|----------------------------------|--------------| -| apiVersion | apiVersion for target HPA object | "apps/v1" | -| kind | kind for target HPA object | "Deployment" | -| name | Required name of target object | "" | +| Name | Description | Value | +|--------------|----------------------------------|--------------| +| `apiVersion` | apiVersion for target HPA object | "apps/v1" | +| `kind` | kind for target HPA object | "Deployment" | +| `name` | (REQUIRED) name of target object | "" | + +### PrometheusRule parameters + +`prometheusrules` is map of PrometheusRule-s, where key is a name + +| Name | Description | Value | +|----------|-----------------------------------------------------------------------------------------------------|-------| +| `labels` | Extra PrometheusRule labels | `{}` | +| `groups` | (REQUIRED) map of [PrometheusRuleGroup](#prometheusrulegroup-object-parameters) where key is a name | `{}` | + +### PrometheusRuleGroup object parameters + +| Name | Description | Value | +|------------|--------------------------------------------------------------|-------| +| `interval` | period check for alerts | `5m` | +| `rules` | map of [Alert](#alert-object-parameters) where key is a name | `{}` | + +### Alert object parameters + +| Name | Description | Value | +|---------------|------------------------------|-------| +| `expr` | (REQUIRED) PromQL expression | `""` | +| `for` | Duration for alert | `5m` | +| `labels` | Map of rule labels | `{}` | +| `annotations` | Map of rule annotations | `{}` | ## Configuration and installation details diff --git a/charts/universal-chart/results/prometheusrules.yaml b/charts/universal-chart/results/prometheusrules.yaml new file mode 100644 index 0000000..34c6807 --- /dev/null +++ b/charts/universal-chart/results/prometheusrules.yaml @@ -0,0 +1,25 @@ +--- +# Source: universal-chart/templates/prometheusrule.yml +apiVersion: monitoring.coreos.com/v1 +kind: PrometheusRule +metadata: + name: test-promrule + namespace: "default" + labels: + app.kubernetes.io/name: test + app.kubernetes.io/instance: test + app.kubernetes.io/managed-by: Helm + foo: bar +spec: + groups: + - name: "job_rules" + interval: 1m + rules: + - alert: "RedisDown" + expr: redis_up == 0 + for: 2m + labels: + severity: critical + annotations: + description: Redis instance "{{ $labels.instance }}" is down. + summary: Redis instance "{{ $labels.instance }}" down diff --git a/charts/universal-chart/samples/prometheusrules.yaml b/charts/universal-chart/samples/prometheusrules.yaml new file mode 100644 index 0000000..7eb46b3 --- /dev/null +++ b/charts/universal-chart/samples/prometheusrules.yaml @@ -0,0 +1,16 @@ +prometheusrules: + promrule: + labels: + foo: bar + groups: + job_rules: + interval: 1m + rules: + RedisDown: + expr: redis_up == 0 + for: 2m + labels: + severity: critical + annotations: + summary: Redis instance "{{ $labels.instance }}" down + description: Redis instance "{{ $labels.instance }}" is down. diff --git a/charts/universal-chart/templates/prometheusrule.yml b/charts/universal-chart/templates/prometheusrule.yml new file mode 100644 index 0000000..68f1540 --- /dev/null +++ b/charts/universal-chart/templates/prometheusrule.yml @@ -0,0 +1,31 @@ +{{- range $name, $rule := .Values.prometheusrules }} +--- +apiVersion: monitoring.coreos.com/v1 +kind: PrometheusRule +metadata: + name: {{ include "helpers.app.fullname" (dict "name" $name "context" $) }} + namespace: {{ $.Release.Namespace | quote }} + labels: + {{- include "helpers.app.labels" $ | nindent 4 }} + {{- with .labels }}{{- include "helpers.tplvalues.render" (dict "value" . "context" $) | nindent 4 }}{{- end }} +spec: + groups: + {{- range $gname, $group := $rule.groups }} + - name: {{ $gname | quote }} + interval: {{ .interval }} + rules: + {{- range $aname, $alert := .rules }} + - alert: {{ $aname | quote }} + expr: {{ .expr }} + for: {{ .for }} + labels: + {{- range $key, $value := .labels }} + {{ $key }}: {{ $value }} + {{- end }} + annotations: + {{- range $key, $value := .annotations }} + {{ $key }}: {{ $value }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/universal-chart/testit.sh b/charts/universal-chart/testit.sh index a204884..844bcc0 100755 --- a/charts/universal-chart/testit.sh +++ b/charts/universal-chart/testit.sh @@ -8,7 +8,7 @@ for filename in "$dirname"/samples/* do echo "Testing $filename" basename=$(basename "$filename") - helm template test "$dirname" --values "$filename" |grep -Ev '^ +helm.sh/chart:' > "$tests"/"$basename" + helm --kube-context="notexisting" template test "$dirname" --values "$filename" |grep -Ev '^ +helm.sh/chart:' > "$tests"/"$basename" diff -u "$dirname"/results/"$basename" "$tests"/"$basename" echo "OK" done diff --git a/charts/universal-chart/values.yaml b/charts/universal-chart/values.yaml index 1ac9216..2487a4f 100644 --- a/charts/universal-chart/values.yaml +++ b/charts/universal-chart/values.yaml @@ -260,6 +260,23 @@ servicemonitors: {} # labels: # foo: foo +prometheusrules: {} + # promrule: + # labels: + # foo: bar + # groups: + # job_rules: + # interval: 1m + # rules: + # RedisDown: + # expr: redis_up == 0 + # for: 2m + # labels: + # severity: critical + # annotations: + # summary: Redis instance "{{ $labels.instance }}" down + # description: Redis instance "{{ $labels.instance }}" is down. + diagnosticMode: enabled: false command: ["sleep"]