apiVersion : kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: enforce-limits-fraction
spec:
  validationFailureAction: enforce
  rules:
  - name: check-memory-requests-limits
    match:
      any:
      - resources:
          kinds:
          - Pod
    validate:
      message: Limits may not exceed 2.5x the requests.
      foreach:
      - list: "request.object.spec.containers"
        preconditions:
          all:
          - key: "{{ element.resources.limits.memory || '' }}"
            operator: NotEquals
            value: ""
          - key: "{{ element.resources.requests.memory || '' }}"
            operator: NotEquals
            value: ""
        deny:
          conditions:
            any:
            - key: "{{ divide('{{ element.resources.limits.memory }}', '{{ element.resources.requests.memory }}') }}"
              operator: GreaterThan
              value: 2.5