k8s_openapi/v1_33/api/resource/v1beta2/
allocated_device_status.rs

1// Generated from definition io.k8s.api.resource.v1beta2.AllocatedDeviceStatus
2
3/// AllocatedDeviceStatus contains the status of an allocated device, if the driver chooses to report it. This may include driver-specific information.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct AllocatedDeviceStatus {
6    /// Conditions contains the latest observation of the device's state. If the device has been configured according to the class and claim config references, the `Ready` condition should be True.
7    ///
8    /// Must not contain more than 8 entries.
9    pub conditions: Option<std::vec::Vec<crate::apimachinery::pkg::apis::meta::v1::Condition>>,
10
11    /// Data contains arbitrary driver-specific data.
12    ///
13    /// The length of the raw data must be smaller or equal to 10 Ki.
14    pub data: Option<crate::apimachinery::pkg::runtime::RawExtension>,
15
16    /// Device references one device instance via its name in the driver's resource pool. It must be a DNS label.
17    pub device: std::string::String,
18
19    /// Driver specifies the name of the DRA driver whose kubelet plugin should be invoked to process the allocation once the claim is needed on a node.
20    ///
21    /// Must be a DNS subdomain and should end with a DNS domain owned by the vendor of the driver.
22    pub driver: std::string::String,
23
24    /// NetworkData contains network-related information specific to the device.
25    pub network_data: Option<crate::api::resource::v1beta2::NetworkDeviceData>,
26
27    /// This name together with the driver name and the device name field identify which device was allocated (`\<driver name\>/\<pool name\>/\<device name\>`).
28    ///
29    /// Must not be longer than 253 characters and may contain one or more DNS sub-domains separated by slashes.
30    pub pool: std::string::String,
31}
32
33impl crate::DeepMerge for AllocatedDeviceStatus {
34    fn merge_from(&mut self, other: Self) {
35        crate::merge_strategies::list::map(
36            &mut self.conditions,
37            other.conditions,
38            &[|lhs, rhs| lhs.type_ == rhs.type_],
39            |current_item, other_item| {
40                crate::DeepMerge::merge_from(current_item, other_item);
41            },
42        );
43        crate::DeepMerge::merge_from(&mut self.data, other.data);
44        crate::DeepMerge::merge_from(&mut self.device, other.device);
45        crate::DeepMerge::merge_from(&mut self.driver, other.driver);
46        crate::DeepMerge::merge_from(&mut self.network_data, other.network_data);
47        crate::DeepMerge::merge_from(&mut self.pool, other.pool);
48    }
49}
50
51impl<'de> crate::serde::Deserialize<'de> for AllocatedDeviceStatus {
52    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
53        #[allow(non_camel_case_types)]
54        enum Field {
55            Key_conditions,
56            Key_data,
57            Key_device,
58            Key_driver,
59            Key_network_data,
60            Key_pool,
61            Other,
62        }
63
64        impl<'de> crate::serde::Deserialize<'de> for Field {
65            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
66                struct Visitor;
67
68                impl crate::serde::de::Visitor<'_> for Visitor {
69                    type Value = Field;
70
71                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
72                        f.write_str("field identifier")
73                    }
74
75                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
76                        Ok(match v {
77                            "conditions" => Field::Key_conditions,
78                            "data" => Field::Key_data,
79                            "device" => Field::Key_device,
80                            "driver" => Field::Key_driver,
81                            "networkData" => Field::Key_network_data,
82                            "pool" => Field::Key_pool,
83                            _ => Field::Other,
84                        })
85                    }
86                }
87
88                deserializer.deserialize_identifier(Visitor)
89            }
90        }
91
92        struct Visitor;
93
94        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
95            type Value = AllocatedDeviceStatus;
96
97            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
98                f.write_str("AllocatedDeviceStatus")
99            }
100
101            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
102                let mut value_conditions: Option<std::vec::Vec<crate::apimachinery::pkg::apis::meta::v1::Condition>> = None;
103                let mut value_data: Option<crate::apimachinery::pkg::runtime::RawExtension> = None;
104                let mut value_device: Option<std::string::String> = None;
105                let mut value_driver: Option<std::string::String> = None;
106                let mut value_network_data: Option<crate::api::resource::v1beta2::NetworkDeviceData> = None;
107                let mut value_pool: Option<std::string::String> = None;
108
109                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
110                    match key {
111                        Field::Key_conditions => value_conditions = crate::serde::de::MapAccess::next_value(&mut map)?,
112                        Field::Key_data => value_data = crate::serde::de::MapAccess::next_value(&mut map)?,
113                        Field::Key_device => value_device = crate::serde::de::MapAccess::next_value(&mut map)?,
114                        Field::Key_driver => value_driver = crate::serde::de::MapAccess::next_value(&mut map)?,
115                        Field::Key_network_data => value_network_data = crate::serde::de::MapAccess::next_value(&mut map)?,
116                        Field::Key_pool => value_pool = crate::serde::de::MapAccess::next_value(&mut map)?,
117                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
118                    }
119                }
120
121                Ok(AllocatedDeviceStatus {
122                    conditions: value_conditions,
123                    data: value_data,
124                    device: value_device.unwrap_or_default(),
125                    driver: value_driver.unwrap_or_default(),
126                    network_data: value_network_data,
127                    pool: value_pool.unwrap_or_default(),
128                })
129            }
130        }
131
132        deserializer.deserialize_struct(
133            "AllocatedDeviceStatus",
134            &[
135                "conditions",
136                "data",
137                "device",
138                "driver",
139                "networkData",
140                "pool",
141            ],
142            Visitor,
143        )
144    }
145}
146
147impl crate::serde::Serialize for AllocatedDeviceStatus {
148    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
149        let mut state = serializer.serialize_struct(
150            "AllocatedDeviceStatus",
151            3 +
152            self.conditions.as_ref().map_or(0, |_| 1) +
153            self.data.as_ref().map_or(0, |_| 1) +
154            self.network_data.as_ref().map_or(0, |_| 1),
155        )?;
156        if let Some(value) = &self.conditions {
157            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "conditions", value)?;
158        }
159        if let Some(value) = &self.data {
160            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "data", value)?;
161        }
162        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "device", &self.device)?;
163        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "driver", &self.driver)?;
164        if let Some(value) = &self.network_data {
165            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "networkData", value)?;
166        }
167        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "pool", &self.pool)?;
168        crate::serde::ser::SerializeStruct::end(state)
169    }
170}
171
172#[cfg(feature = "schemars")]
173impl crate::schemars::JsonSchema for AllocatedDeviceStatus {
174    fn schema_name() -> std::string::String {
175        "io.k8s.api.resource.v1beta2.AllocatedDeviceStatus".into()
176    }
177
178    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
179        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
180            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
181                description: Some("AllocatedDeviceStatus contains the status of an allocated device, if the driver chooses to report it. This may include driver-specific information.".into()),
182                ..Default::default()
183            })),
184            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
185            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
186                properties: [
187                    (
188                        "conditions".into(),
189                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
190                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
191                                description: Some("Conditions contains the latest observation of the device's state. If the device has been configured according to the class and claim config references, the `Ready` condition should be True.\n\nMust not contain more than 8 entries.".into()),
192                                ..Default::default()
193                            })),
194                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
195                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
196                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::Condition>()))),
197                                ..Default::default()
198                            })),
199                            ..Default::default()
200                        }),
201                    ),
202                    (
203                        "data".into(),
204                        {
205                            let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::runtime::RawExtension>().into_object();
206                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
207                                description: Some("Data contains arbitrary driver-specific data.\n\nThe length of the raw data must be smaller or equal to 10 Ki.".into()),
208                                ..Default::default()
209                            }));
210                            crate::schemars::schema::Schema::Object(schema_obj)
211                        },
212                    ),
213                    (
214                        "device".into(),
215                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
216                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
217                                description: Some("Device references one device instance via its name in the driver's resource pool. It must be a DNS label.".into()),
218                                ..Default::default()
219                            })),
220                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
221                            ..Default::default()
222                        }),
223                    ),
224                    (
225                        "driver".into(),
226                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
227                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
228                                description: Some("Driver specifies the name of the DRA driver whose kubelet plugin should be invoked to process the allocation once the claim is needed on a node.\n\nMust be a DNS subdomain and should end with a DNS domain owned by the vendor of the driver.".into()),
229                                ..Default::default()
230                            })),
231                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
232                            ..Default::default()
233                        }),
234                    ),
235                    (
236                        "networkData".into(),
237                        {
238                            let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta2::NetworkDeviceData>().into_object();
239                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
240                                description: Some("NetworkData contains network-related information specific to the device.".into()),
241                                ..Default::default()
242                            }));
243                            crate::schemars::schema::Schema::Object(schema_obj)
244                        },
245                    ),
246                    (
247                        "pool".into(),
248                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
249                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
250                                description: Some("This name together with the driver name and the device name field identify which device was allocated (`<driver name>/<pool name>/<device name>`).\n\nMust not be longer than 253 characters and may contain one or more DNS sub-domains separated by slashes.".into()),
251                                ..Default::default()
252                            })),
253                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
254                            ..Default::default()
255                        }),
256                    ),
257                ].into(),
258                required: [
259                    "device".into(),
260                    "driver".into(),
261                    "pool".into(),
262                ].into(),
263                ..Default::default()
264            })),
265            ..Default::default()
266        })
267    }
268}