kubewarden / cel-policy

A policy that can run CEL expressions
Apache License 2.0
3 stars 5 forks source link

docs: document the type of object returned by the kubernetes `list` call #55

Closed flavio closed 4 months ago

flavio commented 4 months ago

I had the following configuration:

    variables:
      - name: knownIngresses
        expression: |
          kw.k8s.apiVersion("networking.k8s.io/v1").kind("Ingress").list()
      - name: knownHosts
        expression: |
          variables.knownIngresses.map(i, i.spec.rules.map(r, r.host))

which failed with this message: failed to evaluate variables: no such key: spec

That happens because the list function returns a kubernetes ObjectList, meaning the ingress objects are inside of the .items variable.

The code from above has to be changed to be like that:

    variables:
      - name: knownIngresses
        expression: |
          kw.k8s.apiVersion("networking.k8s.io/v1").kind("Ingress").list()
      - name: knownHosts
        expression: |
          variables.knownIngresses.items.map(i, i.spec.rules.map(r, r.host))

Desired changed

We should update our inline docs to make clear the list() function returns an object that holds all the desired resources inside of a CEL list called .items