1// Generated from definition io.k8s.api.resource.v1beta2.DeviceRequest
23/// DeviceRequest is a request for devices required for a claim. This is typically a request for a single resource like a device, but can also ask for several identical devices. With FirstAvailable it is also possible to provide a prioritized list of requests.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceRequest {
6/// Exactly specifies the details for a single request that must be met exactly for the request to be satisfied.
7 ///
8 /// One of Exactly or FirstAvailable must be set.
9pub exactly: Option<crate::api::resource::v1beta2::ExactDeviceRequest>,
1011/// FirstAvailable contains subrequests, of which exactly one will be selected by the scheduler. It tries to satisfy them in the order in which they are listed here. So if there are two entries in the list, the scheduler will only check the second one if it determines that the first one can not be used.
12 ///
13 /// DRA does not yet implement scoring, so the scheduler will select the first set of devices that satisfies all the requests in the claim. And if the requirements can be satisfied on more than one node, other scheduling features will determine which node is chosen. This means that the set of devices allocated to a claim might not be the optimal set available to the cluster. Scoring will be implemented later.
14pub first_available: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSubRequest>>,
1516/// Name can be used to reference this request in a pod.spec.containers\[\].resources.claims entry and in a constraint of the claim.
17 ///
18 /// References using the name in the DeviceRequest will uniquely identify a request when the Exactly field is set. When the FirstAvailable field is set, a reference to the name of the DeviceRequest will match whatever subrequest is chosen by the scheduler.
19 ///
20 /// Must be a DNS label.
21pub name: std::string::String,
22}
2324impl crate::DeepMerge for DeviceRequest {
25fn merge_from(&mut self, other: Self) {
26crate::DeepMerge::merge_from(&mut self.exactly, other.exactly);
27crate::merge_strategies::list::atomic(&mut self.first_available, other.first_available);
28crate::DeepMerge::merge_from(&mut self.name, other.name);
29 }
30}
3132impl<'de> crate::serde::Deserialize<'de> for DeviceRequest {
33fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
34#[allow(non_camel_case_types)]
35enum Field {
36 Key_exactly,
37 Key_first_available,
38 Key_name,
39 Other,
40 }
4142impl<'de> crate::serde::Deserialize<'de> for Field {
43fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
44struct Visitor;
4546impl crate::serde::de::Visitor<'_> for Visitor {
47type Value = Field;
4849fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
50 f.write_str("field identifier")
51 }
5253fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
54Ok(match v {
55"exactly" => Field::Key_exactly,
56"firstAvailable" => Field::Key_first_available,
57"name" => Field::Key_name,
58_ => Field::Other,
59 })
60 }
61 }
6263 deserializer.deserialize_identifier(Visitor)
64 }
65 }
6667struct Visitor;
6869impl<'de> crate::serde::de::Visitor<'de> for Visitor {
70type Value = DeviceRequest;
7172fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
73 f.write_str("DeviceRequest")
74 }
7576fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
77let mut value_exactly: Option<crate::api::resource::v1beta2::ExactDeviceRequest> = None;
78let mut value_first_available: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSubRequest>> = None;
79let mut value_name: Option<std::string::String> = None;
8081while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
82match key {
83 Field::Key_exactly => value_exactly = crate::serde::de::MapAccess::next_value(&mut map)?,
84 Field::Key_first_available => value_first_available = crate::serde::de::MapAccess::next_value(&mut map)?,
85 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
86 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
87 }
88 }
8990Ok(DeviceRequest {
91 exactly: value_exactly,
92 first_available: value_first_available,
93 name: value_name.unwrap_or_default(),
94 })
95 }
96 }
9798 deserializer.deserialize_struct(
99"DeviceRequest",
100&[
101"exactly",
102"firstAvailable",
103"name",
104 ],
105 Visitor,
106 )
107 }
108}
109110impl crate::serde::Serialize for DeviceRequest {
111fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
112let mut state = serializer.serialize_struct(
113"DeviceRequest",
1141 +
115self.exactly.as_ref().map_or(0, |_| 1) +
116self.first_available.as_ref().map_or(0, |_| 1),
117 )?;
118if let Some(value) = &self.exactly {
119crate::serde::ser::SerializeStruct::serialize_field(&mut state, "exactly", value)?;
120 }
121if let Some(value) = &self.first_available {
122crate::serde::ser::SerializeStruct::serialize_field(&mut state, "firstAvailable", value)?;
123 }
124crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
125crate::serde::ser::SerializeStruct::end(state)
126 }
127}
128129#[cfg(feature = "schemars")]
130impl crate::schemars::JsonSchema for DeviceRequest {
131fn schema_name() -> std::string::String {
132"io.k8s.api.resource.v1beta2.DeviceRequest".into()
133 }
134135fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
136crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
137 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
138 description: Some("DeviceRequest is a request for devices required for a claim. This is typically a request for a single resource like a device, but can also ask for several identical devices. With FirstAvailable it is also possible to provide a prioritized list of requests.".into()),
139 ..Default::default()
140 })),
141 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
142 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
143 properties: [
144 (
145"exactly".into(),
146 {
147let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta2::ExactDeviceRequest>().into_object();
148 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
149 description: Some("Exactly specifies the details for a single request that must be met exactly for the request to be satisfied.\n\nOne of Exactly or FirstAvailable must be set.".into()),
150 ..Default::default()
151 }));
152crate::schemars::schema::Schema::Object(schema_obj)
153 },
154 ),
155 (
156"firstAvailable".into(),
157crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
158 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
159 description: Some("FirstAvailable contains subrequests, of which exactly one will be selected by the scheduler. It tries to satisfy them in the order in which they are listed here. So if there are two entries in the list, the scheduler will only check the second one if it determines that the first one can not be used.\n\nDRA does not yet implement scoring, so the scheduler will select the first set of devices that satisfies all the requests in the claim. And if the requirements can be satisfied on more than one node, other scheduling features will determine which node is chosen. This means that the set of devices allocated to a claim might not be the optimal set available to the cluster. Scoring will be implemented later.".into()),
160 ..Default::default()
161 })),
162 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
163 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
164 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta2::DeviceSubRequest>()))),
165 ..Default::default()
166 })),
167 ..Default::default()
168 }),
169 ),
170 (
171"name".into(),
172crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
173 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
174 description: Some("Name can be used to reference this request in a pod.spec.containers[].resources.claims entry and in a constraint of the claim.\n\nReferences using the name in the DeviceRequest will uniquely identify a request when the Exactly field is set. When the FirstAvailable field is set, a reference to the name of the DeviceRequest will match whatever subrequest is chosen by the scheduler.\n\nMust be a DNS label.".into()),
175 ..Default::default()
176 })),
177 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
178 ..Default::default()
179 }),
180 ),
181 ].into(),
182 required: [
183"name".into(),
184 ].into(),
185 ..Default::default()
186 })),
187 ..Default::default()
188 })
189 }
190}