k8s_openapi/v1_31/api/resource/v1alpha3/
allocation_result.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct AllocationResult {
6 pub controller: Option<std::string::String>,
12
13 pub devices: Option<crate::api::resource::v1alpha3::DeviceAllocationResult>,
15
16 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::string::String {
130 "io.k8s.api.resource.v1alpha3.AllocationResult".into()
131 }
132
133 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
134 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
135 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
136 description: Some("AllocationResult contains attributes of an allocated resource.".into()),
137 ..Default::default()
138 })),
139 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
140 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
141 properties: [
142 (
143 "controller".into(),
144 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
145 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
146 description: Some("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.".into()),
147 ..Default::default()
148 })),
149 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
150 ..Default::default()
151 }),
152 ),
153 (
154 "devices".into(),
155 {
156 let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1alpha3::DeviceAllocationResult>().into_object();
157 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
158 description: Some("Devices is the result of allocating devices.".into()),
159 ..Default::default()
160 }));
161 crate::schemars::schema::Schema::Object(schema_obj)
162 },
163 ),
164 (
165 "nodeSelector".into(),
166 {
167 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>().into_object();
168 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
169 description: Some("NodeSelector defines where the allocated resources are available. If unset, they are available everywhere.".into()),
170 ..Default::default()
171 }));
172 crate::schemars::schema::Schema::Object(schema_obj)
173 },
174 ),
175 ].into(),
176 ..Default::default()
177 })),
178 ..Default::default()
179 })
180 }
181}