
{{- $Values := (.helm).Values | default .Values }}
{{- $runbookUrl := ($Values.defaultRules).runbookUrl | default "https://runbooks.prometheus-operator.dev/runbooks" }}
{{- $clusterLabel := ($Values.global).clusterLabel | default "cluster" }}
{{- $additionalGroupByLabels := append $Values.defaultRules.additionalGroupByLabels $clusterLabel }}
{{- $groupLabels := join "," (uniq $additionalGroupByLabels) }}
{{- $grafanaAddr := include "vm-k8s-stack.grafana.addr" . }}
name: kubernetes-system
rules:
- alert: KubeVersionMismatch
  expr: {{ printf "count(count(label_replace(kubernetes_build_info{job!~\"kube-dns|coredns\"}, \"git_version\", \"$1\", \"git_version\", \"(v[0-9]*.[0-9]*).*\")) by(git_version,%s)) by(%s) > 1" $groupLabels $groupLabels }}
  annotations:
    description: There are {{`{{`}} $value {{`}}`}} different semantic versions of Kubernetes components running on cluster {{`{{`}} $labels.{{ $clusterLabel }} {{`}}`}}.
    runbook_url: {{ $runbookUrl }}/kubernetes/kubeversionmismatch
    summary: Different semantic versions of Kubernetes components running.
  condition: true
  for: 15m
  labels:
    severity: warning
- alert: KubeClientErrors
  expr: {{ printf "(sum(rate(rest_client_requests_total{job=\"apiserver\",code=~\"5..\"}[5m])) by(%s,instance,job,namespace) / sum(rate(rest_client_requests_total{job=\"apiserver\"}[5m])) by(%s,instance,job,namespace)) > 0.01" $groupLabels $groupLabels }}
  annotations:
    description: Kubernetes API server client '{{`{{`}} $labels.job {{`}}`}}/{{`{{`}} $labels.instance {{`}}`}}' is experiencing {{`{{`}} $value | humanizePercentage {{`}}`}} errors on cluster {{`{{`}} $labels.{{ $clusterLabel }} {{`}}`}}.
    runbook_url: {{ $runbookUrl }}/kubernetes/kubeclienterrors
    summary: Kubernetes API server client is experiencing errors.
  condition: true
  for: 15m
  labels:
    severity: warning
condition: true
