Skip to main content

k8s_openapi/v1_36/api/resource/v1beta2/
device_allocation_configuration.rs

1// Generated from definition io.k8s.api.resource.v1beta2.DeviceAllocationConfiguration
2
3/// DeviceAllocationConfiguration gets embedded in an AllocationResult.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceAllocationConfiguration {
6    /// Opaque provides driver-specific configuration parameters.
7    pub opaque: Option<crate::api::resource::v1beta2::OpaqueDeviceConfiguration>,
8
9    /// Requests lists the names of requests where the configuration applies. If empty, its applies to all requests.
10    ///
11    /// References to subrequests must include the name of the main request and may include the subrequest using the format \<main request\>\[/\<subrequest\>\]. If just the main request is given, the configuration applies to all subrequests.
12    pub requests: Option<std::vec::Vec<std::string::String>>,
13
14    /// Source records whether the configuration comes from a class and thus is not something that a normal user would have been able to set or from a claim.
15    pub source: std::string::String,
16}
17
18impl crate::DeepMerge for DeviceAllocationConfiguration {
19    fn merge_from(&mut self, other: Self) {
20        crate::DeepMerge::merge_from(&mut self.opaque, other.opaque);
21        crate::merge_strategies::list::atomic(&mut self.requests, other.requests);
22        crate::DeepMerge::merge_from(&mut self.source, other.source);
23    }
24}
25
26impl<'de> crate::serde::Deserialize<'de> for DeviceAllocationConfiguration {
27    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
28        #[allow(non_camel_case_types)]
29        enum Field {
30            Key_opaque,
31            Key_requests,
32            Key_source,
33            Other,
34        }
35
36        impl<'de> crate::serde::Deserialize<'de> for Field {
37            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38                struct Visitor;
39
40                impl crate::serde::de::Visitor<'_> for Visitor {
41                    type Value = Field;
42
43                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44                        f.write_str("field identifier")
45                    }
46
47                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
48                        Ok(match v {
49                            "opaque" => Field::Key_opaque,
50                            "requests" => Field::Key_requests,
51                            "source" => Field::Key_source,
52                            _ => Field::Other,
53                        })
54                    }
55                }
56
57                deserializer.deserialize_identifier(Visitor)
58            }
59        }
60
61        struct Visitor;
62
63        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
64            type Value = DeviceAllocationConfiguration;
65
66            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
67                f.write_str("DeviceAllocationConfiguration")
68            }
69
70            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
71                let mut value_opaque: Option<crate::api::resource::v1beta2::OpaqueDeviceConfiguration> = None;
72                let mut value_requests: Option<std::vec::Vec<std::string::String>> = None;
73                let mut value_source: Option<std::string::String> = None;
74
75                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
76                    match key {
77                        Field::Key_opaque => value_opaque = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Key_requests => value_requests = crate::serde::de::MapAccess::next_value(&mut map)?,
79                        Field::Key_source => value_source = crate::serde::de::MapAccess::next_value(&mut map)?,
80                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
81                    }
82                }
83
84                Ok(DeviceAllocationConfiguration {
85                    opaque: value_opaque,
86                    requests: value_requests,
87                    source: value_source.unwrap_or_default(),
88                })
89            }
90        }
91
92        deserializer.deserialize_struct(
93            "DeviceAllocationConfiguration",
94            &[
95                "opaque",
96                "requests",
97                "source",
98            ],
99            Visitor,
100        )
101    }
102}
103
104impl crate::serde::Serialize for DeviceAllocationConfiguration {
105    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
106        let mut state = serializer.serialize_struct(
107            "DeviceAllocationConfiguration",
108            1 +
109            self.opaque.as_ref().map_or(0, |_| 1) +
110            self.requests.as_ref().map_or(0, |_| 1),
111        )?;
112        if let Some(value) = &self.opaque {
113            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "opaque", value)?;
114        }
115        if let Some(value) = &self.requests {
116            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requests", value)?;
117        }
118        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "source", &self.source)?;
119        crate::serde::ser::SerializeStruct::end(state)
120    }
121}
122
123#[cfg(feature = "schemars")]
124impl crate::schemars::JsonSchema for DeviceAllocationConfiguration {
125    fn schema_name() -> std::borrow::Cow<'static, str> {
126        "io.k8s.api.resource.v1beta2.DeviceAllocationConfiguration".into()
127    }
128
129    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
130        crate::schemars::json_schema!({
131            "description": "DeviceAllocationConfiguration gets embedded in an AllocationResult.",
132            "type": "object",
133            "properties": {
134                "opaque": ({
135                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta2::OpaqueDeviceConfiguration>();
136                    schema_obj.ensure_object().insert("description".into(), "Opaque provides driver-specific configuration parameters.".into());
137                    schema_obj
138                }),
139                "requests": {
140                    "description": "Requests lists the names of requests where the configuration applies. If empty, its applies to all requests.\n\nReferences to subrequests must include the name of the main request and may include the subrequest using the format <main request>[/<subrequest>]. If just the main request is given, the configuration applies to all subrequests.",
141                    "type": "array",
142                    "items": {
143                        "type": "string",
144                    },
145                },
146                "source": {
147                    "description": "Source records whether the configuration comes from a class and thus is not something that a normal user would have been able to set or from a claim.",
148                    "type": "string",
149                },
150            },
151            "required": [
152                "source",
153            ],
154        })
155    }
156}
157
158#[cfg(feature = "schemars08")]
159impl crate::schemars08::JsonSchema for DeviceAllocationConfiguration {
160    fn schema_name() -> std::string::String {
161        "io.k8s.api.resource.v1beta2.DeviceAllocationConfiguration".into()
162    }
163
164    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
165        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
166            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
167                description: Some("DeviceAllocationConfiguration gets embedded in an AllocationResult.".into()),
168                ..Default::default()
169            })),
170            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
171            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
172                properties: [
173                    (
174                        "opaque".into(),
175                        {
176                            let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta2::OpaqueDeviceConfiguration>().into_object();
177                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
178                                description: Some("Opaque provides driver-specific configuration parameters.".into()),
179                                ..Default::default()
180                            }));
181                            crate::schemars08::schema::Schema::Object(schema_obj)
182                        },
183                    ),
184                    (
185                        "requests".into(),
186                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
187                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
188                                description: Some("Requests lists the names of requests where the configuration applies. If empty, its applies to all requests.\n\nReferences to subrequests must include the name of the main request and may include the subrequest using the format <main request>[/<subrequest>]. If just the main request is given, the configuration applies to all subrequests.".into()),
189                                ..Default::default()
190                            })),
191                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
192                            array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
193                                items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
194                                    crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
195                                        instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
196                                        ..Default::default()
197                                    })
198                                ))),
199                                ..Default::default()
200                            })),
201                            ..Default::default()
202                        }),
203                    ),
204                    (
205                        "source".into(),
206                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
207                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
208                                description: Some("Source records whether the configuration comes from a class and thus is not something that a normal user would have been able to set or from a claim.".into()),
209                                ..Default::default()
210                            })),
211                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
212                            ..Default::default()
213                        }),
214                    ),
215                ].into(),
216                required: [
217                    "source".into(),
218                ].into(),
219                ..Default::default()
220            })),
221            ..Default::default()
222        })
223    }
224}