VerticalPodAutoscaler (VPA) is useful to automatically adjust the resources assigned to Pods. It requires defining a specific target resource by kind and name. There are no built-in validation checks by the VPA controller to prevent the creation of multiple VPAs which target the same resource. This policy has two rules, the first of which ensures that the only targetRef kinds accepted are one of either Deployment, StatefulSet, ReplicaSet, or DaemonSet. The second prevents the creation of duplicate VPAs by validating that any new VPA targets a unique resource.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: prevent-duplicate-vpaannotations:policies.kyverno.io/title: Prevent Duplicate VerticalPodAutoscalerspolicies.kyverno.io/category: Otherpolicies.kyverno.io/severity: mediumkyverno.io/kyverno-version: 1.11.4kyverno.io/kubernetes-version: "1.27"policies.kyverno.io/subject: VerticalPodAutoscalerpolicies.kyverno.io/description: VerticalPodAutoscaler (VPA) is useful to automatically adjust the resources assigned to Pods. It requires defining a specific target resource by kind and name. There are no built-in validation checks by the VPA controller to prevent the creation of multiple VPAs which target the same resource. This policy has two rules, the first of which ensures that the only targetRef kinds accepted are one of either Deployment, StatefulSet, ReplicaSet, or DaemonSet. The second prevents the creation of duplicate VPAs by validating that any new VPA targets a unique resource.spec:validationFailureAction: Auditbackground: falserules:- name: verify-kind-name-duplicatesmatch:any:- resources:kinds:- VerticalPodAutoscaleroperations:- CREATEvalidate:message: The target kind must be specified exactly as Deployment, StatefulSet, ReplicaSet, or DaemonSet.pattern:spec:targetRef:kind: Deployment | StatefulSet | ReplicaSet | DaemonSet- name: check-targetref-duplicatesmatch:any:- resources:kinds:- VerticalPodAutoscaleroperations:- CREATEpreconditions:all:- key:- Deployment- StatefulSet- ReplicaSet- DaemonSetoperator: AnyInvalue: "{{ request.object.spec.targetRef.kind }}"context:- name: targetsapiCall:urlPath: /apis/autoscaling.k8s.io/v1/namespaces/{{ request.namespace }}/verticalpodautoscalersjmesPath: items[?spec.targetRef.kind=='{{ request.object.spec.targetRef.kind }}'].spec.targetRef.namevalidate:message: The target {{ request.object.spec.targetRef.kind }} named {{ request.object.spec.targetRef.name }} already has an existing VPA configured for it. Duplicate VPAs are not allowed.deny:conditions:all:- key: "{{ request.object.spec.targetRef.name }}"operator: AnyInvalue: "{{ targets }}"
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.