k8s_openapi/v1_36/api/admissionregistration/v1/
match_condition.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct MatchCondition {
6 pub expression: std::string::String,
16
17 pub name: std::string::String,
21}
22
23impl crate::DeepMerge for MatchCondition {
24 fn merge_from(&mut self, other: Self) {
25 crate::DeepMerge::merge_from(&mut self.expression, other.expression);
26 crate::DeepMerge::merge_from(&mut self.name, other.name);
27 }
28}
29
30impl<'de> crate::serde::Deserialize<'de> for MatchCondition {
31 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
32 #[allow(non_camel_case_types)]
33 enum Field {
34 Key_expression,
35 Key_name,
36 Other,
37 }
38
39 impl<'de> crate::serde::Deserialize<'de> for Field {
40 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
41 struct Visitor;
42
43 impl crate::serde::de::Visitor<'_> for Visitor {
44 type Value = Field;
45
46 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
47 f.write_str("field identifier")
48 }
49
50 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
51 Ok(match v {
52 "expression" => Field::Key_expression,
53 "name" => Field::Key_name,
54 _ => Field::Other,
55 })
56 }
57 }
58
59 deserializer.deserialize_identifier(Visitor)
60 }
61 }
62
63 struct Visitor;
64
65 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
66 type Value = MatchCondition;
67
68 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
69 f.write_str("MatchCondition")
70 }
71
72 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
73 let mut value_expression: Option<std::string::String> = None;
74 let mut value_name: Option<std::string::String> = None;
75
76 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
77 match key {
78 Field::Key_expression => value_expression = crate::serde::de::MapAccess::next_value(&mut map)?,
79 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
80 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
81 }
82 }
83
84 Ok(MatchCondition {
85 expression: value_expression.unwrap_or_default(),
86 name: value_name.unwrap_or_default(),
87 })
88 }
89 }
90
91 deserializer.deserialize_struct(
92 "MatchCondition",
93 &[
94 "expression",
95 "name",
96 ],
97 Visitor,
98 )
99 }
100}
101
102impl crate::serde::Serialize for MatchCondition {
103 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104 let mut state = serializer.serialize_struct(
105 "MatchCondition",
106 2,
107 )?;
108 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "expression", &self.expression)?;
109 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
110 crate::serde::ser::SerializeStruct::end(state)
111 }
112}
113
114#[cfg(feature = "schemars")]
115impl crate::schemars::JsonSchema for MatchCondition {
116 fn schema_name() -> std::borrow::Cow<'static, str> {
117 "io.k8s.api.admissionregistration.v1.MatchCondition".into()
118 }
119
120 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
121 crate::schemars::json_schema!({
122 "description": "MatchCondition represents a condition which must by fulfilled for a request to be sent to a webhook.",
123 "type": "object",
124 "properties": {
125 "expression": {
126 "description": "expression represents the expression which will be evaluated by CEL. Must evaluate to bool. CEL expressions have access to the contents of the AdmissionRequest and Authorizer, organized into CEL variables:\n\n'object' - The object from the incoming request. The value is null for DELETE requests. 'oldObject' - The existing object. The value is null for CREATE requests. 'request' - Attributes of the admission request(/pkg/apis/admission/types.go#AdmissionRequest). 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request.\n See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz\n'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the\n request resource.\nDocumentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/\n\nRequired.",
127 "type": "string",
128 },
129 "name": {
130 "description": "name is an identifier for this match condition, used for strategic merging of MatchConditions, as well as providing an identifier for logging purposes. A good name should be descriptive of the associated expression. Name must be a qualified name consisting of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]') with an optional DNS subdomain prefix and '/' (e.g. 'example.com/MyName')\n\nRequired.",
131 "type": "string",
132 },
133 },
134 "required": [
135 "expression",
136 "name",
137 ],
138 })
139 }
140}
141
142#[cfg(feature = "schemars08")]
143impl crate::schemars08::JsonSchema for MatchCondition {
144 fn schema_name() -> std::string::String {
145 "io.k8s.api.admissionregistration.v1.MatchCondition".into()
146 }
147
148 fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
149 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
150 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
151 description: Some("MatchCondition represents a condition which must by fulfilled for a request to be sent to a webhook.".into()),
152 ..Default::default()
153 })),
154 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
155 object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
156 properties: [
157 (
158 "expression".into(),
159 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
160 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
161 description: Some("expression represents the expression which will be evaluated by CEL. Must evaluate to bool. CEL expressions have access to the contents of the AdmissionRequest and Authorizer, organized into CEL variables:\n\n'object' - The object from the incoming request. The value is null for DELETE requests. 'oldObject' - The existing object. The value is null for CREATE requests. 'request' - Attributes of the admission request(/pkg/apis/admission/types.go#AdmissionRequest). 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request.\n See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz\n'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the\n request resource.\nDocumentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/\n\nRequired.".into()),
162 ..Default::default()
163 })),
164 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
165 ..Default::default()
166 }),
167 ),
168 (
169 "name".into(),
170 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
171 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
172 description: Some("name is an identifier for this match condition, used for strategic merging of MatchConditions, as well as providing an identifier for logging purposes. A good name should be descriptive of the associated expression. Name must be a qualified name consisting of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]') with an optional DNS subdomain prefix and '/' (e.g. 'example.com/MyName')\n\nRequired.".into()),
173 ..Default::default()
174 })),
175 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
176 ..Default::default()
177 }),
178 ),
179 ].into(),
180 required: [
181 "expression".into(),
182 "name".into(),
183 ].into(),
184 ..Default::default()
185 })),
186 ..Default::default()
187 })
188 }
189}