k8s_openapi/v1_35/api/admissionregistration/v1beta1/
mutating_admission_policy_binding_spec.rs

1// Generated from definition io.k8s.api.admissionregistration.v1beta1.MutatingAdmissionPolicyBindingSpec
2
3/// MutatingAdmissionPolicyBindingSpec is the specification of the MutatingAdmissionPolicyBinding.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct MutatingAdmissionPolicyBindingSpec {
6    /// matchResources limits what resources match this binding and may be mutated by it. Note that if matchResources matches a resource, the resource must also match a policy's matchConstraints and matchConditions before the resource may be mutated. When matchResources is unset, it does not constrain resource matching, and only the policy's matchConstraints and matchConditions must match for the resource to be mutated. Additionally, matchResources.resourceRules are optional and do not constraint matching when unset. Note that this is differs from MutatingAdmissionPolicy matchConstraints, where resourceRules are required. The CREATE, UPDATE and CONNECT operations are allowed.  The DELETE operation may not be matched. '*' matches CREATE, UPDATE and CONNECT.
7    pub match_resources: Option<crate::api::admissionregistration::v1beta1::MatchResources>,
8
9    /// paramRef specifies the parameter resource used to configure the admission control policy. It should point to a resource of the type specified in spec.ParamKind of the bound MutatingAdmissionPolicy. If the policy specifies a ParamKind and the resource referred to by ParamRef does not exist, this binding is considered mis-configured and the FailurePolicy of the MutatingAdmissionPolicy applied. If the policy does not specify a ParamKind then this field is ignored, and the rules are evaluated without a param.
10    pub param_ref: Option<crate::api::admissionregistration::v1beta1::ParamRef>,
11
12    /// policyName references a MutatingAdmissionPolicy name which the MutatingAdmissionPolicyBinding binds to. If the referenced resource does not exist, this binding is considered invalid and will be ignored Required.
13    pub policy_name: Option<std::string::String>,
14}
15
16impl crate::DeepMerge for MutatingAdmissionPolicyBindingSpec {
17    fn merge_from(&mut self, other: Self) {
18        crate::DeepMerge::merge_from(&mut self.match_resources, other.match_resources);
19        crate::DeepMerge::merge_from(&mut self.param_ref, other.param_ref);
20        crate::DeepMerge::merge_from(&mut self.policy_name, other.policy_name);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for MutatingAdmissionPolicyBindingSpec {
25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26        #[allow(non_camel_case_types)]
27        enum Field {
28            Key_match_resources,
29            Key_param_ref,
30            Key_policy_name,
31            Other,
32        }
33
34        impl<'de> crate::serde::Deserialize<'de> for Field {
35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36                struct Visitor;
37
38                impl crate::serde::de::Visitor<'_> for Visitor {
39                    type Value = Field;
40
41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42                        f.write_str("field identifier")
43                    }
44
45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46                        Ok(match v {
47                            "matchResources" => Field::Key_match_resources,
48                            "paramRef" => Field::Key_param_ref,
49                            "policyName" => Field::Key_policy_name,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = MutatingAdmissionPolicyBindingSpec;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("MutatingAdmissionPolicyBindingSpec")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_match_resources: Option<crate::api::admissionregistration::v1beta1::MatchResources> = None;
70                let mut value_param_ref: Option<crate::api::admissionregistration::v1beta1::ParamRef> = None;
71                let mut value_policy_name: Option<std::string::String> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_match_resources => value_match_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_param_ref => value_param_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_policy_name => value_policy_name = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79                    }
80                }
81
82                Ok(MutatingAdmissionPolicyBindingSpec {
83                    match_resources: value_match_resources,
84                    param_ref: value_param_ref,
85                    policy_name: value_policy_name,
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "MutatingAdmissionPolicyBindingSpec",
92            &[
93                "matchResources",
94                "paramRef",
95                "policyName",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for MutatingAdmissionPolicyBindingSpec {
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            "MutatingAdmissionPolicyBindingSpec",
106            self.match_resources.as_ref().map_or(0, |_| 1) +
107            self.param_ref.as_ref().map_or(0, |_| 1) +
108            self.policy_name.as_ref().map_or(0, |_| 1),
109        )?;
110        if let Some(value) = &self.match_resources {
111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "matchResources", value)?;
112        }
113        if let Some(value) = &self.param_ref {
114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "paramRef", value)?;
115        }
116        if let Some(value) = &self.policy_name {
117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "policyName", value)?;
118        }
119        crate::serde::ser::SerializeStruct::end(state)
120    }
121}
122
123#[cfg(feature = "schemars")]
124impl crate::schemars::JsonSchema for MutatingAdmissionPolicyBindingSpec {
125    fn schema_name() -> std::borrow::Cow<'static, str> {
126        "io.k8s.api.admissionregistration.v1beta1.MutatingAdmissionPolicyBindingSpec".into()
127    }
128
129    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
130        crate::schemars::json_schema!({
131            "description": "MutatingAdmissionPolicyBindingSpec is the specification of the MutatingAdmissionPolicyBinding.",
132            "type": "object",
133            "properties": {
134                "matchResources": ({
135                    let mut schema_obj = __gen.subschema_for::<crate::api::admissionregistration::v1beta1::MatchResources>();
136                    schema_obj.ensure_object().insert("description".into(), "matchResources limits what resources match this binding and may be mutated by it. Note that if matchResources matches a resource, the resource must also match a policy's matchConstraints and matchConditions before the resource may be mutated. When matchResources is unset, it does not constrain resource matching, and only the policy's matchConstraints and matchConditions must match for the resource to be mutated. Additionally, matchResources.resourceRules are optional and do not constraint matching when unset. Note that this is differs from MutatingAdmissionPolicy matchConstraints, where resourceRules are required. The CREATE, UPDATE and CONNECT operations are allowed.  The DELETE operation may not be matched. '*' matches CREATE, UPDATE and CONNECT.".into());
137                    schema_obj
138                }),
139                "paramRef": ({
140                    let mut schema_obj = __gen.subschema_for::<crate::api::admissionregistration::v1beta1::ParamRef>();
141                    schema_obj.ensure_object().insert("description".into(), "paramRef specifies the parameter resource used to configure the admission control policy. It should point to a resource of the type specified in spec.ParamKind of the bound MutatingAdmissionPolicy. If the policy specifies a ParamKind and the resource referred to by ParamRef does not exist, this binding is considered mis-configured and the FailurePolicy of the MutatingAdmissionPolicy applied. If the policy does not specify a ParamKind then this field is ignored, and the rules are evaluated without a param.".into());
142                    schema_obj
143                }),
144                "policyName": {
145                    "description": "policyName references a MutatingAdmissionPolicy name which the MutatingAdmissionPolicyBinding binds to. If the referenced resource does not exist, this binding is considered invalid and will be ignored Required.",
146                    "type": "string",
147                },
148            },
149        })
150    }
151}