@@ -407,7 +407,7 @@ spec:
407
407
validations :
408
408
- name : max-replicas
409
409
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 {}'.format([ params.maxReplicas] )"
411
411
reason : Invalid
412
412
# ...other rule related fields here...
413
413
```
@@ -850,6 +850,9 @@ Policy definitions:
850
850
- Each validation may define a message :
851
851
- ` message` - plain string message
852
852
- `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
+ - While messageExpression is a CEL expression, it does not factor into the runtime cost limit.
853
856
- If `message` and `messageExpression` are absent, `expression` and `name`
854
857
will be included in the failure message
855
858
- If `messageExpression` results in an error : ` expression` and `name` will be
@@ -871,7 +874,7 @@ spec:
871
874
validations:
872
875
- expression: "self.name.startsWith('xyz-')"
873
876
name: name-prefix
874
- messageExpression: "self.name + ' must start with xyz-'"
877
+ messageExpression: "'{} must start with xyz-'.format([self.name]) "
875
878
reason: Unauthorized
876
879
- expression: "self.name.contains('bad')"
877
880
name: bad-name
@@ -880,7 +883,7 @@ spec:
880
883
reason: Invalid
881
884
- expression: "self.name.contains('suspicious')"
882
885
name: suspicious-name
883
- messageExpression: "self.name + ' contains suspicious'"
886
+ messageExpression: "'{} contains suspicious'.format([self.name]) "
884
887
code: 400
885
888
reason: Invalid
886
889
` ` `
@@ -1223,7 +1226,10 @@ Plan:
1223
1226
To consider :
1224
1227
1225
1228
- 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.
1229
+
1230
+ To implement :
1231
+
1232
+ - ` string.format` for CEL/cel-go ([tracking PR](https://github.com/google/cel-go/pull/617))
1227
1233
1228
1234
# ### Audit Annotations
1229
1235
@@ -2872,7 +2878,7 @@ For example, to validate all containers:
2872
2878
validations:
2873
2879
- scope: "spec.containers[*]"
2874
2880
expression: "scope.name.startsWith('xyz-')"
2875
- messageExpression: "scope.name + ' does not start with \' xyz\' ' "
2881
+ messageExpression: "'{} does not start with \' xyz\' -'.format([scope.name]) "
2876
2882
` ` `
2877
2883
2878
2884
To make it possible to access the path information in the scope, we can offer a
@@ -2886,7 +2892,7 @@ spec.x[xKey].y[yIndex].field
2886
2892
validations:
2887
2893
- scope: "x[xKey].y[yIndex].field"
2888
2894
expression: "scope.startsWith('xyz-')"
2889
- messageExpression: "scopePath.xKey + ', ' + scopePath.yIndex + ' : some problem'"
2895
+ messageExpression: "'{}, {} : some problem'.format([scopePath.xKey, scopePath.yIndex]) "
2890
2896
` ` `
2891
2897
2892
2898
Prior art :
@@ -2907,7 +2913,7 @@ Note: We considered extending to a list of scopes, e.g.:
2907
2913
validations:
2908
2914
- scopes: ["spec.containers[*]", "initContainers[*]", "spec.ephemeralContainers[*]"]
2909
2915
expression: "scope.name.startsWith('xyz-')"
2910
- messageExpression: "scope.name + ' does not start with \' xyz\' '"
2916
+ messageExpression: "'{} does not start with \' xyz\' '.format([scope.name]) "
2911
2917
` ` `
2912
2918
2913
2919
But feedback was this is signficantly more difficult to understand.
0 commit comments