Skip to main content

k8s_openapi/v1_36/api/resource/v1beta1/
allocation_result.rs

1// Generated from definition io.k8s.api.resource.v1beta1.AllocationResult
2
3/// AllocationResult contains attributes of an allocated resource.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct AllocationResult {
6    /// AllocationTimestamp stores the time when the resources were allocated. This field is not guaranteed to be set, in which case that time is unknown.
7    ///
8    /// This is a beta field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gate.
9    pub allocation_timestamp: Option<crate::apimachinery::pkg::apis::meta::v1::Time>,
10
11    /// Devices is the result of allocating devices.
12    pub devices: Option<crate::api::resource::v1beta1::DeviceAllocationResult>,
13
14    /// NodeSelector defines where the allocated resources are available. If unset, they are available everywhere.
15    pub node_selector: Option<crate::api::core::v1::NodeSelector>,
16}
17
18impl crate::DeepMerge for AllocationResult {
19    fn merge_from(&mut self, other: Self) {
20        crate::DeepMerge::merge_from(&mut self.allocation_timestamp, other.allocation_timestamp);
21        crate::DeepMerge::merge_from(&mut self.devices, other.devices);
22        crate::DeepMerge::merge_from(&mut self.node_selector, other.node_selector);
23    }
24}
25
26impl<'de> crate::serde::Deserialize<'de> for AllocationResult {
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_allocation_timestamp,
31            Key_devices,
32            Key_node_selector,
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                            "allocationTimestamp" => Field::Key_allocation_timestamp,
50                            "devices" => Field::Key_devices,
51                            "nodeSelector" => Field::Key_node_selector,
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 = AllocationResult;
65
66            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
67                f.write_str("AllocationResult")
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_allocation_timestamp: Option<crate::apimachinery::pkg::apis::meta::v1::Time> = None;
72                let mut value_devices: Option<crate::api::resource::v1beta1::DeviceAllocationResult> = None;
73                let mut value_node_selector: Option<crate::api::core::v1::NodeSelector> = None;
74
75                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
76                    match key {
77                        Field::Key_allocation_timestamp => value_allocation_timestamp = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Key_devices => value_devices = crate::serde::de::MapAccess::next_value(&mut map)?,
79                        Field::Key_node_selector => value_node_selector = 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(AllocationResult {
85                    allocation_timestamp: value_allocation_timestamp,
86                    devices: value_devices,
87                    node_selector: value_node_selector,
88                })
89            }
90        }
91
92        deserializer.deserialize_struct(
93            "AllocationResult",
94            &[
95                "allocationTimestamp",
96                "devices",
97                "nodeSelector",
98            ],
99            Visitor,
100        )
101    }
102}
103
104impl crate::serde::Serialize for AllocationResult {
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            "AllocationResult",
108            self.allocation_timestamp.as_ref().map_or(0, |_| 1) +
109            self.devices.as_ref().map_or(0, |_| 1) +
110            self.node_selector.as_ref().map_or(0, |_| 1),
111        )?;
112        if let Some(value) = &self.allocation_timestamp {
113            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationTimestamp", value)?;
114        }
115        if let Some(value) = &self.devices {
116            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "devices", value)?;
117        }
118        if let Some(value) = &self.node_selector {
119            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeSelector", value)?;
120        }
121        crate::serde::ser::SerializeStruct::end(state)
122    }
123}
124
125#[cfg(feature = "schemars")]
126impl crate::schemars::JsonSchema for AllocationResult {
127    fn schema_name() -> std::borrow::Cow<'static, str> {
128        "io.k8s.api.resource.v1beta1.AllocationResult".into()
129    }
130
131    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
132        crate::schemars::json_schema!({
133            "description": "AllocationResult contains attributes of an allocated resource.",
134            "type": "object",
135            "properties": {
136                "allocationTimestamp": ({
137                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::Time>();
138                    schema_obj.ensure_object().insert("description".into(), "AllocationTimestamp stores the time when the resources were allocated. This field is not guaranteed to be set, in which case that time is unknown.\n\nThis is a beta field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gate.".into());
139                    schema_obj
140                }),
141                "devices": ({
142                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::DeviceAllocationResult>();
143                    schema_obj.ensure_object().insert("description".into(), "Devices is the result of allocating devices.".into());
144                    schema_obj
145                }),
146                "nodeSelector": ({
147                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>();
148                    schema_obj.ensure_object().insert("description".into(), "NodeSelector defines where the allocated resources are available. If unset, they are available everywhere.".into());
149                    schema_obj
150                }),
151            },
152        })
153    }
154}
155
156#[cfg(feature = "schemars08")]
157impl crate::schemars08::JsonSchema for AllocationResult {
158    fn schema_name() -> std::string::String {
159        "io.k8s.api.resource.v1beta1.AllocationResult".into()
160    }
161
162    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
163        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
164            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
165                description: Some("AllocationResult contains attributes of an allocated resource.".into()),
166                ..Default::default()
167            })),
168            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
169            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
170                properties: [
171                    (
172                        "allocationTimestamp".into(),
173                        {
174                            let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::Time>().into_object();
175                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
176                                description: Some("AllocationTimestamp stores the time when the resources were allocated. This field is not guaranteed to be set, in which case that time is unknown.\n\nThis is a beta field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gate.".into()),
177                                ..Default::default()
178                            }));
179                            crate::schemars08::schema::Schema::Object(schema_obj)
180                        },
181                    ),
182                    (
183                        "devices".into(),
184                        {
185                            let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::DeviceAllocationResult>().into_object();
186                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
187                                description: Some("Devices is the result of allocating devices.".into()),
188                                ..Default::default()
189                            }));
190                            crate::schemars08::schema::Schema::Object(schema_obj)
191                        },
192                    ),
193                    (
194                        "nodeSelector".into(),
195                        {
196                            let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>().into_object();
197                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
198                                description: Some("NodeSelector defines where the allocated resources are available. If unset, they are available everywhere.".into()),
199                                ..Default::default()
200                            }));
201                            crate::schemars08::schema::Schema::Object(schema_obj)
202                        },
203                    ),
204                ].into(),
205                ..Default::default()
206            })),
207            ..Default::default()
208        })
209    }
210}