1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct MutatingWebhook {
6 pub admission_review_versions: std::vec::Vec<std::string::String>,
8
9 pub client_config: crate::api::admissionregistration::v1::WebhookClientConfig,
11
12 pub failure_policy: Option<std::string::String>,
14
15 pub match_conditions: Option<std::vec::Vec<crate::api::admissionregistration::v1::MatchCondition>>,
24
25 pub match_policy: Option<std::string::String>,
33
34 pub name: std::string::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<std::string::String>,
81
82 pub rules: Option<std::vec::Vec<crate::api::admissionregistration::v1::RuleWithOperations>>,
84
85 pub side_effects: std::string::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 core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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<std::vec::Vec<std::string::String>> = None;
180 let mut value_client_config: Option<crate::api::admissionregistration::v1::WebhookClientConfig> = None;
181 let mut value_failure_policy: Option<std::string::String> = None;
182 let mut value_match_conditions: Option<std::vec::Vec<crate::api::admissionregistration::v1::MatchCondition>> = None;
183 let mut value_match_policy: Option<std::string::String> = None;
184 let mut value_name: Option<std::string::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<std::string::String> = None;
188 let mut value_rules: Option<std::vec::Vec<crate::api::admissionregistration::v1::RuleWithOperations>> = None;
189 let mut value_side_effects: Option<std::string::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() -> std::borrow::Cow<'static, str> {
297 "io.k8s.api.admissionregistration.v1.MutatingWebhook".into()
298 }
299
300 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
301 crate::schemars::json_schema!({
302 "description": "MutatingWebhook describes an admission webhook and the resources and operations it applies to.",
303 "type": "object",
304 "properties": {
305 "admissionReviewVersions": {
306 "description": "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.",
307 "type": "array",
308 "items": {
309 "type": "string",
310 },
311 },
312 "clientConfig": ({
313 let mut schema_obj = __gen.subschema_for::<crate::api::admissionregistration::v1::WebhookClientConfig>();
314 schema_obj.ensure_object().insert("description".into(), "ClientConfig defines how to communicate with the hook. Required".into());
315 schema_obj
316 }),
317 "failurePolicy": {
318 "description": "FailurePolicy defines how unrecognized errors from the admission endpoint are handled - allowed values are Ignore or Fail. Defaults to Fail.",
319 "type": "string",
320 },
321 "matchConditions": {
322 "description": "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",
323 "type": "array",
324 "items": (__gen.subschema_for::<crate::api::admissionregistration::v1::MatchCondition>()),
325 },
326 "matchPolicy": {
327 "description": "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\"",
328 "type": "string",
329 },
330 "name": {
331 "description": "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.",
332 "type": "string",
333 },
334 "namespaceSelector": ({
335 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>();
336 schema_obj.ensure_object().insert("description".into(), "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.".into());
337 schema_obj
338 }),
339 "objectSelector": ({
340 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>();
341 schema_obj.ensure_object().insert("description".into(), "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.".into());
342 schema_obj
343 }),
344 "reinvocationPolicy": {
345 "description": "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\".",
346 "type": "string",
347 },
348 "rules": {
349 "description": "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.",
350 "type": "array",
351 "items": (__gen.subschema_for::<crate::api::admissionregistration::v1::RuleWithOperations>()),
352 },
353 "sideEffects": {
354 "description": "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.",
355 "type": "string",
356 },
357 "timeoutSeconds": {
358 "description": "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.",
359 "type": "integer",
360 "format": "int32",
361 },
362 },
363 "required": [
364 "admissionReviewVersions",
365 "clientConfig",
366 "name",
367 "sideEffects",
368 ],
369 })
370 }
371}