Skip to content

Commit

Permalink
#1291 Updated sum function docs to mention array should not be empty (#…
Browse files Browse the repository at this point in the history
…1454)

Updated sum function docs to mention array should not be empty

Signed-off-by: Sonali Srivastava <[email protected]>
Co-authored-by: shuting <[email protected]>
  • Loading branch information
cerebro1 and realshuting authored Feb 6, 2025
1 parent 16ead10 commit 78dbd0a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion content/en/docs/writing-policies/jmespath.md
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,7 @@ spec:
<details><summary>Expand</summary>
<p>

The `sum()` filter takes an array of numbers, durations, or quantities and sums them together. This is a customized version of `sum()` found in the [upstream JMESPath specification](https://jmespath.org/specification.html#sum) but augmented to support inputs common to Kubernetes workloads, specifically durations and quantities. `sum()` is similar to `add()` with the difference that `sum()` accepts an array as an input while `add()` does not. Inputs must be of a homogenous type. For example, the query `echo '{"input":['2Ki','5Gi','8Mi']}' | kyverno jp query "sum(input)"` results in the value `"5251074Ki"`. The query `echo '{"input":['2h','50s','90s']}' | kyverno jp query "sum(input)"` results in the value `"2h2m20s"`. And the query `echo '{"input":[6,3,8]}' | kyverno jp query "sum(input)"` results in the value of `17`.
The `sum()` filter takes an array of numbers, durations, or quantities and sums them together. This is a customized version of `sum()` found in the [upstream JMESPath specification](https://jmespath.org/specification.html#sum) but augmented to support inputs common to Kubernetes workloads, specifically durations and quantities. `sum()` is similar to `add()` with the difference that `sum()` accepts an array as an input while `add()` does not. This `sum()` function requires at least one element in the array. Inputs must be of a homogenous type. For example, the query `echo '{"input":['2Ki','5Gi','8Mi']}' | kyverno jp query "sum(input)"` results in the value `"5251074Ki"`. The query `echo '{"input":['2h','50s','90s']}' | kyverno jp query "sum(input)"` results in the value `"2h2m20s"`. And the query `echo '{"input":[6,3,8]}' | kyverno jp query "sum(input)"` results in the value of `17`.

Arithmetic filters like `sum()` currently accept inputs in the following formats.

Expand Down

0 comments on commit 78dbd0a

Please sign in to comment.