1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PersistentVolumeClaimSpec {
6 pub access_modes: Option<Vec<String>>,
8
9 pub data_source: Option<crate::api::core::v1::TypedLocalObjectReference>,
11
12 pub data_source_ref: Option<crate::api::core::v1::TypedObjectReference>,
21
22 pub resources: Option<crate::api::core::v1::VolumeResourceRequirements>,
24
25 pub selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
27
28 pub storage_class_name: Option<String>,
30
31 pub volume_attributes_class_name: Option<String>,
33
34 pub volume_mode: Option<String>,
36
37 pub volume_name: Option<String>,
39}
40
41impl crate::DeepMerge for PersistentVolumeClaimSpec {
42 fn merge_from(&mut self, other: Self) {
43 crate::merge_strategies::list::atomic(&mut self.access_modes, other.access_modes);
44 crate::DeepMerge::merge_from(&mut self.data_source, other.data_source);
45 crate::DeepMerge::merge_from(&mut self.data_source_ref, other.data_source_ref);
46 crate::DeepMerge::merge_from(&mut self.resources, other.resources);
47 crate::DeepMerge::merge_from(&mut self.selector, other.selector);
48 crate::DeepMerge::merge_from(&mut self.storage_class_name, other.storage_class_name);
49 crate::DeepMerge::merge_from(&mut self.volume_attributes_class_name, other.volume_attributes_class_name);
50 crate::DeepMerge::merge_from(&mut self.volume_mode, other.volume_mode);
51 crate::DeepMerge::merge_from(&mut self.volume_name, other.volume_name);
52 }
53}
54
55impl<'de> crate::serde::Deserialize<'de> for PersistentVolumeClaimSpec {
56 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
57 #[allow(non_camel_case_types)]
58 enum Field {
59 Key_access_modes,
60 Key_data_source,
61 Key_data_source_ref,
62 Key_resources,
63 Key_selector,
64 Key_storage_class_name,
65 Key_volume_attributes_class_name,
66 Key_volume_mode,
67 Key_volume_name,
68 Other,
69 }
70
71 impl<'de> crate::serde::Deserialize<'de> for Field {
72 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
73 struct Visitor;
74
75 impl crate::serde::de::Visitor<'_> for Visitor {
76 type Value = Field;
77
78 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79 f.write_str("field identifier")
80 }
81
82 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
83 Ok(match v {
84 "accessModes" => Field::Key_access_modes,
85 "dataSource" => Field::Key_data_source,
86 "dataSourceRef" => Field::Key_data_source_ref,
87 "resources" => Field::Key_resources,
88 "selector" => Field::Key_selector,
89 "storageClassName" => Field::Key_storage_class_name,
90 "volumeAttributesClassName" => Field::Key_volume_attributes_class_name,
91 "volumeMode" => Field::Key_volume_mode,
92 "volumeName" => Field::Key_volume_name,
93 _ => Field::Other,
94 })
95 }
96 }
97
98 deserializer.deserialize_identifier(Visitor)
99 }
100 }
101
102 struct Visitor;
103
104 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
105 type Value = PersistentVolumeClaimSpec;
106
107 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
108 f.write_str("PersistentVolumeClaimSpec")
109 }
110
111 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
112 let mut value_access_modes: Option<Vec<String>> = None;
113 let mut value_data_source: Option<crate::api::core::v1::TypedLocalObjectReference> = None;
114 let mut value_data_source_ref: Option<crate::api::core::v1::TypedObjectReference> = None;
115 let mut value_resources: Option<crate::api::core::v1::VolumeResourceRequirements> = None;
116 let mut value_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
117 let mut value_storage_class_name: Option<String> = None;
118 let mut value_volume_attributes_class_name: Option<String> = None;
119 let mut value_volume_mode: Option<String> = None;
120 let mut value_volume_name: Option<String> = None;
121
122 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
123 match key {
124 Field::Key_access_modes => value_access_modes = crate::serde::de::MapAccess::next_value(&mut map)?,
125 Field::Key_data_source => value_data_source = crate::serde::de::MapAccess::next_value(&mut map)?,
126 Field::Key_data_source_ref => value_data_source_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
127 Field::Key_resources => value_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
128 Field::Key_selector => value_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
129 Field::Key_storage_class_name => value_storage_class_name = crate::serde::de::MapAccess::next_value(&mut map)?,
130 Field::Key_volume_attributes_class_name => value_volume_attributes_class_name = crate::serde::de::MapAccess::next_value(&mut map)?,
131 Field::Key_volume_mode => value_volume_mode = crate::serde::de::MapAccess::next_value(&mut map)?,
132 Field::Key_volume_name => value_volume_name = crate::serde::de::MapAccess::next_value(&mut map)?,
133 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
134 }
135 }
136
137 Ok(PersistentVolumeClaimSpec {
138 access_modes: value_access_modes,
139 data_source: value_data_source,
140 data_source_ref: value_data_source_ref,
141 resources: value_resources,
142 selector: value_selector,
143 storage_class_name: value_storage_class_name,
144 volume_attributes_class_name: value_volume_attributes_class_name,
145 volume_mode: value_volume_mode,
146 volume_name: value_volume_name,
147 })
148 }
149 }
150
151 deserializer.deserialize_struct(
152 "PersistentVolumeClaimSpec",
153 &[
154 "accessModes",
155 "dataSource",
156 "dataSourceRef",
157 "resources",
158 "selector",
159 "storageClassName",
160 "volumeAttributesClassName",
161 "volumeMode",
162 "volumeName",
163 ],
164 Visitor,
165 )
166 }
167}
168
169impl crate::serde::Serialize for PersistentVolumeClaimSpec {
170 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
171 let mut state = serializer.serialize_struct(
172 "PersistentVolumeClaimSpec",
173 self.access_modes.as_ref().map_or(0, |_| 1) +
174 self.data_source.as_ref().map_or(0, |_| 1) +
175 self.data_source_ref.as_ref().map_or(0, |_| 1) +
176 self.resources.as_ref().map_or(0, |_| 1) +
177 self.selector.as_ref().map_or(0, |_| 1) +
178 self.storage_class_name.as_ref().map_or(0, |_| 1) +
179 self.volume_attributes_class_name.as_ref().map_or(0, |_| 1) +
180 self.volume_mode.as_ref().map_or(0, |_| 1) +
181 self.volume_name.as_ref().map_or(0, |_| 1),
182 )?;
183 if let Some(value) = &self.access_modes {
184 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "accessModes", value)?;
185 }
186 if let Some(value) = &self.data_source {
187 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "dataSource", value)?;
188 }
189 if let Some(value) = &self.data_source_ref {
190 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "dataSourceRef", value)?;
191 }
192 if let Some(value) = &self.resources {
193 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resources", value)?;
194 }
195 if let Some(value) = &self.selector {
196 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selector", value)?;
197 }
198 if let Some(value) = &self.storage_class_name {
199 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "storageClassName", value)?;
200 }
201 if let Some(value) = &self.volume_attributes_class_name {
202 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "volumeAttributesClassName", value)?;
203 }
204 if let Some(value) = &self.volume_mode {
205 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "volumeMode", value)?;
206 }
207 if let Some(value) = &self.volume_name {
208 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "volumeName", value)?;
209 }
210 crate::serde::ser::SerializeStruct::end(state)
211 }
212}
213
214#[cfg(feature = "schemars")]
215impl crate::schemars::JsonSchema for PersistentVolumeClaimSpec {
216 fn schema_name() -> String {
217 "io.k8s.api.core.v1.PersistentVolumeClaimSpec".to_owned()
218 }
219
220 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
221 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
222 metadata: Some(Box::new(crate::schemars::schema::Metadata {
223 description: Some("PersistentVolumeClaimSpec describes the common attributes of storage devices and allows a Source for provider-specific attributes".to_owned()),
224 ..Default::default()
225 })),
226 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
227 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
228 properties: [
229 (
230 "accessModes".to_owned(),
231 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
232 metadata: Some(Box::new(crate::schemars::schema::Metadata {
233 description: Some("accessModes contains the desired access modes the volume should have. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes-1".to_owned()),
234 ..Default::default()
235 })),
236 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
237 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
238 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
239 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
240 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
241 ..Default::default()
242 })
243 ))),
244 ..Default::default()
245 })),
246 ..Default::default()
247 }),
248 ),
249 (
250 "dataSource".to_owned(),
251 {
252 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::TypedLocalObjectReference>().into_object();
253 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
254 description: Some("dataSource field can be used to specify either: * An existing VolumeSnapshot object (snapshot.storage.k8s.io/VolumeSnapshot) * An existing PVC (PersistentVolumeClaim) If the provisioner or an external controller can support the specified data source, it will create a new volume based on the contents of the specified data source. When the AnyVolumeDataSource feature gate is enabled, dataSource contents will be copied to dataSourceRef, and dataSourceRef contents will be copied to dataSource when dataSourceRef.namespace is not specified. If the namespace is specified, then dataSourceRef will not be copied to dataSource.".to_owned()),
255 ..Default::default()
256 }));
257 crate::schemars::schema::Schema::Object(schema_obj)
258 },
259 ),
260 (
261 "dataSourceRef".to_owned(),
262 {
263 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::TypedObjectReference>().into_object();
264 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
265 description: Some("dataSourceRef specifies the object from which to populate the volume with data, if a non-empty volume is desired. This may be any object from a non-empty API group (non core object) or a PersistentVolumeClaim object. When this field is specified, volume binding will only succeed if the type of the specified object matches some installed volume populator or dynamic provisioner. This field will replace the functionality of the dataSource field and as such if both fields are non-empty, they must have the same value. For backwards compatibility, when namespace isn't specified in dataSourceRef, both fields (dataSource and dataSourceRef) will be set to the same value automatically if one of them is empty and the other is non-empty. When namespace is specified in dataSourceRef, dataSource isn't set to the same value and must be empty. There are three important differences between dataSource and dataSourceRef: * While dataSource only allows two specific types of objects, dataSourceRef\n allows any non-core object, as well as PersistentVolumeClaim objects.\n* While dataSource ignores disallowed values (dropping them), dataSourceRef\n preserves all values, and generates an error if a disallowed value is\n specified.\n* While dataSource only allows local objects, dataSourceRef allows objects\n in any namespaces.\n(Beta) Using this field requires the AnyVolumeDataSource feature gate to be enabled. (Alpha) Using the namespace field of dataSourceRef requires the CrossNamespaceVolumeDataSource feature gate to be enabled.".to_owned()),
266 ..Default::default()
267 }));
268 crate::schemars::schema::Schema::Object(schema_obj)
269 },
270 ),
271 (
272 "resources".to_owned(),
273 {
274 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::VolumeResourceRequirements>().into_object();
275 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
276 description: Some("resources represents the minimum resources the volume should have. If RecoverVolumeExpansionFailure feature is enabled users are allowed to specify resource requirements that are lower than previous value but must still be higher than capacity recorded in the status field of the claim. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#resources".to_owned()),
277 ..Default::default()
278 }));
279 crate::schemars::schema::Schema::Object(schema_obj)
280 },
281 ),
282 (
283 "selector".to_owned(),
284 {
285 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>().into_object();
286 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
287 description: Some("selector is a label query over volumes to consider for binding.".to_owned()),
288 ..Default::default()
289 }));
290 crate::schemars::schema::Schema::Object(schema_obj)
291 },
292 ),
293 (
294 "storageClassName".to_owned(),
295 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
296 metadata: Some(Box::new(crate::schemars::schema::Metadata {
297 description: Some("storageClassName is the name of the StorageClass required by the claim. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1".to_owned()),
298 ..Default::default()
299 })),
300 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
301 ..Default::default()
302 }),
303 ),
304 (
305 "volumeAttributesClassName".to_owned(),
306 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
307 metadata: Some(Box::new(crate::schemars::schema::Metadata {
308 description: Some("volumeAttributesClassName may be used to set the VolumeAttributesClass used by this claim. If specified, the CSI driver will create or update the volume with the attributes defined in the corresponding VolumeAttributesClass. This has a different purpose than storageClassName, it can be changed after the claim is created. An empty string value means that no VolumeAttributesClass will be applied to the claim but it's not allowed to reset this field to empty string once it is set. If unspecified and the PersistentVolumeClaim is unbound, the default VolumeAttributesClass will be set by the persistentvolume controller if it exists. If the resource referred to by volumeAttributesClass does not exist, this PersistentVolumeClaim will be set to a Pending state, as reflected by the modifyVolumeStatus field, until such as a resource exists. More info: https://kubernetes.io/docs/concepts/storage/volume-attributes-classes/ (Alpha) Using this field requires the VolumeAttributesClass feature gate to be enabled.".to_owned()),
309 ..Default::default()
310 })),
311 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
312 ..Default::default()
313 }),
314 ),
315 (
316 "volumeMode".to_owned(),
317 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
318 metadata: Some(Box::new(crate::schemars::schema::Metadata {
319 description: Some("volumeMode defines what type of volume is required by the claim. Value of Filesystem is implied when not included in claim spec.".to_owned()),
320 ..Default::default()
321 })),
322 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
323 ..Default::default()
324 }),
325 ),
326 (
327 "volumeName".to_owned(),
328 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
329 metadata: Some(Box::new(crate::schemars::schema::Metadata {
330 description: Some("volumeName is the binding reference to the PersistentVolume backing this claim.".to_owned()),
331 ..Default::default()
332 })),
333 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
334 ..Default::default()
335 }),
336 ),
337 ].into(),
338 ..Default::default()
339 })),
340 ..Default::default()
341 })
342 }
343}