k8s_openapi/v1_33/api/storage/v1/
volume_attachment_spec.rs

1// Generated from definition io.k8s.api.storage.v1.VolumeAttachmentSpec
2
3/// VolumeAttachmentSpec is the specification of a VolumeAttachment request.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct VolumeAttachmentSpec {
6    /// attacher indicates the name of the volume driver that MUST handle this request. This is the name returned by GetPluginName().
7    pub attacher: std::string::String,
8
9    /// nodeName represents the node that the volume should be attached to.
10    pub node_name: std::string::String,
11
12    /// source represents the volume that should be attached.
13    pub source: crate::api::storage::v1::VolumeAttachmentSource,
14}
15
16impl crate::DeepMerge for VolumeAttachmentSpec {
17    fn merge_from(&mut self, other: Self) {
18        crate::DeepMerge::merge_from(&mut self.attacher, other.attacher);
19        crate::DeepMerge::merge_from(&mut self.node_name, other.node_name);
20        crate::DeepMerge::merge_from(&mut self.source, other.source);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for VolumeAttachmentSpec {
25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26        #[allow(non_camel_case_types)]
27        enum Field {
28            Key_attacher,
29            Key_node_name,
30            Key_source,
31            Other,
32        }
33
34        impl<'de> crate::serde::Deserialize<'de> for Field {
35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36                struct Visitor;
37
38                impl crate::serde::de::Visitor<'_> for Visitor {
39                    type Value = Field;
40
41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42                        f.write_str("field identifier")
43                    }
44
45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46                        Ok(match v {
47                            "attacher" => Field::Key_attacher,
48                            "nodeName" => Field::Key_node_name,
49                            "source" => Field::Key_source,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = VolumeAttachmentSpec;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("VolumeAttachmentSpec")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_attacher: Option<std::string::String> = None;
70                let mut value_node_name: Option<std::string::String> = None;
71                let mut value_source: Option<crate::api::storage::v1::VolumeAttachmentSource> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_attacher => value_attacher = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_node_name => value_node_name = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_source => value_source = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79                    }
80                }
81
82                Ok(VolumeAttachmentSpec {
83                    attacher: value_attacher.unwrap_or_default(),
84                    node_name: value_node_name.unwrap_or_default(),
85                    source: value_source.unwrap_or_default(),
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "VolumeAttachmentSpec",
92            &[
93                "attacher",
94                "nodeName",
95                "source",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for VolumeAttachmentSpec {
103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104        let mut state = serializer.serialize_struct(
105            "VolumeAttachmentSpec",
106            3,
107        )?;
108        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "attacher", &self.attacher)?;
109        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeName", &self.node_name)?;
110        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "source", &self.source)?;
111        crate::serde::ser::SerializeStruct::end(state)
112    }
113}
114
115#[cfg(feature = "schemars")]
116impl crate::schemars::JsonSchema for VolumeAttachmentSpec {
117    fn schema_name() -> std::string::String {
118        "io.k8s.api.storage.v1.VolumeAttachmentSpec".into()
119    }
120
121    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
122        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
123            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
124                description: Some("VolumeAttachmentSpec is the specification of a VolumeAttachment request.".into()),
125                ..Default::default()
126            })),
127            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
128            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
129                properties: [
130                    (
131                        "attacher".into(),
132                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
133                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
134                                description: Some("attacher indicates the name of the volume driver that MUST handle this request. This is the name returned by GetPluginName().".into()),
135                                ..Default::default()
136                            })),
137                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
138                            ..Default::default()
139                        }),
140                    ),
141                    (
142                        "nodeName".into(),
143                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
144                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
145                                description: Some("nodeName represents the node that the volume should be attached to.".into()),
146                                ..Default::default()
147                            })),
148                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
149                            ..Default::default()
150                        }),
151                    ),
152                    (
153                        "source".into(),
154                        {
155                            let mut schema_obj = __gen.subschema_for::<crate::api::storage::v1::VolumeAttachmentSource>().into_object();
156                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
157                                description: Some("source represents the volume that should be attached.".into()),
158                                ..Default::default()
159                            }));
160                            crate::schemars::schema::Schema::Object(schema_obj)
161                        },
162                    ),
163                ].into(),
164                required: [
165                    "attacher".into(),
166                    "nodeName".into(),
167                    "source".into(),
168                ].into(),
169                ..Default::default()
170            })),
171            ..Default::default()
172        })
173    }
174}