k8s_openapi/v1_31/api/resource/v1alpha3/
allocation_result.rs

1// Generated from definition io.k8s.api.resource.v1alpha3.AllocationResult
2
3/// AllocationResult contains attributes of an allocated resource.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct AllocationResult {
6    /// Controller is the name of the DRA driver which handled the allocation. That driver is also responsible for deallocating the claim. It is empty when the claim can be deallocated without involving a driver.
7    ///
8    /// A driver may allocate devices provided by other drivers, so this driver name here can be different from the driver names listed for the results.
9    ///
10    /// This is an alpha field and requires enabling the DRAControlPlaneController feature gate.
11    pub controller: Option<std::string::String>,
12
13    /// Devices is the result of allocating devices.
14    pub devices: Option<crate::api::resource::v1alpha3::DeviceAllocationResult>,
15
16    /// NodeSelector defines where the allocated resources are available. If unset, they are available everywhere.
17    pub node_selector: Option<crate::api::core::v1::NodeSelector>,
18}
19
20impl crate::DeepMerge for AllocationResult {
21    fn merge_from(&mut self, other: Self) {
22        crate::DeepMerge::merge_from(&mut self.controller, other.controller);
23        crate::DeepMerge::merge_from(&mut self.devices, other.devices);
24        crate::DeepMerge::merge_from(&mut self.node_selector, other.node_selector);
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for AllocationResult {
29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
30        #[allow(non_camel_case_types)]
31        enum Field {
32            Key_controller,
33            Key_devices,
34            Key_node_selector,
35            Other,
36        }
37
38        impl<'de> crate::serde::Deserialize<'de> for Field {
39            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
40                struct Visitor;
41
42                impl crate::serde::de::Visitor<'_> for Visitor {
43                    type Value = Field;
44
45                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
46                        f.write_str("field identifier")
47                    }
48
49                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
50                        Ok(match v {
51                            "controller" => Field::Key_controller,
52                            "devices" => Field::Key_devices,
53                            "nodeSelector" => Field::Key_node_selector,
54                            _ => Field::Other,
55                        })
56                    }
57                }
58
59                deserializer.deserialize_identifier(Visitor)
60            }
61        }
62
63        struct Visitor;
64
65        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
66            type Value = AllocationResult;
67
68            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
69                f.write_str("AllocationResult")
70            }
71
72            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
73                let mut value_controller: Option<std::string::String> = None;
74                let mut value_devices: Option<crate::api::resource::v1alpha3::DeviceAllocationResult> = None;
75                let mut value_node_selector: Option<crate::api::core::v1::NodeSelector> = None;
76
77                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
78                    match key {
79                        Field::Key_controller => value_controller = crate::serde::de::MapAccess::next_value(&mut map)?,
80                        Field::Key_devices => value_devices = crate::serde::de::MapAccess::next_value(&mut map)?,
81                        Field::Key_node_selector => value_node_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
82                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
83                    }
84                }
85
86                Ok(AllocationResult {
87                    controller: value_controller,
88                    devices: value_devices,
89                    node_selector: value_node_selector,
90                })
91            }
92        }
93
94        deserializer.deserialize_struct(
95            "AllocationResult",
96            &[
97                "controller",
98                "devices",
99                "nodeSelector",
100            ],
101            Visitor,
102        )
103    }
104}
105
106impl crate::serde::Serialize for AllocationResult {
107    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
108        let mut state = serializer.serialize_struct(
109            "AllocationResult",
110            self.controller.as_ref().map_or(0, |_| 1) +
111            self.devices.as_ref().map_or(0, |_| 1) +
112            self.node_selector.as_ref().map_or(0, |_| 1),
113        )?;
114        if let Some(value) = &self.controller {
115            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "controller", value)?;
116        }
117        if let Some(value) = &self.devices {
118            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "devices", value)?;
119        }
120        if let Some(value) = &self.node_selector {
121            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeSelector", value)?;
122        }
123        crate::serde::ser::SerializeStruct::end(state)
124    }
125}
126
127#[cfg(feature = "schemars")]
128impl crate::schemars::JsonSchema for AllocationResult {
129    fn schema_name() -> std::borrow::Cow<'static, str> {
130        "io.k8s.api.resource.v1alpha3.AllocationResult".into()
131    }
132
133    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
134        crate::schemars::json_schema!({
135            "description": "AllocationResult contains attributes of an allocated resource.",
136            "type": "object",
137            "properties": {
138                "controller": {
139                    "description": "Controller is the name of the DRA driver which handled the allocation. That driver is also responsible for deallocating the claim. It is empty when the claim can be deallocated without involving a driver.\n\nA driver may allocate devices provided by other drivers, so this driver name here can be different from the driver names listed for the results.\n\nThis is an alpha field and requires enabling the DRAControlPlaneController feature gate.",
140                    "type": "string",
141                },
142                "devices": ({
143                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1alpha3::DeviceAllocationResult>();
144                    schema_obj.ensure_object().insert("description".into(), "Devices is the result of allocating devices.".into());
145                    schema_obj
146                }),
147                "nodeSelector": ({
148                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>();
149                    schema_obj.ensure_object().insert("description".into(), "NodeSelector defines where the allocated resources are available. If unset, they are available everywhere.".into());
150                    schema_obj
151                }),
152            },
153        })
154    }
155}