Skip to content

Commit 3cd2bb6

Browse files
authored
Merge pull request #44972 from cici37/fixURL
[CEL doc] Fix the hyperlinks, add quantity, optional, CrossTypeNumericComparisons which is available now
2 parents 319a08a + 27bec3a commit 3cd2bb6

File tree

1 file changed

+59
-21
lines changed
  • content/en/docs/reference/using-api

1 file changed

+59
-21
lines changed

content/en/docs/reference/using-api/cel.md

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,21 @@ Example CEL expressions:
6565

6666
CEL is configured with the following options, libraries and language features, introduced at the specified Kubernetes versions:
6767

68-
| CEL option, library or language feature | Included | Availablity |
69-
| --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | -------------------------- |
70-
| [Standard macros](stdmacros) | `has`, `all`, `exists`, `exists_one`, `map`, `filter` | All Kubernetes versions |
71-
| [Standard functions](stdlib) | See [official list of standard definitions](stdlib) | All Kubernetes versions |
72-
| [Homogeneous Aggregate Literals](opt1) | | All Kubernetes versions |
73-
| [Default UTC Time Zone](opt2) | | All Kubernetes versions |
74-
| [Eagerly Validate Declarations](opt3) | | All Kubernetes versions |
75-
| [extended strings library](stringsgodoc), Version 1 | `charAt`, `indexOf`, `lastIndexOf`, `lowerAscii`, `upperAscii`, `replace`, `split`, `join`, `substring`, `trim` | All Kubernetes versions |
76-
| Kubernetes list library | See [Kubernetes list library](#kubernetes-list-library) | All Kubernetes versions |
77-
| Kubernetes regex library | See [Kubernetes regex library](#kubernetes-regex-library) | All Kubernetes versions |
78-
| Kubernetes URL library | See [Kubernetes URL library](#kubernetes-url-library) | All Kubernetes versions |
79-
| Kubernetes authorizer library | See [Kubernetes authorizer library](#kubernetes-authorizer-library) | All Kubernetes versions |
80-
81-
[stdmacros]: https://github.com/google/cel-spec/blob/v0.7.0/doc/langdef.md#macros
82-
[stdlib]: https://github.com/google/cel-spec/blob/master/doc/langdef.md#list-of-standard-definitions
83-
[stringsgodoc]: https://pkg.go.dev/github.com/google/cel-go/ext#Strings
84-
[opt1]: https://pkg.go.dev/github.com/google/[email protected]/cel#HomogeneousAggregateLiterals
85-
[opt2]: https://pkg.go.dev/github.com/google/[email protected]/cel#DefaultUTCTimeZone
86-
[opt3]: https://pkg.go.dev/github.com/google/[email protected]/cel#EagerlyValidateDeclarations
87-
[opt4]: https://pkg.go.dev/github.com/google/[email protected]/cel#OptionalTypes
88-
[opt5]: https://pkg.go.dev/github.com/google/[email protected]/cel#CrossTypeNumericComparisons
68+
| CEL option, library or language feature | Included | Availablity |
69+
|------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
70+
| [Standard macros](https://github.com/google/cel-spec/blob/v0.7.0/doc/langdef.md#macros) | `has`, `all`, `exists`, `exists_one`, `map`, `filter` | All Kubernetes versions |
71+
| [Standard functions](https://github.com/google/cel-spec/blob/master/doc/langdef.md#list-of-standard-definitions) | See [official list of standard definitions](https://github.com/google/cel-spec/blob/master/doc/langdef.md#list-of-standard-definitions) | All Kubernetes versions |
72+
| [Homogeneous Aggregate Literals](https://pkg.go.dev/github.com/google/[email protected]/cel#HomogeneousAggregateLiterals) | | All Kubernetes versions |
73+
| [Default UTC Time Zone](https://pkg.go.dev/github.com/google/[email protected]/cel#DefaultUTCTimeZone) | | All Kubernetes versions |
74+
| [Eagerly Validate Declarations](https://pkg.go.dev/github.com/google/[email protected]/cel#EagerlyValidateDeclarations) | | All Kubernetes versions |
75+
| [extended strings library](https://pkg.go.dev/github.com/google/cel-go/ext#Strings), Version 1 | `charAt`, `indexOf`, `lastIndexOf`, `lowerAscii`, `upperAscii`, `replace`, `split`, `join`, `substring`, `trim` | All Kubernetes versions |
76+
| Kubernetes list library | See [Kubernetes list library](#kubernetes-list-library) | All Kubernetes versions |
77+
| Kubernetes regex library | See [Kubernetes regex library](#kubernetes-regex-library) | All Kubernetes versions |
78+
| Kubernetes URL library | See [Kubernetes URL library](#kubernetes-url-library) | All Kubernetes versions |
79+
| Kubernetes authorizer library | See [Kubernetes authorizer library](#kubernetes-authorizer-library) | All Kubernetes versions |
80+
| Kubernetes quantity library | See [Kubernetes quantity library](#kubernetes-quantity-library) | Kubernetes versions 1.29+ |
81+
| CEL optional types | See [CEL optional types](https://pkg.go.dev/github.com/google/[email protected]/cel#OptionalTypes) | Kubernetes versions 1.29+ |
82+
| CEL CrossTypeNumericComparisons | See [CEL CrossTypeNumericComparisons](https://pkg.go.dev/github.com/google/[email protected]/cel#CrossTypeNumericComparisons) | Kubernetes versions 1.29+ |
8983

9084
CEL functions, features and language settings support Kubernetes control plane
9185
rollbacks. For example, _CEL Optional Values_ was introduced at Kubernetes 1.29
@@ -207,6 +201,50 @@ To perform an authorization check for a service account:
207201
See the [Kubernetes Authz library](https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz)
208202
godoc for more information.
209203

204+
### Kubernetes quantity library
205+
206+
Kubernetes 1.28 adds support for manipulating quantity strings (ex 1.5G, 512k, 20Mi)
207+
208+
- `isQuantity(string)` checks if a string is a valid Quantity according to [Kubernetes'
209+
resource.Quantity](https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity).
210+
- `quantity(string) Quantity` converts a string to a Quantity or results in an error if the
211+
string is not a valid quantity.
212+
213+
Once parsed via the `quantity` function, the resulting Quantity object has the
214+
following library of member functions:
215+
216+
{{< table caption="Available member functions of a Quantity" >}}
217+
| Member Function | CEL Return Value | Description |
218+
|-------------------------------|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
219+
| `isInteger()` | bool | returns true if and only if asInteger is safe to call without an error |
220+
| `asInteger()` | int | returns a representation of the current value as an int64 if possible or results in an error if conversion would result in overflow or loss of precision. |
221+
| `asApproximateFloat()` | float | returns a float64 representation of the quantity which may lose precision. If the value of the quantity is outside the range of a float64 +Inf/-Inf will be returned. |
222+
| `sign()` | int | Returns `1` if the quantity is positive, `-1` if it is negative. `0` if it is zero |
223+
| `add(<Quantity>)` | Quantity | Returns sum of two quantities |
224+
| `add(<int>)` | Quantity | Returns sum of quantity and an integer |
225+
| `sub(<Quantity>)` | Quantity | Returns difference between two quantities |
226+
| `sub(<int>)` | Quantity | Returns difference between a quantity and an integer |
227+
| `isLessThan(<Quantity>)` | bool | Returns true if and only if the receiver is less than the operand |
228+
| `isGreaterThan(<Quantity>)` | bool | Returns true if and only if the receiver is greater than the operand |
229+
| `compareTo(<Quantity>)` | int | Compares receiver to operand and returns 0 if they are equal, 1 if the receiver is greater, or -1 if the receiver is less than the operand |
230+
{{< /table >}}
231+
232+
Examples:
233+
234+
{{< table caption="Examples of CEL expressions using URL library functions" >}}
235+
| CEL Expression | Purpose |
236+
|---------------------------------------------------------------------------|-------------------------------------------------------|
237+
| `quantity("500000G").isInteger()` | Test if conversion to integer would throw an error |
238+
| `quantity("50k").asInteger()` | Precise conversion to integer |
239+
| `quantity("9999999999999999999999999999999999999G").asApproximateFloat()` | Lossy conversion to float |
240+
| `quantity("50k").add("20k")` | Add two quantities |
241+
| `quantity("50k").sub(20000)` | Subtract an integer from a quantity |
242+
| `quantity("50k").add(20).sub(quantity("100k")).sub(-50000)` | Chain adding and subtracting integers and quantities |
243+
| `quantity("200M").compareTo(quantity("0.2G"))` | Compare two quantities |
244+
| `quantity("150Mi").isGreaterThan(quantity("100Mi"))` | Test if a quantity is greater than the receiver |
245+
| `quantity("50M").isLessThan(quantity("100M"))` | Test if a quantity is less than the receiver |
246+
{{< /table >}}
247+
210248
## Type checking
211249

212250
CEL is a [gradually typed language](https://github.com/google/cel-spec/blob/master/doc/langdef.md#gradual-type-checking).

0 commit comments

Comments
 (0)