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

1// Generated from definition io.k8s.api.resource.v1alpha3.ResourceClaimStatus
2
3/// 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.
7    pub allocation: Option<crate::api::resource::v1alpha3::AllocationResult>,
8
9    /// Indicates that a claim is to be deallocated. While this is set, no new consumers may be added to ReservedFor.
10    ///
11    /// This is only used if the claim needs to be deallocated by a DRA driver. That driver then must deallocate this claim and reset the field together with clearing the Allocation field.
12    ///
13    /// This is an alpha field and requires enabling the DRAControlPlaneController feature gate.
14    pub deallocation_requested: Option<bool>,
15
16    /// 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.
17    ///
18    /// 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.
19    ///
20    /// 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.
21    ///
22    /// There can be at most 32 such reservations. This may get increased in the future, but not reduced.
23    pub reserved_for: Option<std::vec::Vec<crate::api::resource::v1alpha3::ResourceClaimConsumerReference>>,
24}
25
26impl crate::DeepMerge for ResourceClaimStatus {
27    fn merge_from(&mut self, other: Self) {
28        crate::DeepMerge::merge_from(&mut self.allocation, other.allocation);
29        crate::DeepMerge::merge_from(&mut self.deallocation_requested, other.deallocation_requested);
30        crate::merge_strategies::list::map(
31            &mut self.reserved_for,
32            other.reserved_for,
33            &[|lhs, rhs| lhs.uid == rhs.uid],
34            |current_item, other_item| {
35                crate::DeepMerge::merge_from(current_item, other_item);
36            },
37        );
38    }
39}
40
41impl<'de> crate::serde::Deserialize<'de> for ResourceClaimStatus {
42    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
43        #[allow(non_camel_case_types)]
44        enum Field {
45            Key_allocation,
46            Key_deallocation_requested,
47            Key_reserved_for,
48            Other,
49        }
50
51        impl<'de> crate::serde::Deserialize<'de> for Field {
52            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
53                struct Visitor;
54
55                impl crate::serde::de::Visitor<'_> for Visitor {
56                    type Value = Field;
57
58                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
59                        f.write_str("field identifier")
60                    }
61
62                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
63                        Ok(match v {
64                            "allocation" => Field::Key_allocation,
65                            "deallocationRequested" => Field::Key_deallocation_requested,
66                            "reservedFor" => Field::Key_reserved_for,
67                            _ => Field::Other,
68                        })
69                    }
70                }
71
72                deserializer.deserialize_identifier(Visitor)
73            }
74        }
75
76        struct Visitor;
77
78        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
79            type Value = ResourceClaimStatus;
80
81            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
82                f.write_str("ResourceClaimStatus")
83            }
84
85            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
86                let mut value_allocation: Option<crate::api::resource::v1alpha3::AllocationResult> = None;
87                let mut value_deallocation_requested: Option<bool> = None;
88                let mut value_reserved_for: Option<std::vec::Vec<crate::api::resource::v1alpha3::ResourceClaimConsumerReference>> = None;
89
90                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
91                    match key {
92                        Field::Key_allocation => value_allocation = crate::serde::de::MapAccess::next_value(&mut map)?,
93                        Field::Key_deallocation_requested => value_deallocation_requested = crate::serde::de::MapAccess::next_value(&mut map)?,
94                        Field::Key_reserved_for => value_reserved_for = crate::serde::de::MapAccess::next_value(&mut map)?,
95                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
96                    }
97                }
98
99                Ok(ResourceClaimStatus {
100                    allocation: value_allocation,
101                    deallocation_requested: value_deallocation_requested,
102                    reserved_for: value_reserved_for,
103                })
104            }
105        }
106
107        deserializer.deserialize_struct(
108            "ResourceClaimStatus",
109            &[
110                "allocation",
111                "deallocationRequested",
112                "reservedFor",
113            ],
114            Visitor,
115        )
116    }
117}
118
119impl crate::serde::Serialize for ResourceClaimStatus {
120    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
121        let mut state = serializer.serialize_struct(
122            "ResourceClaimStatus",
123            self.allocation.as_ref().map_or(0, |_| 1) +
124            self.deallocation_requested.as_ref().map_or(0, |_| 1) +
125            self.reserved_for.as_ref().map_or(0, |_| 1),
126        )?;
127        if let Some(value) = &self.allocation {
128            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocation", value)?;
129        }
130        if let Some(value) = &self.deallocation_requested {
131            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deallocationRequested", value)?;
132        }
133        if let Some(value) = &self.reserved_for {
134            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "reservedFor", value)?;
135        }
136        crate::serde::ser::SerializeStruct::end(state)
137    }
138}
139
140#[cfg(feature = "schemars")]
141impl crate::schemars::JsonSchema for ResourceClaimStatus {
142    fn schema_name() -> std::string::String {
143        "io.k8s.api.resource.v1alpha3.ResourceClaimStatus".into()
144    }
145
146    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
147        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
148            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
149                description: Some("ResourceClaimStatus tracks whether the resource has been allocated and what the result of that was.".into()),
150                ..Default::default()
151            })),
152            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
153            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
154                properties: [
155                    (
156                        "allocation".into(),
157                        {
158                            let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1alpha3::AllocationResult>().into_object();
159                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
160                                description: Some("Allocation is set once the claim has been allocated successfully.".into()),
161                                ..Default::default()
162                            }));
163                            crate::schemars::schema::Schema::Object(schema_obj)
164                        },
165                    ),
166                    (
167                        "deallocationRequested".into(),
168                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
169                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
170                                description: Some("Indicates that a claim is to be deallocated. While this is set, no new consumers may be added to ReservedFor.\n\nThis is only used if the claim needs to be deallocated by a DRA driver. That driver then must deallocate this claim and reset the field together with clearing the Allocation field.\n\nThis is an alpha field and requires enabling the DRAControlPlaneController feature gate.".into()),
171                                ..Default::default()
172                            })),
173                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Boolean))),
174                            ..Default::default()
175                        }),
176                    ),
177                    (
178                        "reservedFor".into(),
179                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
180                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
181                                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.".into()),
182                                ..Default::default()
183                            })),
184                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
185                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
186                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1alpha3::ResourceClaimConsumerReference>()))),
187                                ..Default::default()
188                            })),
189                            ..Default::default()
190                        }),
191                    ),
192                ].into(),
193                ..Default::default()
194            })),
195            ..Default::default()
196        })
197    }
198}