k8s_openapi/v1_30/api/core/v1/
csi_volume_source.rs

1// Generated from definition io.k8s.api.core.v1.CSIVolumeSource
2
3/// Represents a source location of a volume to mount, managed by an external CSI driver
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct CSIVolumeSource {
6    /// driver is the name of the CSI driver that handles this volume. Consult with your admin for the correct name as registered in the cluster.
7    pub driver: String,
8
9    /// fsType to mount. Ex. "ext4", "xfs", "ntfs". If not provided, the empty value is passed to the associated CSI driver which will determine the default filesystem to apply.
10    pub fs_type: Option<String>,
11
12    /// nodePublishSecretRef is a reference to the secret object containing sensitive information to pass to the CSI driver to complete the CSI NodePublishVolume and NodeUnpublishVolume calls. This field is optional, and  may be empty if no secret is required. If the secret object contains more than one secret, all secret references are passed.
13    pub node_publish_secret_ref: Option<crate::api::core::v1::LocalObjectReference>,
14
15    /// readOnly specifies a read-only configuration for the volume. Defaults to false (read/write).
16    pub read_only: Option<bool>,
17
18    /// volumeAttributes stores driver-specific properties that are passed to the CSI driver. Consult your driver's documentation for supported values.
19    pub volume_attributes: Option<std::collections::BTreeMap<String, String>>,
20}
21
22impl crate::DeepMerge for CSIVolumeSource {
23    fn merge_from(&mut self, other: Self) {
24        crate::DeepMerge::merge_from(&mut self.driver, other.driver);
25        crate::DeepMerge::merge_from(&mut self.fs_type, other.fs_type);
26        crate::DeepMerge::merge_from(&mut self.node_publish_secret_ref, other.node_publish_secret_ref);
27        crate::DeepMerge::merge_from(&mut self.read_only, other.read_only);
28        crate::merge_strategies::map::granular(&mut self.volume_attributes, other.volume_attributes, |current_item, other_item| {
29            crate::DeepMerge::merge_from(current_item, other_item);
30        });
31    }
32}
33
34impl<'de> crate::serde::Deserialize<'de> for CSIVolumeSource {
35    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36        #[allow(non_camel_case_types)]
37        enum Field {
38            Key_driver,
39            Key_fs_type,
40            Key_node_publish_secret_ref,
41            Key_read_only,
42            Key_volume_attributes,
43            Other,
44        }
45
46        impl<'de> crate::serde::Deserialize<'de> for Field {
47            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
48                struct Visitor;
49
50                impl crate::serde::de::Visitor<'_> for Visitor {
51                    type Value = Field;
52
53                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54                        f.write_str("field identifier")
55                    }
56
57                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
58                        Ok(match v {
59                            "driver" => Field::Key_driver,
60                            "fsType" => Field::Key_fs_type,
61                            "nodePublishSecretRef" => Field::Key_node_publish_secret_ref,
62                            "readOnly" => Field::Key_read_only,
63                            "volumeAttributes" => Field::Key_volume_attributes,
64                            _ => Field::Other,
65                        })
66                    }
67                }
68
69                deserializer.deserialize_identifier(Visitor)
70            }
71        }
72
73        struct Visitor;
74
75        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
76            type Value = CSIVolumeSource;
77
78            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79                f.write_str("CSIVolumeSource")
80            }
81
82            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
83                let mut value_driver: Option<String> = None;
84                let mut value_fs_type: Option<String> = None;
85                let mut value_node_publish_secret_ref: Option<crate::api::core::v1::LocalObjectReference> = None;
86                let mut value_read_only: Option<bool> = None;
87                let mut value_volume_attributes: Option<std::collections::BTreeMap<String, String>> = None;
88
89                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
90                    match key {
91                        Field::Key_driver => value_driver = crate::serde::de::MapAccess::next_value(&mut map)?,
92                        Field::Key_fs_type => value_fs_type = crate::serde::de::MapAccess::next_value(&mut map)?,
93                        Field::Key_node_publish_secret_ref => value_node_publish_secret_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
94                        Field::Key_read_only => value_read_only = crate::serde::de::MapAccess::next_value(&mut map)?,
95                        Field::Key_volume_attributes => value_volume_attributes = crate::serde::de::MapAccess::next_value(&mut map)?,
96                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
97                    }
98                }
99
100                Ok(CSIVolumeSource {
101                    driver: value_driver.unwrap_or_default(),
102                    fs_type: value_fs_type,
103                    node_publish_secret_ref: value_node_publish_secret_ref,
104                    read_only: value_read_only,
105                    volume_attributes: value_volume_attributes,
106                })
107            }
108        }
109
110        deserializer.deserialize_struct(
111            "CSIVolumeSource",
112            &[
113                "driver",
114                "fsType",
115                "nodePublishSecretRef",
116                "readOnly",
117                "volumeAttributes",
118            ],
119            Visitor,
120        )
121    }
122}
123
124impl crate::serde::Serialize for CSIVolumeSource {
125    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
126        let mut state = serializer.serialize_struct(
127            "CSIVolumeSource",
128            1 +
129            self.fs_type.as_ref().map_or(0, |_| 1) +
130            self.node_publish_secret_ref.as_ref().map_or(0, |_| 1) +
131            self.read_only.as_ref().map_or(0, |_| 1) +
132            self.volume_attributes.as_ref().map_or(0, |_| 1),
133        )?;
134        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "driver", &self.driver)?;
135        if let Some(value) = &self.fs_type {
136            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "fsType", value)?;
137        }
138        if let Some(value) = &self.node_publish_secret_ref {
139            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodePublishSecretRef", value)?;
140        }
141        if let Some(value) = &self.read_only {
142            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "readOnly", value)?;
143        }
144        if let Some(value) = &self.volume_attributes {
145            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "volumeAttributes", value)?;
146        }
147        crate::serde::ser::SerializeStruct::end(state)
148    }
149}
150
151#[cfg(feature = "schemars")]
152impl crate::schemars::JsonSchema for CSIVolumeSource {
153    fn schema_name() -> String {
154        "io.k8s.api.core.v1.CSIVolumeSource".to_owned()
155    }
156
157    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
158        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
159            metadata: Some(Box::new(crate::schemars::schema::Metadata {
160                description: Some("Represents a source location of a volume to mount, managed by an external CSI driver".to_owned()),
161                ..Default::default()
162            })),
163            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
164            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
165                properties: [
166                    (
167                        "driver".to_owned(),
168                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
169                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
170                                description: Some("driver is the name of the CSI driver that handles this volume. Consult with your admin for the correct name as registered in the cluster.".to_owned()),
171                                ..Default::default()
172                            })),
173                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
174                            ..Default::default()
175                        }),
176                    ),
177                    (
178                        "fsType".to_owned(),
179                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
180                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
181                                description: Some("fsType to mount. Ex. \"ext4\", \"xfs\", \"ntfs\". If not provided, the empty value is passed to the associated CSI driver which will determine the default filesystem to apply.".to_owned()),
182                                ..Default::default()
183                            })),
184                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
185                            ..Default::default()
186                        }),
187                    ),
188                    (
189                        "nodePublishSecretRef".to_owned(),
190                        {
191                            let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::LocalObjectReference>().into_object();
192                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
193                                description: Some("nodePublishSecretRef is a reference to the secret object containing sensitive information to pass to the CSI driver to complete the CSI NodePublishVolume and NodeUnpublishVolume calls. This field is optional, and  may be empty if no secret is required. If the secret object contains more than one secret, all secret references are passed.".to_owned()),
194                                ..Default::default()
195                            }));
196                            crate::schemars::schema::Schema::Object(schema_obj)
197                        },
198                    ),
199                    (
200                        "readOnly".to_owned(),
201                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
202                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
203                                description: Some("readOnly specifies a read-only configuration for the volume. Defaults to false (read/write).".to_owned()),
204                                ..Default::default()
205                            })),
206                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Boolean))),
207                            ..Default::default()
208                        }),
209                    ),
210                    (
211                        "volumeAttributes".to_owned(),
212                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
213                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
214                                description: Some("volumeAttributes stores driver-specific properties that are passed to the CSI driver. Consult your driver's documentation for supported values.".to_owned()),
215                                ..Default::default()
216                            })),
217                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
218                            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
219                                additional_properties: Some(Box::new(
220                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
221                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
222                                        ..Default::default()
223                                    })
224                                )),
225                                ..Default::default()
226                            })),
227                            ..Default::default()
228                        }),
229                    ),
230                ].into(),
231                required: [
232                    "driver".to_owned(),
233                ].into(),
234                ..Default::default()
235            })),
236            ..Default::default()
237        })
238    }
239}