Coder Social home page Coder Social logo

Comments (5)

JimBugwadia avatar JimBugwadia commented on July 30, 2024

Sample policy:

apiVersion : kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: limits
spec:
  validationFailureAction: enforce
  rules:
  - name: limit-lb-svc
    match:
      resources:
        kinds:
        - Service
    context:
    - name: serviceCount
      apiCall:
        urlPath: "/api/v1/namespaces/{{ request.object.metadata.namespace }}/services"
        jmesPath: "items[?spec.type == 'LoadBalancer'] | length(@)"    
    preconditions:
    - key: "{{ request.operation }}"
      operator: Equals
      value: "CREATE"
    validate:
      message: "Only one LoadBalancer service is allowed per namespace"
      deny:
        conditions:
        - key: "{{ serviceCount }}"
          operator: Equals
          value: 1

from website.

JimBugwadia avatar JimBugwadia commented on July 30, 2024
λ kubectl explain policy.spec.rules.context.apiCall
KIND:     Policy
VERSION:  kyverno.io/v1

RESOURCE: apiCall <Object>

DESCRIPTION:
     APICall is an API server request to retrieve data

FIELDS:
   jmesPath     <string>
     JMESPath is an optional JSON Match Expression that can be used to transform
     the JSON response from the API server.

   urlPath      <string> -required-
     URLPath is the URL path to be used in the HTTP GET request

from website.

chipzoller avatar chipzoller commented on July 30, 2024

@JimBugwadia, can you possibly provide some "starter" docs (in this issue is fine; I can pick up the torch) that describes the functions supported in JMESPath, the operators, and if things like wildcards are supported in that and urlPath along with a couple more examples?

from website.

JimBugwadia avatar JimBugwadia commented on July 30, 2024

Thanks, Chip! Working on it and will get a PR this weekend. I am thinking of splitting the "Variables" and "External Data Lookups" sections into separate chapters with more details on how variables are processed.

from website.

chipzoller avatar chipzoller commented on July 30, 2024

Yeah, I think those definitely should be separate pages. I'm hoping to work on the new features in docs this weekend. Also thinking more about how we can version the docs, the pain in doing so, and what value that provides...

from website.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.