k8s_openapi/v1_32/api/resource/v1beta1/
resource_claim_status.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceClaimStatus {
6 pub allocation: Option<crate::api::resource::v1beta1::AllocationResult>,
8
9 pub devices: Option<Vec<crate::api::resource::v1beta1::AllocatedDeviceStatus>>,
11
12 pub reserved_for: Option<Vec<crate::api::resource::v1beta1::ResourceClaimConsumerReference>>,
20}
21
22impl crate::DeepMerge for ResourceClaimStatus {
23 fn merge_from(&mut self, other: Self) {
24 crate::DeepMerge::merge_from(&mut self.allocation, other.allocation);
25 crate::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| {
30 crate::DeepMerge::merge_from(current_item, other_item);
31 },
32 );
33 crate::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| {
38 crate::DeepMerge::merge_from(current_item, other_item);
39 },
40 );
41 }
42}
43
44impl<'de> crate::serde::Deserialize<'de> for ResourceClaimStatus {
45 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
46 #[allow(non_camel_case_types)]
47 enum Field {
48 Key_allocation,
49 Key_devices,
50 Key_reserved_for,
51 Other,
52 }
53
54 impl<'de> crate::serde::Deserialize<'de> for Field {
55 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
56 struct Visitor;
57
58 impl crate::serde::de::Visitor<'_> for Visitor {
59 type Value = Field;
60
61 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62 f.write_str("field identifier")
63 }
64
65 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
66 Ok(match v {
67 "allocation" => Field::Key_allocation,
68 "devices" => Field::Key_devices,
69 "reservedFor" => Field::Key_reserved_for,
70 _ => Field::Other,
71 })
72 }
73 }
74
75 deserializer.deserialize_identifier(Visitor)
76 }
77 }
78
79 struct Visitor;
80
81 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
82 type Value = ResourceClaimStatus;
83
84 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
85 f.write_str("ResourceClaimStatus")
86 }
87
88 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
89 let mut value_allocation: Option<crate::api::resource::v1beta1::AllocationResult> = None;
90 let mut value_devices: Option<Vec<crate::api::resource::v1beta1::AllocatedDeviceStatus>> = None;
91 let mut value_reserved_for: Option<Vec<crate::api::resource::v1beta1::ResourceClaimConsumerReference>> = None;
92
93 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
94 match 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 }
101
102 Ok(ResourceClaimStatus {
103 allocation: value_allocation,
104 devices: value_devices,
105 reserved_for: value_reserved_for,
106 })
107 }
108 }
109
110 deserializer.deserialize_struct(
111 "ResourceClaimStatus",
112 &[
113 "allocation",
114 "devices",
115 "reservedFor",
116 ],
117 Visitor,
118 )
119 }
120}
121
122impl crate::serde::Serialize for ResourceClaimStatus {
123 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
124 let mut state = serializer.serialize_struct(
125 "ResourceClaimStatus",
126 self.allocation.as_ref().map_or(0, |_| 1) +
127 self.devices.as_ref().map_or(0, |_| 1) +
128 self.reserved_for.as_ref().map_or(0, |_| 1),
129 )?;
130 if let Some(value) = &self.allocation {
131 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocation", value)?;
132 }
133 if let Some(value) = &self.devices {
134 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "devices", value)?;
135 }
136 if let Some(value) = &self.reserved_for {
137 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "reservedFor", value)?;
138 }
139 crate::serde::ser::SerializeStruct::end(state)
140 }
141}
142
143#[cfg(feature = "schemars")]
144impl crate::schemars::JsonSchema for ResourceClaimStatus {
145 fn schema_name() -> String {
146 "io.k8s.api.resource.v1beta1.ResourceClaimStatus".to_owned()
147 }
148
149 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
150 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
151 metadata: Some(Box::new(crate::schemars::schema::Metadata {
152 description: Some("ResourceClaimStatus tracks whether the resource has been allocated and what the result of that was.".to_owned()),
153 ..Default::default()
154 })),
155 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
156 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
157 properties: [
158 (
159 "allocation".to_owned(),
160 {
161 let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::AllocationResult>().into_object();
162 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
163 description: Some("Allocation is set once the claim has been allocated successfully.".to_owned()),
164 ..Default::default()
165 }));
166 crate::schemars::schema::Schema::Object(schema_obj)
167 },
168 ),
169 (
170 "devices".to_owned(),
171 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
172 metadata: Some(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.".to_owned()),
174 ..Default::default()
175 })),
176 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
177 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
178 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::resource::v1beta1::AllocatedDeviceStatus>()))),
179 ..Default::default()
180 })),
181 ..Default::default()
182 }),
183 ),
184 (
185 "reservedFor".to_owned(),
186 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
187 metadata: Some(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 32 such reservations. This may get increased in the future, but not reduced.".to_owned()),
189 ..Default::default()
190 })),
191 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
192 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
193 items: Some(crate::schemars::schema::SingleOrVec::Single(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}