Skip to content

Commit 566b0ea

Browse files
committed
Address 'byte' representation and escaping of weird property names
1 parent 36184df commit 566b0ea

File tree

1 file changed

+18
-14
lines changed
  • keps/sig-api-machinery/2876-crd-validation-expression-language

1 file changed

+18
-14
lines changed

keps/sig-api-machinery/2876-crd-validation-expression-language/README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -283,31 +283,36 @@ like the `all` macro, e.g. `self.all(listItem, <predicate>)` or `self.all(mapKey
283283
Strategy](https://kubernetes.io/docs/reference/using-api/server-side-apply/#merge-strategy) for
284284
details.
285285
- The use of "old" is congruent with how `AdmissionReview` identifies the existing object as
286-
`oldSelf`. To avoid name collisions `old<propertyName>` will be treated the same as a CEL
286+
`oldObject`. To avoid name collisions `old<propertyName>` will be treated the same as a CEL
287287
keyword for escaping purposes (see below).
288288
- xref [analysis of possible interactions with immutability and
289289
validation](https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/1101-immutable-fields#openapi-extension-x-kubernetes-immutable).
290290

291291
- 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-
it will be escaped by prepending a _ prefix. To prevent this from causing a subsequent collision, all properties with a `_` prefix will always be
292+
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
293293
prefixed by `__` (generally, N+1 the existing number of `_`s).
294294

295295
- If a object property name is a CEL language identifier (`int`, `uint`, `double`, `bool`, `string`,
296296
`bytes`, `list`, `map`, `null_type`, `type`, see [CEL language
297297
identifiers](https://github.com/google/cel-spec/blob/master/doc/langdef.md#values)) it is not
298298
accessible as a root variable and must be accessed via `self`, .e.g. `self.int`.
299299

300+
- If a object property name contains characters not allowed in CEL identifiers it is escaped using these rules:
301+
- `.` (period) is escaped as `__dot__`
302+
- `-` (slash) is escaped as `__slash__`
303+
- ` ` (space) is escaped as `__space__`
304+
- `__` (2 underscores) is escaped as `__underscores__`
305+
300306
- 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.
307+
declared in the OpenAPIv3 schema of the CRD as well as `apiVersion`, `kind`, `metadata.name` and
308+
`metadata.generateName`. This includes selection of fields in both the `spec` and `status` in the
309+
same expression, e.g. `status.quantity <= spec.maxQuantity`. Because CRDs only allow the `name`
310+
and `generatName` to be declared in the `metadata` of an object, these are the only metadata
311+
fields that may be validated using CEL validator rules. For example,
312+
`metadata.name.endsWith('mySuffix')` is allowed, but `size(metadata.labels) < 3` it not
313+
allowed. The limit on which `metadata` fields may be validated is an intentional design choice
314+
(that aims to keep metadata behavior uniform across types) and applies to all validation
315+
mechanisms (e.g. the OpenAPIV3 `maxItems` restriction), not just CEL validator rules.
311316

312317
- We plan to allow access to the current state of the object to allow validation rules to check the
313318
new value against the current value, e.g. for immutability checks (for validation racheting we would
@@ -505,8 +510,7 @@ Types:
505510
| 'integer' (all formats) | int (64) |
506511
| 'null' | null_type |
507512
| 'string' | string |
508-
| 'string' with format=byte | string (containing base64 encoded data) |
509-
| 'string' with format=binary | bytes |
513+
| 'string' with format=byte (base64 encoded) | bytes |
510514
| 'string' with format=date | timestamp (google.protobuf.Timestamp) |
511515
| 'string' with format=datetime | timestamp (google.protobuf.Timestamp) |
512516
| 'string' with format=duration | duration (google.protobuf.Duration) |

0 commit comments

Comments
 (0)