pub struct Rule {
pub rule: String,
pub message: Option<Message>,
pub field_path: Option<String>,
pub reason: Option<Reason>,
}
Expand description
Rule is a CEL validation rule for the CRD field
Fields§
§rule: String
rule 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.
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()));
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Rule
impl RefUnwindSafe for Rule
impl Send for Rule
impl Sync for Rule
impl Unpin for Rule
impl UnwindSafe for Rule
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more