k8s_openapi/v1_32/api/resource/v1beta1/
allocated_device_status.rs

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