Skip to content

Commit cc74f30

Browse files
authored
Merge pull request #3736 from DangerOnTheRanger/policy-string-format-update
KEP-3488: Adjust for inclusion of string.format in CEL
2 parents 21af5c7 + dbd173d commit cc74f30

File tree

1 file changed

+15
-7
lines changed
  • keps/sig-api-machinery/3488-cel-admission-control

1 file changed

+15
-7
lines changed

keps/sig-api-machinery/3488-cel-admission-control/README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ spec:
407407
validations:
408408
- name: max-replicas
409409
expression: "object.spec.replicas <= params.maxReplicas"
410-
messageExpression: "'object.spec.replicas must be no greater than ' + string(params.maxReplicas)"
410+
messageExpression: "'object.spec.replicas must be no greater than %d'.format([params.maxReplicas])"
411411
reason: Invalid
412412
# ...other rule related fields here...
413413
```
@@ -850,6 +850,11 @@ Policy definitions:
850850
- Each validation may define a message:
851851
- `message` - plain string message
852852
- `messageExpression: "<cel expression>"` (mutually exclusive with `message`)
853+
- As part of [the KEP update to add expression composition](https://github.com/kubernetes/enhancements/pull/3669/files),
854+
expressions defined under `variables` will be accessible from `messageExpression`
855+
- `messageExpression` is a CEL expression and thus factors into the runtime cost limit.
856+
If the runtime cost limit is exceeded during `messageExpression` execution, then this is logged.
857+
Whether or not the action is admitted after that depends upon failure policy.
853858
- If `message` and `messageExpression` are absent, `expression` and `name`
854859
will be included in the failure message
855860
- If `messageExpression` results in an error: `expression` and `name` will be
@@ -871,7 +876,7 @@ spec:
871876
validations:
872877
- expression: "self.name.startsWith('xyz-')"
873878
name: name-prefix
874-
messageExpression: "self.name + ' must start with xyz-'"
879+
message: "self.name must start with xyz-"
875880
reason: Unauthorized
876881
- expression: "self.name.contains('bad')"
877882
name: bad-name
@@ -880,7 +885,7 @@ spec:
880885
reason: Invalid
881886
- expression: "self.name.contains('suspicious')"
882887
name: suspicious-name
883-
messageExpression: "self.name + ' contains suspicious'"
888+
message: "'self.name contains suspicious'"
884889
code: 400
885890
reason: Invalid
886891
```
@@ -1223,7 +1228,10 @@ Plan:
12231228
To consider:
12241229

12251230
- labelSelector evaluation functions or other match evaluator functions ([original comment thread](https://github.com/kubernetes/enhancements/pull/3492#discussion_r981747317))
1226-
- `string.format(string, list(dyn))` to make `messageExpression` more convenient.
1231+
1232+
To implement:
1233+
1234+
- `string.format` into CEL upstream ([tracking PR](https://github.com/google/cel-go/pull/617)) (TODO @DangerOnTheRanger: add tracking cel-go issue once available)
12271235

12281236
#### Audit Annotations
12291237

@@ -2872,7 +2880,7 @@ For example, to validate all containers:
28722880
validations:
28732881
- scope: "spec.containers[*]"
28742882
expression: "scope.name.startsWith('xyz-')"
2875-
messageExpression: "scope.name + 'does not start with \'xyz\''"
2883+
message: "scope.name does not start with 'xyz'"
28762884
```
28772885

28782886
To make it possible to access the path information in the scope, we can offer a
@@ -2886,7 +2894,7 @@ spec.x[xKey].y[yIndex].field
28862894
validations:
28872895
- scope: "x[xKey].y[yIndex].field"
28882896
expression: "scope.startsWith('xyz-')"
2889-
messageExpression: "scopePath.xKey + ', ' + scopePath.yIndex + ': some problem'"
2897+
messageExpression: "'%s, %d: some problem'.format([scopePath.xKey, scopePath.yIndex])"
28902898
```
28912899

28922900
Prior art:
@@ -2907,7 +2915,7 @@ Note: We considered extending to a list of scopes, e.g.:
29072915
validations:
29082916
- scopes: ["spec.containers[*]", "initContainers[*]", "spec.ephemeralContainers[*]"]
29092917
expression: "scope.name.startsWith('xyz-')"
2910-
messageExpression: "scope.name + ' does not start with \'xyz\''"
2918+
message: "scope.name does not start with 'xyz'"
29112919
```
29122920

29132921
But feedback was this is signficantly more difficult to understand.

0 commit comments

Comments
 (0)