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));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Rule
impl<'de> Deserialize<'de> for Rule
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Rule
impl RefUnwindSafe for Rule
impl Send for Rule
impl Sync for Rule
impl Unpin for Rule
impl UnsafeUnpin for Rule
impl UnwindSafe for Rule
Blanket Implementations§
Source§impl<T> AnyExt for T
impl<T> AnyExt for T
Source§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind referenceSource§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable referenceSource§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointerSource§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointer