pub struct Rule {
pub rule: String,
pub message: Option<Message>,
pub field_path: Option<String>,
pub reason: Option<Reason>,
pub optional_old_self: Option<bool>,
}Expand description
Rule is a CEL validation rule for the CRD field
Fields§
§rule: Stringrule represents the expression which will be evaluated by CEL.
The self variable in the CEL expression is bound to the scoped value.
message: Option<Message>message represents CEL validation message for the provided type If unset, the message is “failed rule: {Rule}”.
field_path: Option<String>fieldPath represents the field path returned when the validation fails. It must be a relative JSON path, scoped to the location of the field in the schema
reason: Option<Reason>reason is a machine-readable value providing more detail about why a field failed the validation.
optional_old_self: Option<bool>optionalOldSelf allows transition rules (using oldSelf) to also evaluate during object creation
When enabled, oldSelf becomes a CEL optional_type. You must use functions like optMap(), hasValue(), or orValue() to safely compare it against self.
Implementations§
Source§impl Rule
impl Rule
Sourcepub fn new(rule: impl Into<String>) -> Self
pub fn new(rule: impl Into<String>) -> Self
Initialize the rule
use kube_core::Rule;
let r = Rule::new("self == oldSelf");
assert_eq!(r.rule, "self == oldSelf".to_string())Sourcepub fn message(self, message: impl Into<Message>) -> Self
pub fn message(self, message: impl Into<Message>) -> Self
Set the rule message.
use kube_core::Rule;
use kube_core::{Rule, Message};
let r = Rule::new("self == oldSelf").message("is immutable");
assert_eq!(r.rule, "self == oldSelf".to_string());
assert_eq!(r.message, Some(Message::Message("is immutable".to_string())));Sourcepub fn reason(self, reason: impl Into<Reason>) -> Self
pub fn reason(self, reason: impl Into<Reason>) -> Self
Set the failure reason.
use kube_core::Rule;
use kube_core::{Rule, Reason};
let r = Rule::new("self == oldSelf").reason(Reason::default());
assert_eq!(r.rule, "self == oldSelf".to_string());
assert_eq!(r.reason, Some(Reason::FieldValueInvalid));Sourcepub fn field_path(self, field_path: impl Into<String>) -> Self
pub fn field_path(self, field_path: impl Into<String>) -> Self
Set the failure field_path.
use kube_core::Rule;
use kube_core::Rule;
let r = Rule::new("self == oldSelf").field_path("obj.field");
assert_eq!(r.rule, "self == oldSelf".to_string());
assert_eq!(r.field_path, Some("obj.field".to_string()));Sourcepub fn optional_old_self(self, optional: bool) -> Self
pub fn optional_old_self(self, optional: bool) -> Self
Set the optionalOldSelf configuration.
use kube_core::Rule;
let r = Rule::new("oldSelf.optMap(o, o == self).orValue(true)").optional_old_self(true);
assert_eq!(r.optional_old_self, Some(true));