k8s_openapi/v1_35/api/core/v1/
persistent_volume_claim_spec.rs

1// Generated from definition io.k8s.api.core.v1.PersistentVolumeClaimSpec
2
3/// PersistentVolumeClaimSpec describes the common attributes of storage devices and allows a Source for provider-specific attributes
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PersistentVolumeClaimSpec {
6    /// accessModes contains the desired access modes the volume should have. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes-1
7    pub access_modes: Option<std::vec::Vec<std::string::String>>,
8
9    /// 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.
10    pub data_source: Option<crate::api::core::v1::TypedLocalObjectReference>,
11
12    /// 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
13    ///   allows any non-core object, as well as PersistentVolumeClaim objects.
14    /// * While dataSource ignores disallowed values (dropping them), dataSourceRef
15    ///   preserves all values, and generates an error if a disallowed value is
16    ///   specified.
17    /// * While dataSource only allows local objects, dataSourceRef allows objects
18    ///   in any namespaces.
19    /// (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.
20    pub data_source_ref: Option<crate::api::core::v1::TypedObjectReference>,
21
22    /// resources represents the minimum resources the volume should have. 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
23    pub resources: Option<crate::api::core::v1::VolumeResourceRequirements>,
24
25    /// selector is a label query over volumes to consider for binding.
26    pub selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
27
28    /// storageClassName is the name of the StorageClass required by the claim. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1
29    pub storage_class_name: Option<std::string::String>,
30
31    /// 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 or nil value indicates that no VolumeAttributesClass will be applied to the claim. If the claim enters an Infeasible error state, this field can be reset to its previous value (including nil) to cancel the modification. 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/
32    pub volume_attributes_class_name: Option<std::string::String>,
33
34    /// volumeMode defines what type of volume is required by the claim. Value of Filesystem is implied when not included in claim spec.
35    pub volume_mode: Option<std::string::String>,
36
37    /// volumeName is the binding reference to the PersistentVolume backing this claim.
38    pub volume_name: Option<std::string::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 core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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<std::vec::Vec<std::string::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<std::string::String> = None;
118                let mut value_volume_attributes_class_name: Option<std::string::String> = None;
119                let mut value_volume_mode: Option<std::string::String> = None;
120                let mut value_volume_name: Option<std::string::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() -> std::borrow::Cow<'static, str> {
217        "io.k8s.api.core.v1.PersistentVolumeClaimSpec".into()
218    }
219
220    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
221        crate::schemars::json_schema!({
222            "description": "PersistentVolumeClaimSpec describes the common attributes of storage devices and allows a Source for provider-specific attributes",
223            "type": "object",
224            "properties": {
225                "accessModes": {
226                    "description": "accessModes contains the desired access modes the volume should have. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes-1",
227                    "type": "array",
228                    "items": {
229                        "type": "string",
230                    },
231                },
232                "dataSource": ({
233                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::TypedLocalObjectReference>();
234                    schema_obj.ensure_object().insert("description".into(), "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.".into());
235                    schema_obj
236                }),
237                "dataSourceRef": ({
238                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::TypedObjectReference>();
239                    schema_obj.ensure_object().insert("description".into(), "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.".into());
240                    schema_obj
241                }),
242                "resources": ({
243                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::VolumeResourceRequirements>();
244                    schema_obj.ensure_object().insert("description".into(), "resources represents the minimum resources the volume should have. 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".into());
245                    schema_obj
246                }),
247                "selector": ({
248                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>();
249                    schema_obj.ensure_object().insert("description".into(), "selector is a label query over volumes to consider for binding.".into());
250                    schema_obj
251                }),
252                "storageClassName": {
253                    "description": "storageClassName is the name of the StorageClass required by the claim. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1",
254                    "type": "string",
255                },
256                "volumeAttributesClassName": {
257                    "description": "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 or nil value indicates that no VolumeAttributesClass will be applied to the claim. If the claim enters an Infeasible error state, this field can be reset to its previous value (including nil) to cancel the modification. 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/",
258                    "type": "string",
259                },
260                "volumeMode": {
261                    "description": "volumeMode defines what type of volume is required by the claim. Value of Filesystem is implied when not included in claim spec.",
262                    "type": "string",
263                },
264                "volumeName": {
265                    "description": "volumeName is the binding reference to the PersistentVolume backing this claim.",
266                    "type": "string",
267                },
268            },
269        })
270    }
271}