k8s_openapi/v1_33/api/resource/v1beta1/
device_allocation_configuration.rs

1// Generated from definition io.k8s.api.resource.v1beta1.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::v1beta1::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::v1beta1::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::string::String {
126        "io.k8s.api.resource.v1beta1.DeviceAllocationConfiguration".into()
127    }
128
129    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
130        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
131            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
132                description: Some("DeviceAllocationConfiguration gets embedded in an AllocationResult.".into()),
133                ..Default::default()
134            })),
135            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
136            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
137                properties: [
138                    (
139                        "opaque".into(),
140                        {
141                            let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::OpaqueDeviceConfiguration>().into_object();
142                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
143                                description: Some("Opaque provides driver-specific configuration parameters.".into()),
144                                ..Default::default()
145                            }));
146                            crate::schemars::schema::Schema::Object(schema_obj)
147                        },
148                    ),
149                    (
150                        "requests".into(),
151                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
152                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
153                                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()),
154                                ..Default::default()
155                            })),
156                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
157                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
158                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(
159                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
160                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
161                                        ..Default::default()
162                                    })
163                                ))),
164                                ..Default::default()
165                            })),
166                            ..Default::default()
167                        }),
168                    ),
169                    (
170                        "source".into(),
171                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
172                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
173                                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()),
174                                ..Default::default()
175                            })),
176                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
177                            ..Default::default()
178                        }),
179                    ),
180                ].into(),
181                required: [
182                    "source".into(),
183                ].into(),
184                ..Default::default()
185            })),
186            ..Default::default()
187        })
188    }
189}