kyverno / website

User docs and sample policies: https://kyverno.io
Apache License 2.0
35 stars 147 forks source link

[Bug] Kyverno's `sum` function requires at least 1 element in the array #1291

Open AlessandroPomponio opened 3 months ago

AlessandroPomponio commented 3 months ago

Page link

https://kyverno.io/docs/writing-policies/jmespath/#sum

Description

The page mentions that the sum function in Kyverno is a custom version that has been augmented compared to the baseline JMESPath specification.

The page, however, does not mention the caveat that the sum function in Kyverno requires at least 1 element in the array, while the JMESPath specification says that the result should be 0.

This can be checked with the following: echo '{"input":[]}' | kyverno jp query "sum(input)" And seen in the source code: https://github.com/kyverno/kyverno/blob/f7a962fd11846ebebf85e33cfaf85dc92f6d117e/pkg/engine/jmespath/functions.go#L858

Expected behavior

I would expect to see a note about this behaviour, as it deviates from the JMESPath spec

Slack discussion

No response

welcome[bot] commented 3 months ago

Thanks for opening your first issue here! Be sure to follow the issue template!