1// Generated from definition io.k8s.api.resource.v1beta1.ResourceClaimStatus
23/// ResourceClaimStatus tracks whether the resource has been allocated and what the result of that was.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceClaimStatus {
6/// Allocation is set once the claim has been allocated successfully.
7pub allocation: Option<crate::api::resource::v1beta1::AllocationResult>,
89/// Devices contains the status of each device allocated for this claim, as reported by the driver. This can include driver-specific information. Entries are owned by their respective drivers.
10pub devices: Option<std::vec::Vec<crate::api::resource::v1beta1::AllocatedDeviceStatus>>,
1112/// ReservedFor indicates which entities are currently allowed to use the claim. A Pod which references a ResourceClaim which is not reserved for that Pod will not be started. A claim that is in use or might be in use because it has been reserved must not get deallocated.
13 ///
14 /// In a cluster with multiple scheduler instances, two pods might get scheduled concurrently by different schedulers. When they reference the same ResourceClaim which already has reached its maximum number of consumers, only one pod can be scheduled.
15 ///
16 /// Both schedulers try to add their pod to the claim.status.reservedFor field, but only the update that reaches the API server first gets stored. The other one fails with an error and the scheduler which issued it knows that it must put the pod back into the queue, waiting for the ResourceClaim to become usable again.
17 ///
18 /// There can be at most 256 such reservations. This may get increased in the future, but not reduced.
19pub reserved_for: Option<std::vec::Vec<crate::api::resource::v1beta1::ResourceClaimConsumerReference>>,
20}
2122impl crate::DeepMerge for ResourceClaimStatus {
23fn merge_from(&mut self, other: Self) {
24crate::DeepMerge::merge_from(&mut self.allocation, other.allocation);
25crate::merge_strategies::list::map(
26&mut self.devices,
27 other.devices,
28&[|lhs, rhs| lhs.driver == rhs.driver, |lhs, rhs| lhs.device == rhs.device, |lhs, rhs| lhs.pool == rhs.pool],
29 |current_item, other_item| {
30crate::DeepMerge::merge_from(current_item, other_item);
31 },
32 );
33crate::merge_strategies::list::map(
34&mut self.reserved_for,
35 other.reserved_for,
36&[|lhs, rhs| lhs.uid == rhs.uid],
37 |current_item, other_item| {
38crate::DeepMerge::merge_from(current_item, other_item);
39 },
40 );
41 }
42}
4344impl<'de> crate::serde::Deserialize<'de> for ResourceClaimStatus {
45fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
46#[allow(non_camel_case_types)]
47enum Field {
48 Key_allocation,
49 Key_devices,
50 Key_reserved_for,
51 Other,
52 }
5354impl<'de> crate::serde::Deserialize<'de> for Field {
55fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
56struct Visitor;
5758impl crate::serde::de::Visitor<'_> for Visitor {
59type Value = Field;
6061fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
62 f.write_str("field identifier")
63 }
6465fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
66Ok(match v {
67"allocation" => Field::Key_allocation,
68"devices" => Field::Key_devices,
69"reservedFor" => Field::Key_reserved_for,
70_ => Field::Other,
71 })
72 }
73 }
7475 deserializer.deserialize_identifier(Visitor)
76 }
77 }
7879struct Visitor;
8081impl<'de> crate::serde::de::Visitor<'de> for Visitor {
82type Value = ResourceClaimStatus;
8384fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
85 f.write_str("ResourceClaimStatus")
86 }
8788fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
89let mut value_allocation: Option<crate::api::resource::v1beta1::AllocationResult> = None;
90let mut value_devices: Option<std::vec::Vec<crate::api::resource::v1beta1::AllocatedDeviceStatus>> = None;
91let mut value_reserved_for: Option<std::vec::Vec<crate::api::resource::v1beta1::ResourceClaimConsumerReference>> = None;
9293while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
94match key {
95 Field::Key_allocation => value_allocation = crate::serde::de::MapAccess::next_value(&mut map)?,
96 Field::Key_devices => value_devices = crate::serde::de::MapAccess::next_value(&mut map)?,
97 Field::Key_reserved_for => value_reserved_for = crate::serde::de::MapAccess::next_value(&mut map)?,
98 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
99 }
100 }
101102Ok(ResourceClaimStatus {
103 allocation: value_allocation,
104 devices: value_devices,
105 reserved_for: value_reserved_for,
106 })
107 }
108 }
109110 deserializer.deserialize_struct(
111"ResourceClaimStatus",
112&[
113"allocation",
114"devices",
115"reservedFor",
116 ],
117 Visitor,
118 )
119 }
120}
121122impl crate::serde::Serialize for ResourceClaimStatus {
123fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
124let mut state = serializer.serialize_struct(
125"ResourceClaimStatus",
126self.allocation.as_ref().map_or(0, |_| 1) +
127self.devices.as_ref().map_or(0, |_| 1) +
128self.reserved_for.as_ref().map_or(0, |_| 1),
129 )?;
130if let Some(value) = &self.allocation {
131crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocation", value)?;
132 }
133if let Some(value) = &self.devices {
134crate::serde::ser::SerializeStruct::serialize_field(&mut state, "devices", value)?;
135 }
136if let Some(value) = &self.reserved_for {
137crate::serde::ser::SerializeStruct::serialize_field(&mut state, "reservedFor", value)?;
138 }
139crate::serde::ser::SerializeStruct::end(state)
140 }
141}
142143#[cfg(feature = "schemars")]
144impl crate::schemars::JsonSchema for ResourceClaimStatus {
145fn schema_name() -> std::string::String {
146"io.k8s.api.resource.v1beta1.ResourceClaimStatus".into()
147 }
148149fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
150crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
151 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
152 description: Some("ResourceClaimStatus tracks whether the resource has been allocated and what the result of that was.".into()),
153 ..Default::default()
154 })),
155 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
156 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
157 properties: [
158 (
159"allocation".into(),
160 {
161let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::AllocationResult>().into_object();
162 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
163 description: Some("Allocation is set once the claim has been allocated successfully.".into()),
164 ..Default::default()
165 }));
166crate::schemars::schema::Schema::Object(schema_obj)
167 },
168 ),
169 (
170"devices".into(),
171crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
172 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
173 description: Some("Devices contains the status of each device allocated for this claim, as reported by the driver. This can include driver-specific information. Entries are owned by their respective drivers.".into()),
174 ..Default::default()
175 })),
176 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
177 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
178 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta1::AllocatedDeviceStatus>()))),
179 ..Default::default()
180 })),
181 ..Default::default()
182 }),
183 ),
184 (
185"reservedFor".into(),
186crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
187 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
188 description: Some("ReservedFor indicates which entities are currently allowed to use the claim. A Pod which references a ResourceClaim which is not reserved for that Pod will not be started. A claim that is in use or might be in use because it has been reserved must not get deallocated.\n\nIn a cluster with multiple scheduler instances, two pods might get scheduled concurrently by different schedulers. When they reference the same ResourceClaim which already has reached its maximum number of consumers, only one pod can be scheduled.\n\nBoth schedulers try to add their pod to the claim.status.reservedFor field, but only the update that reaches the API server first gets stored. The other one fails with an error and the scheduler which issued it knows that it must put the pod back into the queue, waiting for the ResourceClaim to become usable again.\n\nThere can be at most 256 such reservations. This may get increased in the future, but not reduced.".into()),
189 ..Default::default()
190 })),
191 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
192 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
193 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta1::ResourceClaimConsumerReference>()))),
194 ..Default::default()
195 })),
196 ..Default::default()
197 }),
198 ),
199 ].into(),
200 ..Default::default()
201 })),
202 ..Default::default()
203 })
204 }
205}