When a Pod controller which can run multiple replicas is subject to an active PodDisruptionBudget, if the replicas field has a value equal to the minAvailable value of the PodDisruptionBudget it may prevent voluntary disruptions including Node drains which may impact routine maintenance tasks and disrupt operations. This policy checks incoming Deployments and StatefulSets which have a matching PodDisruptionBudget to ensure these two values do not match.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: pdb-minavailable-checkannotations:policies.kyverno.io/title: Check PodDisruptionBudget minAvailablepolicies.kyverno.io/category: Otherkyverno.io/kyverno-version: 1.9.0kyverno.io/kubernetes-version: "1.24"policies.kyverno.io/subject: PodDisruptionBudget, Deployment, StatefulSetpolicies.kyverno.io/description: When a Pod controller which can run multiple replicas is subject to an active PodDisruptionBudget, if the replicas field has a value equal to the minAvailable value of the PodDisruptionBudget it may prevent voluntary disruptions including Node drains which may impact routine maintenance tasks and disrupt operations. This policy checks incoming Deployments and StatefulSets which have a matching PodDisruptionBudget to ensure these two values do not match.spec:validationFailureAction: Auditbackground: falserules:- name: pdb-minavailablematch:any:- resources:kinds:- Deployment- StatefulSetpreconditions:all:- key: "{{request.operation || 'BACKGROUND'}}"operator: AnyInvalue:- CREATE- UPDATE- key: "{{ request.object.spec.replicas || `1` }}"operator: GreaterThanvalue: 0context:- name: minavailableapiCall:urlPath: /apis/policy/v1/namespaces/{{request.namespace}}/poddisruptionbudgetsjmesPath: items[?label_match(spec.selector.matchLabels, `{{request.object.spec.template.metadata.labels}}`)] | [0] | spec.minAvailable || `0`validate:message: The matching PodDisruptionBudget for this resource has its minAvailable value equal to the replica count which is not permitted.deny:conditions:any:- key: "{{ request.object.spec.replicas }}"operator: Equalsvalue: "{{ minavailable }}"
This policy prevents the use of the default project in an Application.
This policy prevents updates to the project field after an Application is created.
This policy ensures that the name of the ApplicationSet is the same value provided in the project.