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
+70-29Lines changed: 70 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,9 +101,7 @@ CRDs validation, they significantly complicate the development and
101
101
operability of CRDs.
102
102
103
103
This KEP proposes that an inline expression language be integrated directly into CRDs such that a
104
-
much larger portion of validation use cases can be solved without the use of webhooks. When
105
-
selecting an exression language, we want to be sure that it can support defaulting and CRD
106
-
conversion in the future.
104
+
much larger portion of validation use cases can be solved without the use of webhooks.
107
105
108
106
This KEP proposes the adoption of [Common Expression Language
109
107
(CEL)](https://github.com/google/cel-go). It is sufficiently lightweight and safe to be run directly
@@ -237,10 +235,12 @@ will be surfaced when the validation rule evaluates to false.
237
235
extension in the schema. In the above example, the validator is scoped to the
238
236
`spec`field. `self` will be used to represent the name of the field which the validator
239
237
is scoped to.
240
-
- Consideration under adding the representative of scoped filed name: There would be composition problem while generating CRD with tools like `controller-gen`.
241
-
When trying to add validation as a marker comment to a field, the validation rule will
242
-
be hard to define without the actual field name. As the example showing below. When we want to put cel validation on ToySpec, the field name as `spec` has not
243
-
been identified yet which makes rule hard to define.
238
+
239
+
- Consideration under adding the representative of scoped filed name: There would be composition
240
+
problem while generating CRD with tools like `controller-gen`. When trying to add validation as
241
+
a marker comment to a field, the validation rule will be hard to define without the actual field
242
+
name. As the example showing below. When we want to put cel validation on ToySpec, the field
243
+
name as `spec` has not been identified yet which makes rule hard to define.
244
244
245
245
```azure
246
246
// +kubebuilder:validation:XValidator=
@@ -283,14 +283,31 @@ like the `all` macro, e.g. `self.all(listItem, <predicate>)` or `self.all(mapKey
283
283
Strategy](https://kubernetes.io/docs/reference/using-api/server-side-apply/#merge-strategy) for
284
284
details.
285
285
- The use of "old" is congruent with how `AdmissionReview` identifies the existing object as
286
-
`oldObject`. To avoid name collisions `old<propertyName>` will be treated the same as a CEL
286
+
`oldSelf`. To avoid name collisions `old<propertyName>` will be treated the same as a CEL
287
287
keyword for escaping purposes (see below).
288
288
- xref [analysis of possible interactions with immutability and
- If a object property collides with a CEL keyword (see RESERVED in [CEL Syntax](https://github.com/google/cel-spec/blob/master/doc/langdef.md#syntax)),
291
+
- If a object property name is a CEL keyword (see RESERVED in [CEL Syntax](https://github.com/google/cel-spec/blob/master/doc/langdef.md#syntax)),
292
292
it will be escaped by prepending a _ prefix. To prevent this from causing a subsequent collision, all properties with a `_` prefix will always be
293
293
prefixed by `__` (generally, N+1 the existing number of `_`s).
294
+
295
+
- If a object property name is a CEL language identifier (`int`, `uint`, `double`, `bool`, `string`,
296
+
`bytes`, `list`, `map`, `null_type`, `type`, see [CEL language
297
+
identifiers](https://github.com/google/cel-spec/blob/master/doc/langdef.md#values)) it is not
298
+
accessible as a root variable and must be accessed via `self`, .e.g. `seft.int`.
299
+
300
+
- Rules may be written at the root of an object, and may make field selection into any fields
301
+
declared in the OpenAPIv3 schema of the CRD. This includes selection of fields in both the `spec`
302
+
and `status` in the same expression, e.g. `status.quantity <= spec.maxQuantity`. Because CRDs only
303
+
allow the `name` and `generatedName` to be declared in the `metadata` of an object, these are the
304
+
only metadata fields that may be validated using CEL validator rules. For example,
305
+
`metadata.name.endsWith('mySuffix')`is allowed, but only when the OpenAPIv3 schema explicitly
306
+
declares `metadata` as a field in the root object and declares the `name` field within `metadata`.
307
+
`size(metadata.labels) < 3`however, it not allowed. The limit on which `metadata` fields may be
308
+
validated is an intentional design choice (that aims to keep metadata behavior uniform across
309
+
types) and applies to all validation mechanisms (e.g. the OpenAPIV3 `maxItems` restriction), not
310
+
just CEL validator rules.
294
311
295
312
- We plan to allow access to the current state of the object to allow validation rules to check the
296
313
new value against the current value, e.g. for immutability checks (for validation racheting we would
@@ -311,7 +328,6 @@ exact indices of the list items and the keys of map entries it traverses.
311
328
A field *pattern* is a path to all nodes in the data tree that match the pattern. I.e.
312
329
it may wildcard list item and map keys.
313
330
314
-
315
331
#### Expression lifecycle
316
332
317
333
When CRDs are written to the kube-apiserver, all expressions will be [parsed and
@@ -330,7 +346,6 @@ List of functions to include for the initial release:
330
346
- Regular Expressions
331
347
- Some Standard Definitions
332
348
333
-
334
349
Considerations:
335
350
- The functions will become VERY difficult to change as this feature matures. We
336
351
should limit ourselves initially to functions that we have a high level of
@@ -475,24 +490,50 @@ coverage of interactions in these dimensions:
0 commit comments