Files
kyverno-2026-example/05-variables/03-templates/kyverno-policies/templates/require-labels.yaml
2026-04-08 20:22:14 +07:00

41 lines
1.2 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{{- if .Values.requiredLabels.enabled }}
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-standard-labels
annotations:
policies.kyverno.io/title: "Обязательные стандартные лейблы"
policies.kyverno.io/category: Governance
policies.kyverno.io/severity: medium
policies.kyverno.io/version: {{ .Chart.Version }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
spec:
validationFailureAction: {{ .Values.requiredLabels.failureAction | default .Values.global.failureAction }}
background: true
rules:
- name: check-required-labels
match:
resources:
kinds:
- Deployment
- StatefulSet
- DaemonSet
exclude:
resources:
namespaces:
{{- range .Values.global.excludedNamespaces }}
- {{ . }}
{{- end }}
validate:
message: >-
Ресурс '{{ "{{" }} request.object.metadata.name {{ "}}" }}'
должен иметь все обязательные лейблы:
{{ .Values.requiredLabels.labels | join ", " }}
pattern:
metadata:
labels:
{{- range .Values.requiredLabels.labels }}
{{ . }}: "?*"
{{- end }}
{{- end }}