1// Generated from definition io.k8s.api.admissionregistration.v1.ParamRef
23/// ParamRef describes how to locate the params to be used as input to expressions of rules applied by a policy binding.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ParamRef {
6/// name is the name of the resource being referenced.
7 ///
8 /// One of `name` or `selector` must be set, but `name` and `selector` are mutually exclusive properties. If one is set, the other must be unset.
9 ///
10 /// A single parameter used for all admission requests can be configured by setting the `name` field, leaving `selector` blank, and setting namespace if `paramKind` is namespace-scoped.
11pub name: Option<std::string::String>,
1213/// namespace is the namespace of the referenced resource. Allows limiting the search for params to a specific namespace. Applies to both `name` and `selector` fields.
14 ///
15 /// A per-namespace parameter may be used by specifying a namespace-scoped `paramKind` in the policy and leaving this field empty.
16 ///
17 /// - If `paramKind` is cluster-scoped, this field MUST be unset. Setting this field results in a configuration error.
18 ///
19 /// - If `paramKind` is namespace-scoped, the namespace of the object being evaluated for admission will be used when this field is left unset. Take care that if this is left empty the binding must not match any cluster-scoped resources, which will result in an error.
20pub namespace: Option<std::string::String>,
2122/// `parameterNotFoundAction` controls the behavior of the binding when the resource exists, and name or selector is valid, but there are no parameters matched by the binding. If the value is set to `Allow`, then no matched parameters will be treated as successful validation by the binding. If set to `Deny`, then no matched parameters will be subject to the `failurePolicy` of the policy.
23 ///
24 /// Allowed values are `Allow` or `Deny`
25 ///
26 /// Required
27pub parameter_not_found_action: Option<std::string::String>,
2829/// selector can be used to match multiple param objects based on their labels. Supply selector: {} to match all resources of the ParamKind.
30 ///
31 /// If multiple params are found, they are all evaluated with the policy expressions and the results are ANDed together.
32 ///
33 /// One of `name` or `selector` must be set, but `name` and `selector` are mutually exclusive properties. If one is set, the other must be unset.
34pub selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
35}
3637impl crate::DeepMerge for ParamRef {
38fn merge_from(&mut self, other: Self) {
39crate::DeepMerge::merge_from(&mut self.name, other.name);
40crate::DeepMerge::merge_from(&mut self.namespace, other.namespace);
41crate::DeepMerge::merge_from(&mut self.parameter_not_found_action, other.parameter_not_found_action);
42crate::DeepMerge::merge_from(&mut self.selector, other.selector);
43 }
44}
4546impl<'de> crate::serde::Deserialize<'de> for ParamRef {
47fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
48#[allow(non_camel_case_types)]
49enum Field {
50 Key_name,
51 Key_namespace,
52 Key_parameter_not_found_action,
53 Key_selector,
54 Other,
55 }
5657impl<'de> crate::serde::Deserialize<'de> for Field {
58fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
59struct Visitor;
6061impl crate::serde::de::Visitor<'_> for Visitor {
62type Value = Field;
6364fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65 f.write_str("field identifier")
66 }
6768fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
69Ok(match v {
70"name" => Field::Key_name,
71"namespace" => Field::Key_namespace,
72"parameterNotFoundAction" => Field::Key_parameter_not_found_action,
73"selector" => Field::Key_selector,
74_ => Field::Other,
75 })
76 }
77 }
7879 deserializer.deserialize_identifier(Visitor)
80 }
81 }
8283struct Visitor;
8485impl<'de> crate::serde::de::Visitor<'de> for Visitor {
86type Value = ParamRef;
8788fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
89 f.write_str("ParamRef")
90 }
9192fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
93let mut value_name: Option<std::string::String> = None;
94let mut value_namespace: Option<std::string::String> = None;
95let mut value_parameter_not_found_action: Option<std::string::String> = None;
96let mut value_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
9798while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
99match key {
100 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
101 Field::Key_namespace => value_namespace = crate::serde::de::MapAccess::next_value(&mut map)?,
102 Field::Key_parameter_not_found_action => value_parameter_not_found_action = crate::serde::de::MapAccess::next_value(&mut map)?,
103 Field::Key_selector => value_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
104 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
105 }
106 }
107108Ok(ParamRef {
109 name: value_name,
110 namespace: value_namespace,
111 parameter_not_found_action: value_parameter_not_found_action,
112 selector: value_selector,
113 })
114 }
115 }
116117 deserializer.deserialize_struct(
118"ParamRef",
119&[
120"name",
121"namespace",
122"parameterNotFoundAction",
123"selector",
124 ],
125 Visitor,
126 )
127 }
128}
129130impl crate::serde::Serialize for ParamRef {
131fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
132let mut state = serializer.serialize_struct(
133"ParamRef",
134self.name.as_ref().map_or(0, |_| 1) +
135self.namespace.as_ref().map_or(0, |_| 1) +
136self.parameter_not_found_action.as_ref().map_or(0, |_| 1) +
137self.selector.as_ref().map_or(0, |_| 1),
138 )?;
139if let Some(value) = &self.name {
140crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", value)?;
141 }
142if let Some(value) = &self.namespace {
143crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespace", value)?;
144 }
145if let Some(value) = &self.parameter_not_found_action {
146crate::serde::ser::SerializeStruct::serialize_field(&mut state, "parameterNotFoundAction", value)?;
147 }
148if let Some(value) = &self.selector {
149crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selector", value)?;
150 }
151crate::serde::ser::SerializeStruct::end(state)
152 }
153}
154155#[cfg(feature = "schemars")]
156impl crate::schemars::JsonSchema for ParamRef {
157fn schema_name() -> std::string::String {
158"io.k8s.api.admissionregistration.v1.ParamRef".into()
159 }
160161fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
162crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
163 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
164 description: Some("ParamRef describes how to locate the params to be used as input to expressions of rules applied by a policy binding.".into()),
165 ..Default::default()
166 })),
167 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
168 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
169 properties: [
170 (
171"name".into(),
172crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
173 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
174 description: Some("name is the name of the resource being referenced.\n\nOne of `name` or `selector` must be set, but `name` and `selector` are mutually exclusive properties. If one is set, the other must be unset.\n\nA single parameter used for all admission requests can be configured by setting the `name` field, leaving `selector` blank, and setting namespace if `paramKind` is namespace-scoped.".into()),
175 ..Default::default()
176 })),
177 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
178 ..Default::default()
179 }),
180 ),
181 (
182"namespace".into(),
183crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
184 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
185 description: Some("namespace is the namespace of the referenced resource. Allows limiting the search for params to a specific namespace. Applies to both `name` and `selector` fields.\n\nA per-namespace parameter may be used by specifying a namespace-scoped `paramKind` in the policy and leaving this field empty.\n\n- If `paramKind` is cluster-scoped, this field MUST be unset. Setting this field results in a configuration error.\n\n- If `paramKind` is namespace-scoped, the namespace of the object being evaluated for admission will be used when this field is left unset. Take care that if this is left empty the binding must not match any cluster-scoped resources, which will result in an error.".into()),
186 ..Default::default()
187 })),
188 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
189 ..Default::default()
190 }),
191 ),
192 (
193"parameterNotFoundAction".into(),
194crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
195 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
196 description: Some("`parameterNotFoundAction` controls the behavior of the binding when the resource exists, and name or selector is valid, but there are no parameters matched by the binding. If the value is set to `Allow`, then no matched parameters will be treated as successful validation by the binding. If set to `Deny`, then no matched parameters will be subject to the `failurePolicy` of the policy.\n\nAllowed values are `Allow` or `Deny`\n\nRequired".into()),
197 ..Default::default()
198 })),
199 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
200 ..Default::default()
201 }),
202 ),
203 (
204"selector".into(),
205 {
206let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>().into_object();
207 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
208 description: Some("selector can be used to match multiple param objects based on their labels. Supply selector: {} to match all resources of the ParamKind.\n\nIf multiple params are found, they are all evaluated with the policy expressions and the results are ANDed together.\n\nOne of `name` or `selector` must be set, but `name` and `selector` are mutually exclusive properties. If one is set, the other must be unset.".into()),
209 ..Default::default()
210 }));
211crate::schemars::schema::Schema::Object(schema_obj)
212 },
213 ),
214 ].into(),
215 ..Default::default()
216 })),
217 ..Default::default()
218 })
219 }
220}