All Policies
Require Annotations in CEL expressions
Define and use annotations that identify semantic attributes of your application or Deployment. A common set of annotations allows tools to work collaboratively, describing objects in a common manner that all tools can understand. The recommended annotations describe applications in a way that can be queried. This policy validates that the annotation `corp.org/department` is specified with some value.
Policy Definition
/other-cel/require-annotations/require-annotations.yaml
1apiVersion: kyverno.io/v1
2kind: ClusterPolicy
3metadata:
4 name: require-annotations
5 annotations:
6 policies.kyverno.io/title: Require Annotations in CEL expressions
7 policies.kyverno.io/category: Other in CEL
8 policies.kyverno.io/severity: medium
9 policies.kyverno.io/subject: Pod, Annotation
10 kyverno.io/kyverno-version: 1.11.0
11 kyverno.io/kubernetes-version: "1.26-1.27"
12 policies.kyverno.io/description: >-
13 Define and use annotations that identify semantic attributes of your application or Deployment.
14 A common set of annotations allows tools to work collaboratively, describing objects in a common manner that
15 all tools can understand. The recommended annotations describe applications in a way that can be
16 queried. This policy validates that the annotation `corp.org/department` is specified with some value.
17spec:
18 validationFailureAction: Audit
19 background: true
20 rules:
21 - name: check-for-annotation
22 match:
23 any:
24 - resources:
25 kinds:
26 - Pod
27 operations:
28 - CREATE
29 - UPDATE
30 validate:
31 cel:
32 expressions:
33 - expression: >-
34 object.metadata.?annotations[?'corp.org/department'].orValue('') != ''
35 message: "The annotation `corp.org/department` is required."