You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: keps/sig-api-machinery/2876-crd-validation-expression-language/README.md
+14-15Lines changed: 14 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -232,6 +232,7 @@ Example Validation Rules:
232
232
| `self.minReplicas <= self.replicas <= self.maxReplicas` | Validate that the three fields defining replicas are ordered appropriately |
233
233
| `'Available' in self.stateCounts` | Validate that an entry with the 'Available' key exists in a map |
234
234
| `(size(self.list1) == 0) != (size(self.list2) == 0)` | Validate that one of two lists is non-empty, but not both |
235
+
| `!('MY_ENV' in self.envars) || self['MY_ENV'].matches('^[a-zA-Z]*$')` | Validate the value of a map for a specific key, if it is in the map |
235
236
| `has(self.expired) && self.created + self.ttl < self.expired` | Validate that 'expired' date is after a 'create' date plus a 'ttl' duration |
236
237
| `self.health.startsWith('ok')` | Validate a 'health' string field has the prefix 'ok' |
237
238
| `self.widgets.exists(w, w.key == 'x' && w.foo < 10)` | Validate that the 'foo' property of a listMap item with a key 'x' is less than 10 |
@@ -257,7 +258,7 @@ is scoped to.
257
258
name. As the example showing below. When we want to put cel validation on ToySpec, the field
258
259
name as `spec` has not been identified yet which makes rule hard to define.
259
260
260
-
```azure
261
+
```
261
262
// +kubebuilder:validation:XValidator=
262
263
type ToySpec struct {
263
264
fieldSample string `json:"fieldSample"`
@@ -307,30 +308,27 @@ like the `all` macro, e.g. `self.all(listItem, <predicate>)` or `self.all(mapKey
307
308
it will be escaped by prepending a _ prefix. To prevent this from causing a subsequent collision, properties named with a CEL keyword and a `_` prefix will be
308
309
prefixed by `__` (generally, N+1 the existing number of `_`s).
309
310
310
-
- Only property names of the form `[a-zA-Z_.-/][a-zA-Z0-9_.-/]*` are accessible.
311
-
If a property name is "self" or matches with a [reserved language identifier](https://github.com/google/cel-spec/blob/v0.6.0/doc/langdef.md#values)
312
-
(`int`, `uint`, `double`, `bool`, `string`, `bytes`, `list`, `map`, `null_type`, `type`), it is
313
-
not escaped, but it is excluded from the bound variables and can only be accessed via
314
-
"self.{property name}". All other accessible property names are escaped according to the following rules
315
-
when accessed in the expression:
311
+
- Only property names of the form `[a-zA-Z_.-/][a-zA-Z0-9_.-/]*` are accessible and are escaped
312
+
according to the following rules when accessed in the expression:
316
313
- '__' escapes to '__underscores__'
317
314
- '.' escapes to '__dot__'
318
315
- '-' escapes to '__dash__'
319
316
- '/' escapes to '__slash__'
320
-
- CEL RESERVED keywords escape to '__{keyword}__'. The keywords are: "true", "false", "null",
- Rules may be written at the root of an object, and may make field selection into any fields
325
322
declared in the OpenAPIv3 schema of the CRD as well as `apiVersion`, `kind`, `metadata.name` and
326
323
`metadata.generateName`. This includes selection of fields in both the `spec` and `status` in the
327
-
same expression, e.g. `self.status.quantity <= self.spec.maxQuantity`. Because CRDs only allow the `name`
328
-
and `generateName` to be declared in the `metadata` of an object, these are the only metadata
329
-
fields that may be validated using CEL validator rules. For example,
324
+
same expression, e.g. `self.status.quantity <= self.spec.maxQuantity`. Because CRDs only allow the
325
+
`name`and `generateName` to be declared in the `metadata` of an object, these are the only
326
+
metadata fields that may be validated using CEL validator rules. For example,
330
327
`self.metadata.name.endsWith('mySuffix')`is allowed, but `size(self.metadata.labels) < 3` it not
331
328
allowed. The limit on which `metadata` fields may be validated is an intentional design choice
332
-
(that aims to keep metadata behavior uniform across types) and applies to all validation
333
-
mechanisms (e.g. the OpenAPIV3 `maxItems` restriction), not just CEL validator rules.
329
+
(that aims to allow for generic access to labels and annotations across all kinds) and applies to
330
+
all validation mechanisms (e.g. the OpenAPIV3 `maxItems` restriction), not just CEL validator
331
+
rules. xref rule 4 in [specifying a structural schema](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#specifying-a-structural-schema).
334
332
335
333
- We plan to allow access to the current state of the object to allow validation rules to check the
336
334
new value against the current value, e.g. for immutability checks (for validation racheting we would
@@ -601,6 +599,7 @@ developers to test their validation rules.
601
599
602
600
#### Beta
603
601
602
+
- Resolve topic of what support we should provide for access to the previous versions of object (ie. 'oldSelf' feature)
604
603
- x-kubernetes-int-or-string is upgraded to use a union type of just int or string, not a dynamic type (CEL go support is planned in lates 2021)
605
604
- Understanding of upper bounds of CPU/memory usage and appropriate limits set to prevent abuse.
606
605
- Build-in macro/function library is comprehensive and stable (any changes to this will be a breaking change)
0 commit comments