1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct MutatingWebhook {
6 pub admission_review_versions: Vec<String>,
8
9 pub client_config: crate::api::admissionregistration::v1::WebhookClientConfig,
11
12 pub failure_policy: Option<String>,
14
15 pub match_conditions: Option<Vec<crate::api::admissionregistration::v1::MatchCondition>>,
24
25 pub match_policy: Option<String>,
33
34 pub name: String,
36
37 pub namespace_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
69
70 pub object_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
72
73 pub reinvocation_policy: Option<String>,
81
82 pub rules: Option<Vec<crate::api::admissionregistration::v1::RuleWithOperations>>,
84
85 pub side_effects: String,
87
88 pub timeout_seconds: Option<i32>,
90}
91
92impl crate::DeepMerge for MutatingWebhook {
93 fn merge_from(&mut self, other: Self) {
94 crate::merge_strategies::list::atomic(&mut self.admission_review_versions, other.admission_review_versions);
95 crate::DeepMerge::merge_from(&mut self.client_config, other.client_config);
96 crate::DeepMerge::merge_from(&mut self.failure_policy, other.failure_policy);
97 crate::merge_strategies::list::map(
98 &mut self.match_conditions,
99 other.match_conditions,
100 &[|lhs, rhs| lhs.name == rhs.name],
101 |current_item, other_item| {
102 crate::DeepMerge::merge_from(current_item, other_item);
103 },
104 );
105 crate::DeepMerge::merge_from(&mut self.match_policy, other.match_policy);
106 crate::DeepMerge::merge_from(&mut self.name, other.name);
107 crate::DeepMerge::merge_from(&mut self.namespace_selector, other.namespace_selector);
108 crate::DeepMerge::merge_from(&mut self.object_selector, other.object_selector);
109 crate::DeepMerge::merge_from(&mut self.reinvocation_policy, other.reinvocation_policy);
110 crate::merge_strategies::list::atomic(&mut self.rules, other.rules);
111 crate::DeepMerge::merge_from(&mut self.side_effects, other.side_effects);
112 crate::DeepMerge::merge_from(&mut self.timeout_seconds, other.timeout_seconds);
113 }
114}
115
116impl<'de> crate::serde::Deserialize<'de> for MutatingWebhook {
117 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
118 #[allow(non_camel_case_types)]
119 enum Field {
120 Key_admission_review_versions,
121 Key_client_config,
122 Key_failure_policy,
123 Key_match_conditions,
124 Key_match_policy,
125 Key_name,
126 Key_namespace_selector,
127 Key_object_selector,
128 Key_reinvocation_policy,
129 Key_rules,
130 Key_side_effects,
131 Key_timeout_seconds,
132 Other,
133 }
134
135 impl<'de> crate::serde::Deserialize<'de> for Field {
136 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
137 struct Visitor;
138
139 impl crate::serde::de::Visitor<'_> for Visitor {
140 type Value = Field;
141
142 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
143 f.write_str("field identifier")
144 }
145
146 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
147 Ok(match v {
148 "admissionReviewVersions" => Field::Key_admission_review_versions,
149 "clientConfig" => Field::Key_client_config,
150 "failurePolicy" => Field::Key_failure_policy,
151 "matchConditions" => Field::Key_match_conditions,
152 "matchPolicy" => Field::Key_match_policy,
153 "name" => Field::Key_name,
154 "namespaceSelector" => Field::Key_namespace_selector,
155 "objectSelector" => Field::Key_object_selector,
156 "reinvocationPolicy" => Field::Key_reinvocation_policy,
157 "rules" => Field::Key_rules,
158 "sideEffects" => Field::Key_side_effects,
159 "timeoutSeconds" => Field::Key_timeout_seconds,
160 _ => Field::Other,
161 })
162 }
163 }
164
165 deserializer.deserialize_identifier(Visitor)
166 }
167 }
168
169 struct Visitor;
170
171 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
172 type Value = MutatingWebhook;
173
174 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
175 f.write_str("MutatingWebhook")
176 }
177
178 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
179 let mut value_admission_review_versions: Option<Vec<String>> = None;
180 let mut value_client_config: Option<crate::api::admissionregistration::v1::WebhookClientConfig> = None;
181 let mut value_failure_policy: Option<String> = None;
182 let mut value_match_conditions: Option<Vec<crate::api::admissionregistration::v1::MatchCondition>> = None;
183 let mut value_match_policy: Option<String> = None;
184 let mut value_name: Option<String> = None;
185 let mut value_namespace_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
186 let mut value_object_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
187 let mut value_reinvocation_policy: Option<String> = None;
188 let mut value_rules: Option<Vec<crate::api::admissionregistration::v1::RuleWithOperations>> = None;
189 let mut value_side_effects: Option<String> = None;
190 let mut value_timeout_seconds: Option<i32> = None;
191
192 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
193 match key {
194 Field::Key_admission_review_versions => value_admission_review_versions = crate::serde::de::MapAccess::next_value(&mut map)?,
195 Field::Key_client_config => value_client_config = crate::serde::de::MapAccess::next_value(&mut map)?,
196 Field::Key_failure_policy => value_failure_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
197 Field::Key_match_conditions => value_match_conditions = crate::serde::de::MapAccess::next_value(&mut map)?,
198 Field::Key_match_policy => value_match_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
199 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
200 Field::Key_namespace_selector => value_namespace_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
201 Field::Key_object_selector => value_object_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
202 Field::Key_reinvocation_policy => value_reinvocation_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
203 Field::Key_rules => value_rules = crate::serde::de::MapAccess::next_value(&mut map)?,
204 Field::Key_side_effects => value_side_effects = crate::serde::de::MapAccess::next_value(&mut map)?,
205 Field::Key_timeout_seconds => value_timeout_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
206 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
207 }
208 }
209
210 Ok(MutatingWebhook {
211 admission_review_versions: value_admission_review_versions.unwrap_or_default(),
212 client_config: value_client_config.unwrap_or_default(),
213 failure_policy: value_failure_policy,
214 match_conditions: value_match_conditions,
215 match_policy: value_match_policy,
216 name: value_name.unwrap_or_default(),
217 namespace_selector: value_namespace_selector,
218 object_selector: value_object_selector,
219 reinvocation_policy: value_reinvocation_policy,
220 rules: value_rules,
221 side_effects: value_side_effects.unwrap_or_default(),
222 timeout_seconds: value_timeout_seconds,
223 })
224 }
225 }
226
227 deserializer.deserialize_struct(
228 "MutatingWebhook",
229 &[
230 "admissionReviewVersions",
231 "clientConfig",
232 "failurePolicy",
233 "matchConditions",
234 "matchPolicy",
235 "name",
236 "namespaceSelector",
237 "objectSelector",
238 "reinvocationPolicy",
239 "rules",
240 "sideEffects",
241 "timeoutSeconds",
242 ],
243 Visitor,
244 )
245 }
246}
247
248impl crate::serde::Serialize for MutatingWebhook {
249 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
250 let mut state = serializer.serialize_struct(
251 "MutatingWebhook",
252 4 +
253 self.failure_policy.as_ref().map_or(0, |_| 1) +
254 self.match_conditions.as_ref().map_or(0, |_| 1) +
255 self.match_policy.as_ref().map_or(0, |_| 1) +
256 self.namespace_selector.as_ref().map_or(0, |_| 1) +
257 self.object_selector.as_ref().map_or(0, |_| 1) +
258 self.reinvocation_policy.as_ref().map_or(0, |_| 1) +
259 self.rules.as_ref().map_or(0, |_| 1) +
260 self.timeout_seconds.as_ref().map_or(0, |_| 1),
261 )?;
262 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "admissionReviewVersions", &self.admission_review_versions)?;
263 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "clientConfig", &self.client_config)?;
264 if let Some(value) = &self.failure_policy {
265 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "failurePolicy", value)?;
266 }
267 if let Some(value) = &self.match_conditions {
268 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "matchConditions", value)?;
269 }
270 if let Some(value) = &self.match_policy {
271 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "matchPolicy", value)?;
272 }
273 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
274 if let Some(value) = &self.namespace_selector {
275 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespaceSelector", value)?;
276 }
277 if let Some(value) = &self.object_selector {
278 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "objectSelector", value)?;
279 }
280 if let Some(value) = &self.reinvocation_policy {
281 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "reinvocationPolicy", value)?;
282 }
283 if let Some(value) = &self.rules {
284 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "rules", value)?;
285 }
286 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "sideEffects", &self.side_effects)?;
287 if let Some(value) = &self.timeout_seconds {
288 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "timeoutSeconds", value)?;
289 }
290 crate::serde::ser::SerializeStruct::end(state)
291 }
292}
293
294#[cfg(feature = "schemars")]
295impl crate::schemars::JsonSchema for MutatingWebhook {
296 fn schema_name() -> String {
297 "io.k8s.api.admissionregistration.v1.MutatingWebhook".to_owned()
298 }
299
300 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
301 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
302 metadata: Some(Box::new(crate::schemars::schema::Metadata {
303 description: Some("MutatingWebhook describes an admission webhook and the resources and operations it applies to.".to_owned()),
304 ..Default::default()
305 })),
306 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
307 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
308 properties: [
309 (
310 "admissionReviewVersions".to_owned(),
311 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
312 metadata: Some(Box::new(crate::schemars::schema::Metadata {
313 description: Some("AdmissionReviewVersions is an ordered list of preferred `AdmissionReview` versions the Webhook expects. API server will try to use first version in the list which it supports. If none of the versions specified in this list supported by API server, validation will fail for this object. If a persisted webhook configuration specifies allowed versions and does not include any versions known to the API Server, calls to the webhook will fail and be subject to the failure policy.".to_owned()),
314 ..Default::default()
315 })),
316 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
317 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
318 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
319 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
320 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
321 ..Default::default()
322 })
323 ))),
324 ..Default::default()
325 })),
326 ..Default::default()
327 }),
328 ),
329 (
330 "clientConfig".to_owned(),
331 {
332 let mut schema_obj = __gen.subschema_for::<crate::api::admissionregistration::v1::WebhookClientConfig>().into_object();
333 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
334 description: Some("ClientConfig defines how to communicate with the hook. Required".to_owned()),
335 ..Default::default()
336 }));
337 crate::schemars::schema::Schema::Object(schema_obj)
338 },
339 ),
340 (
341 "failurePolicy".to_owned(),
342 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
343 metadata: Some(Box::new(crate::schemars::schema::Metadata {
344 description: Some("FailurePolicy defines how unrecognized errors from the admission endpoint are handled - allowed values are Ignore or Fail. Defaults to Fail.".to_owned()),
345 ..Default::default()
346 })),
347 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
348 ..Default::default()
349 }),
350 ),
351 (
352 "matchConditions".to_owned(),
353 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
354 metadata: Some(Box::new(crate::schemars::schema::Metadata {
355 description: Some("MatchConditions is a list of conditions that must be met for a request to be sent to this webhook. Match conditions filter requests that have already been matched by the rules, namespaceSelector, and objectSelector. An empty list of matchConditions matches all requests. There are a maximum of 64 match conditions allowed.\n\nThe exact matching logic is (in order):\n 1. If ANY matchCondition evaluates to FALSE, the webhook is skipped.\n 2. If ALL matchConditions evaluate to TRUE, the webhook is called.\n 3. If any matchCondition evaluates to an error (but none are FALSE):\n - If failurePolicy=Fail, reject the request\n - If failurePolicy=Ignore, the error is ignored and the webhook is skipped".to_owned()),
356 ..Default::default()
357 })),
358 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
359 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
360 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::admissionregistration::v1::MatchCondition>()))),
361 ..Default::default()
362 })),
363 ..Default::default()
364 }),
365 ),
366 (
367 "matchPolicy".to_owned(),
368 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
369 metadata: Some(Box::new(crate::schemars::schema::Metadata {
370 description: Some("matchPolicy defines how the \"rules\" list is used to match incoming requests. Allowed values are \"Exact\" or \"Equivalent\".\n\n- Exact: match a request only if it exactly matches a specified rule. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, but \"rules\" only included `apiGroups:[\"apps\"], apiVersions:[\"v1\"], resources: [\"deployments\"]`, a request to apps/v1beta1 or extensions/v1beta1 would not be sent to the webhook.\n\n- Equivalent: match a request if modifies a resource listed in rules, even via another API group or version. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, and \"rules\" only included `apiGroups:[\"apps\"], apiVersions:[\"v1\"], resources: [\"deployments\"]`, a request to apps/v1beta1 or extensions/v1beta1 would be converted to apps/v1 and sent to the webhook.\n\nDefaults to \"Equivalent\"".to_owned()),
371 ..Default::default()
372 })),
373 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
374 ..Default::default()
375 }),
376 ),
377 (
378 "name".to_owned(),
379 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
380 metadata: Some(Box::new(crate::schemars::schema::Metadata {
381 description: Some("The name of the admission webhook. Name should be fully qualified, e.g., imagepolicy.kubernetes.io, where \"imagepolicy\" is the name of the webhook, and kubernetes.io is the name of the organization. Required.".to_owned()),
382 ..Default::default()
383 })),
384 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
385 ..Default::default()
386 }),
387 ),
388 (
389 "namespaceSelector".to_owned(),
390 {
391 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>().into_object();
392 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
393 description: Some("NamespaceSelector decides whether to run the webhook on an object based on whether the namespace for that object matches the selector. If the object itself is a namespace, the matching is performed on object.metadata.labels. If the object is another cluster scoped resource, it never skips the webhook.\n\nFor example, to run the webhook on any objects whose namespace is not associated with \"runlevel\" of \"0\" or \"1\"; you will set the selector as follows: \"namespaceSelector\": {\n \"matchExpressions\": [\n {\n \"key\": \"runlevel\",\n \"operator\": \"NotIn\",\n \"values\": [\n \"0\",\n \"1\"\n ]\n }\n ]\n}\n\nIf instead you want to only run the webhook on any objects whose namespace is associated with the \"environment\" of \"prod\" or \"staging\"; you will set the selector as follows: \"namespaceSelector\": {\n \"matchExpressions\": [\n {\n \"key\": \"environment\",\n \"operator\": \"In\",\n \"values\": [\n \"prod\",\n \"staging\"\n ]\n }\n ]\n}\n\nSee https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ for more examples of label selectors.\n\nDefault to the empty LabelSelector, which matches everything.".to_owned()),
394 ..Default::default()
395 }));
396 crate::schemars::schema::Schema::Object(schema_obj)
397 },
398 ),
399 (
400 "objectSelector".to_owned(),
401 {
402 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>().into_object();
403 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
404 description: Some("ObjectSelector decides whether to run the webhook based on if the object has matching labels. objectSelector is evaluated against both the oldObject and newObject that would be sent to the webhook, and is considered to match if either object matches the selector. A null object (oldObject in the case of create, or newObject in the case of delete) or an object that cannot have labels (like a DeploymentRollback or a PodProxyOptions object) is not considered to match. Use the object selector only if the webhook is opt-in, because end users may skip the admission webhook by setting the labels. Default to the empty LabelSelector, which matches everything.".to_owned()),
405 ..Default::default()
406 }));
407 crate::schemars::schema::Schema::Object(schema_obj)
408 },
409 ),
410 (
411 "reinvocationPolicy".to_owned(),
412 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
413 metadata: Some(Box::new(crate::schemars::schema::Metadata {
414 description: Some("reinvocationPolicy indicates whether this webhook should be called multiple times as part of a single admission evaluation. Allowed values are \"Never\" and \"IfNeeded\".\n\nNever: the webhook will not be called more than once in a single admission evaluation.\n\nIfNeeded: the webhook will be called at least one additional time as part of the admission evaluation if the object being admitted is modified by other admission plugins after the initial webhook call. Webhooks that specify this option *must* be idempotent, able to process objects they previously admitted. Note: * the number of additional invocations is not guaranteed to be exactly one. * if additional invocations result in further modifications to the object, webhooks are not guaranteed to be invoked again. * webhooks that use this option may be reordered to minimize the number of additional invocations. * to validate an object after all mutations are guaranteed complete, use a validating admission webhook instead.\n\nDefaults to \"Never\".".to_owned()),
415 ..Default::default()
416 })),
417 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
418 ..Default::default()
419 }),
420 ),
421 (
422 "rules".to_owned(),
423 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
424 metadata: Some(Box::new(crate::schemars::schema::Metadata {
425 description: Some("Rules describes what operations on what resources/subresources the webhook cares about. The webhook cares about an operation if it matches _any_ Rule. However, in order to prevent ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks from putting the cluster in a state which cannot be recovered from without completely disabling the plugin, ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks are never called on admission requests for ValidatingWebhookConfiguration and MutatingWebhookConfiguration objects.".to_owned()),
426 ..Default::default()
427 })),
428 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
429 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
430 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::admissionregistration::v1::RuleWithOperations>()))),
431 ..Default::default()
432 })),
433 ..Default::default()
434 }),
435 ),
436 (
437 "sideEffects".to_owned(),
438 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
439 metadata: Some(Box::new(crate::schemars::schema::Metadata {
440 description: Some("SideEffects states whether this webhook has side effects. Acceptable values are: None, NoneOnDryRun (webhooks created via v1beta1 may also specify Some or Unknown). Webhooks with side effects MUST implement a reconciliation system, since a request may be rejected by a future step in the admission chain and the side effects therefore need to be undone. Requests with the dryRun attribute will be auto-rejected if they match a webhook with sideEffects == Unknown or Some.".to_owned()),
441 ..Default::default()
442 })),
443 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
444 ..Default::default()
445 }),
446 ),
447 (
448 "timeoutSeconds".to_owned(),
449 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
450 metadata: Some(Box::new(crate::schemars::schema::Metadata {
451 description: Some("TimeoutSeconds specifies the timeout for this webhook. After the timeout passes, the webhook call will be ignored or the API call will fail based on the failure policy. The timeout value must be between 1 and 30 seconds. Default to 10 seconds.".to_owned()),
452 ..Default::default()
453 })),
454 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
455 format: Some("int32".to_owned()),
456 ..Default::default()
457 }),
458 ),
459 ].into(),
460 required: [
461 "admissionReviewVersions".to_owned(),
462 "clientConfig".to_owned(),
463 "name".to_owned(),
464 "sideEffects".to_owned(),
465 ].into(),
466 ..Default::default()
467 })),
468 ..Default::default()
469 })
470 }
471}