Files
c/kubernetes/docs/v1_validation_rule.md
Kubernetes Prow Robot f0ac80fb61 Automated openapi generation from release-1.27
Signed-off-by: Kubernetes Prow Robot <k8s.ci.robot@gmail.com>
2023-06-05 02:09:22 +00:00

6.2 KiB

v1_validation_rule_t

Properties

Name Type Description Notes
message char * Message represents the message displayed when validation fails. The message is required if the Rule contains line breaks. The message must not contain line breaks. If unset, the message is &quot;failed rule: {Rule}&quot;. e.g. &quot;must be a URL with the host matching spec.host&quot; [optional]
message_expression char * MessageExpression declares a CEL expression that evaluates to the validation failure message that is returned when this rule fails. Since messageExpression is used as a failure message, it must evaluate to a string. If both message and messageExpression are present on a rule, then messageExpression will be used if validation fails. If messageExpression results in a runtime error, the runtime error is logged, and the validation failure message is produced as if the messageExpression field were unset. If messageExpression evaluates to an empty string, a string with only spaces, or a string that contains line breaks, then the validation failure message will also be produced as if the messageExpression field were unset, and the fact that messageExpression produced an empty string/string with only spaces/string with line breaks will be logged. messageExpression has access to all the same variables as the rule; the only difference is the return type. Example: &quot;x must be less than max (&quot;+string(self.max)+&quot;)&quot; [optional]
rule char * Rule represents the expression which will be evaluated by CEL. ref: https://github.com/google/cel-spec The Rule is scoped to the location of the x-kubernetes-validations extension in the schema. The `self` variable in the CEL expression is bound to the scoped value. Example: - Rule scoped to the root of a resource with a status subresource: {&quot;rule&quot;: &quot;self.status.actual <= self.spec.maxDesired&quot;} If the Rule is scoped to an object with properties, the accessible properties of the object are field selectable via `self.field` and field presence can be checked via `has(self.field)`. Null valued fields are treated as absent fields in CEL expressions. If the Rule is scoped to an object with additionalProperties (i.e. a map) the value of the map are accessible via `self[mapKey]`, map containment can be checked via `mapKey in self` and all entries of the map are accessible via CEL macros and functions such as `self.all(...)`. If the Rule is scoped to an array, the elements of the array are accessible via `self[i]` and also by macros and functions. If the Rule is scoped to a scalar, `self` is bound to the scalar value. Examples: - Rule scoped to a map of objects: {&quot;rule&quot;: &quot;self.components['Widget'].priority < 10&quot;} - Rule scoped to a list of integers: {&quot;rule&quot;: &quot;self.values.all(value, value >= 0 && value < 100)&quot;} - Rule scoped to a string value: {&quot;rule&quot;: &quot;self.startsWith('kube')&quot;} The `apiVersion`, `kind`, `metadata.name` and `metadata.generateName` are always accessible from the root of the object and from any x-kubernetes-embedded-resource annotated objects. No other metadata properties are accessible. Unknown data preserved in custom resources via x-kubernetes-preserve-unknown-fields is not accessible in CEL expressions. This includes: - Unknown field values that are preserved by object schemas with x-kubernetes-preserve-unknown-fields. - Object properties where the property schema is of an &quot;unknown type&quot;. An &quot;unknown type&quot; is recursively defined as: - A schema with no type and x-kubernetes-preserve-unknown-fields set to true - An array where the items schema is of an &quot;unknown type&quot; - An object where the additionalProperties schema is of an &quot;unknown type&quot; Only property names of the form `[a-zA-Z_.-/][a-zA-Z0-9_.-/]*` are accessible. Accessible property names are escaped according to the following rules when accessed in the expression: - '' escapes to 'underscores' - '.' escapes to 'dot' - '-' escapes to 'dash' - '/' escapes to 'slash' - Property names that exactly match a CEL RESERVED keyword escape to '{keyword}__'. The keywords are: &quot;true&quot;, &quot;false&quot;, &quot;null&quot;, &quot;in&quot;, &quot;as&quot;, &quot;break&quot;, &quot;const&quot;, &quot;continue&quot;, &quot;else&quot;, &quot;for&quot;, &quot;function&quot;, &quot;if&quot;, &quot;import&quot;, &quot;let&quot;, &quot;loop&quot;, &quot;package&quot;, &quot;namespace&quot;, &quot;return&quot;. Examples: - Rule accessing a property named &quot;namespace&quot;: {&quot;rule&quot;: &quot;self.namespace > 0&quot;} - Rule accessing a property named &quot;x-prop&quot;: {&quot;rule&quot;: &quot;self.x__dash__prop > 0&quot;} - Rule accessing a property named &quot;redact__d&quot;: {&quot;rule&quot;: &quot;self.redact__underscores__d > 0&quot;} Equality on arrays with x-kubernetes-list-type of 'set' or 'map' ignores element order, i.e. [1, 2] == [2, 1]. Concatenation on arrays with x-kubernetes-list-type use the semantics of the list type: - 'set': `X + Y` performs a union where the array positions of all elements in `X` are preserved and non-intersecting elements in `Y` are appended, retaining their partial order. - 'map': `X + Y` performs a merge where the array positions of all keys in `X` are preserved but the values are overwritten by values in `Y` when the key sets of `X` and `Y` intersect. Elements in `Y` with non-intersecting keys are appended, retaining their partial order.

[Back to Model list] [Back to API list] [Back to README]