k8s_openapi/v1_32/api/admissionregistration/v1/
param_ref.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ParamRef {
6 pub name: Option<String>,
12
13 pub namespace: Option<String>,
21
22 pub parameter_not_found_action: Option<String>,
28
29 pub selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
35}
36
37impl crate::DeepMerge for ParamRef {
38 fn merge_from(&mut self, other: Self) {
39 crate::DeepMerge::merge_from(&mut self.name, other.name);
40 crate::DeepMerge::merge_from(&mut self.namespace, other.namespace);
41 crate::DeepMerge::merge_from(&mut self.parameter_not_found_action, other.parameter_not_found_action);
42 crate::DeepMerge::merge_from(&mut self.selector, other.selector);
43 }
44}
45
46impl<'de> crate::serde::Deserialize<'de> for ParamRef {
47 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
48 #[allow(non_camel_case_types)]
49 enum Field {
50 Key_name,
51 Key_namespace,
52 Key_parameter_not_found_action,
53 Key_selector,
54 Other,
55 }
56
57 impl<'de> crate::serde::Deserialize<'de> for Field {
58 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
59 struct Visitor;
60
61 impl crate::serde::de::Visitor<'_> for Visitor {
62 type Value = Field;
63
64 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65 f.write_str("field identifier")
66 }
67
68 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
69 Ok(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 }
78
79 deserializer.deserialize_identifier(Visitor)
80 }
81 }
82
83 struct Visitor;
84
85 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
86 type Value = ParamRef;
87
88 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
89 f.write_str("ParamRef")
90 }
91
92 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
93 let mut value_name: Option<String> = None;
94 let mut value_namespace: Option<String> = None;
95 let mut value_parameter_not_found_action: Option<String> = None;
96 let mut value_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
97
98 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
99 match 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 }
107
108 Ok(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 }
116
117 deserializer.deserialize_struct(
118 "ParamRef",
119 &[
120 "name",
121 "namespace",
122 "parameterNotFoundAction",
123 "selector",
124 ],
125 Visitor,
126 )
127 }
128}
129
130impl crate::serde::Serialize for ParamRef {
131 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
132 let mut state = serializer.serialize_struct(
133 "ParamRef",
134 self.name.as_ref().map_or(0, |_| 1) +
135 self.namespace.as_ref().map_or(0, |_| 1) +
136 self.parameter_not_found_action.as_ref().map_or(0, |_| 1) +
137 self.selector.as_ref().map_or(0, |_| 1),
138 )?;
139 if let Some(value) = &self.name {
140 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", value)?;
141 }
142 if let Some(value) = &self.namespace {
143 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespace", value)?;
144 }
145 if let Some(value) = &self.parameter_not_found_action {
146 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "parameterNotFoundAction", value)?;
147 }
148 if let Some(value) = &self.selector {
149 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selector", value)?;
150 }
151 crate::serde::ser::SerializeStruct::end(state)
152 }
153}
154
155#[cfg(feature = "schemars")]
156impl crate::schemars::JsonSchema for ParamRef {
157 fn schema_name() -> String {
158 "io.k8s.api.admissionregistration.v1.ParamRef".to_owned()
159 }
160
161 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
162 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
163 metadata: Some(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.".to_owned()),
165 ..Default::default()
166 })),
167 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
168 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
169 properties: [
170 (
171 "name".to_owned(),
172 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
173 metadata: Some(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.".to_owned()),
175 ..Default::default()
176 })),
177 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
178 ..Default::default()
179 }),
180 ),
181 (
182 "namespace".to_owned(),
183 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
184 metadata: Some(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.".to_owned()),
186 ..Default::default()
187 })),
188 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
189 ..Default::default()
190 }),
191 ),
192 (
193 "parameterNotFoundAction".to_owned(),
194 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
195 metadata: Some(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".to_owned()),
197 ..Default::default()
198 })),
199 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
200 ..Default::default()
201 }),
202 ),
203 (
204 "selector".to_owned(),
205 {
206 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>().into_object();
207 schema_obj.metadata = Some(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.".to_owned()),
209 ..Default::default()
210 }));
211 crate::schemars::schema::Schema::Object(schema_obj)
212 },
213 ),
214 ].into(),
215 ..Default::default()
216 })),
217 ..Default::default()
218 })
219 }
220}