Files
kyverno-2026-example/05-variables/02-context/restrict-deploys-during-freeze.yaml
2026-04-08 20:22:14 +07:00

53 lines
1.9 KiB
YAML
Raw Permalink 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.
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: restrict-deploys-during-freeze
annotations:
policies.kyverno.io/title: "Блокировка деплойментов во время freeze"
policies.kyverno.io/category: Governance
policies.kyverno.io/severity: high
policies.kyverno.io/subject: Deployment
policies.kyverno.io/description: >-
Блокирует создание новых Deployments когда в ConfigMap
deployment-freeze-config поле freeze_active=true.
Пользователи группы emergency-deployers и system:masters
могут деплоить даже во время freeze.
Активируйте freeze: kubectl patch configmap deployment-freeze-config
-n kyverno --type merge -p '{"data":{"freeze_active":"true"}}'
spec:
rules:
- name: check-freeze
match:
resources:
kinds:
- Deployment
preconditions:
any:
- key: "{{ request.operation }}"
operator: Equals
value: CREATE
context:
- name: freezeConfig
configMap:
name: deployment-freeze-config
namespace: kyverno
validate:
message: >-
Деплойменты заморожены с {{ freezeConfig.data.freeze_start }}
до {{ freezeConfig.data.freeze_end }}.
Причина: {{ freezeConfig.data.freeze_reason }}
Для экстренного деплоя обратитесь к oncall инженеру.
deny:
conditions:
all:
# Freeze активен
- key: "{{ freezeConfig.data.freeze_active }}"
operator: Equals
value: "true"
# Пользователь НЕ в группе экстренного деплоя
- key: "{{ request.userInfo.groups }}"
operator: AllNotIn
value:
- emergency-deployers
- system:masters