Skip to content

Commit 49d894e

Browse files
committed
Add example for listMap value checking for a specific key
1 parent e73e7e3 commit 49d894e

File tree

1 file changed

+4
-3
lines changed
  • keps/sig-api-machinery/2876-crd-validation-expression-language

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,13 @@ Example Validation Rules:
232232
| `self.minReplicas <= self.replicas <= self.maxReplicas` | Validate that the three fields defining replicas are ordered appropriately |
233233
| `'Available' in self.stateCounts` | Validate that an entry with the 'Available' key exists in a map |
234234
| `(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+
| `!('MY_KEY' in self.map1) || self['MY_KEY].matches('^[a-zA-Z]*$')` | Validate the value of a map for a specific key, if it is in the map |
236+
| `self.envars.filter(e, e.name = 'MY_ENV').all(e, e.value.matches('^[a-zA-Z]*$')` | Validate the 'value' field of a listMap entry where key field 'name' is 'MY_ENV' |
236237
| `has(self.expired) && self.created + self.ttl < self.expired` | Validate that 'expired' date is after a 'create' date plus a 'ttl' duration |
237238
| `self.health.startsWith('ok')` | Validate a 'health' string field has the prefix 'ok' |
238239
| `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 |
239-
| `type(self) == string ? self == '100%' : self == 1000` | Validate an int-or-string field for both the the int and string cases |
240-
| `self.metadata.name == 'singleton'` | Validate that an object's name matches a specific value (making it a singleton) |
240+
| `type(self) == string ? self == '100%' : self == 1000` | Validate an int-or-string field for both the the int and string cases |
241+
| `self.metadata.name == 'singleton'` | Validate that an object's name matches a specific value (making it a singleton) |
241242
| `self.set1.all(e, !(e in self.set2))` | Validate that two listSets are disjoint |
242243
| `size(self.names) == size(self.details) && self.names.all(n, n in self.details)` | Validate the 'details' map is keyed by the items in the 'names' listSet |
243244

0 commit comments

Comments
 (0)