k8s_openapi/v1_30/api/resource/v1alpha2/
resource_claim_status.rs

1// Generated from definition io.k8s.api.resource.v1alpha2.ResourceClaimStatus
2
3/// ResourceClaimStatus tracks whether the resource has been allocated and what the resulting attributes are.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceClaimStatus {
6    /// Allocation is set by the resource driver once a resource or set of resources has been allocated successfully. If this is not specified, the resources have not been allocated yet.
7    pub allocation: Option<crate::api::resource::v1alpha2::AllocationResult>,
8
9    /// DeallocationRequested indicates that a ResourceClaim is to be deallocated.
10    ///
11    /// The driver then must deallocate this claim and reset the field together with clearing the Allocation field.
12    ///
13    /// While DeallocationRequested is set, no new consumers may be added to ReservedFor.
14    pub deallocation_requested: Option<bool>,
15
16    /// DriverName is a copy of the driver name from the ResourceClass at the time when allocation started.
17    pub driver_name: Option<std::string::String>,
18
19    /// 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.
20    ///
21    /// There can be at most 32 such reservations. This may get increased in the future, but not reduced.
22    pub reserved_for: Option<std::vec::Vec<crate::api::resource::v1alpha2::ResourceClaimConsumerReference>>,
23}
24
25impl crate::DeepMerge for ResourceClaimStatus {
26    fn merge_from(&mut self, other: Self) {
27        crate::DeepMerge::merge_from(&mut self.allocation, other.allocation);
28        crate::DeepMerge::merge_from(&mut self.deallocation_requested, other.deallocation_requested);
29        crate::DeepMerge::merge_from(&mut self.driver_name, other.driver_name);
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_driver_name,
48            Key_reserved_for,
49            Other,
50        }
51
52        impl<'de> crate::serde::Deserialize<'de> for Field {
53            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
54                struct Visitor;
55
56                impl crate::serde::de::Visitor<'_> for Visitor {
57                    type Value = Field;
58
59                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
60                        f.write_str("field identifier")
61                    }
62
63                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
64                        Ok(match v {
65                            "allocation" => Field::Key_allocation,
66                            "deallocationRequested" => Field::Key_deallocation_requested,
67                            "driverName" => Field::Key_driver_name,
68                            "reservedFor" => Field::Key_reserved_for,
69                            _ => Field::Other,
70                        })
71                    }
72                }
73
74                deserializer.deserialize_identifier(Visitor)
75            }
76        }
77
78        struct Visitor;
79
80        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
81            type Value = ResourceClaimStatus;
82
83            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
84                f.write_str("ResourceClaimStatus")
85            }
86
87            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
88                let mut value_allocation: Option<crate::api::resource::v1alpha2::AllocationResult> = None;
89                let mut value_deallocation_requested: Option<bool> = None;
90                let mut value_driver_name: Option<std::string::String> = None;
91                let mut value_reserved_for: Option<std::vec::Vec<crate::api::resource::v1alpha2::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_deallocation_requested => value_deallocation_requested = crate::serde::de::MapAccess::next_value(&mut map)?,
97                        Field::Key_driver_name => value_driver_name = crate::serde::de::MapAccess::next_value(&mut map)?,
98                        Field::Key_reserved_for => value_reserved_for = crate::serde::de::MapAccess::next_value(&mut map)?,
99                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
100                    }
101                }
102
103                Ok(ResourceClaimStatus {
104                    allocation: value_allocation,
105                    deallocation_requested: value_deallocation_requested,
106                    driver_name: value_driver_name,
107                    reserved_for: value_reserved_for,
108                })
109            }
110        }
111
112        deserializer.deserialize_struct(
113            "ResourceClaimStatus",
114            &[
115                "allocation",
116                "deallocationRequested",
117                "driverName",
118                "reservedFor",
119            ],
120            Visitor,
121        )
122    }
123}
124
125impl crate::serde::Serialize for ResourceClaimStatus {
126    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
127        let mut state = serializer.serialize_struct(
128            "ResourceClaimStatus",
129            self.allocation.as_ref().map_or(0, |_| 1) +
130            self.deallocation_requested.as_ref().map_or(0, |_| 1) +
131            self.driver_name.as_ref().map_or(0, |_| 1) +
132            self.reserved_for.as_ref().map_or(0, |_| 1),
133        )?;
134        if let Some(value) = &self.allocation {
135            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocation", value)?;
136        }
137        if let Some(value) = &self.deallocation_requested {
138            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deallocationRequested", value)?;
139        }
140        if let Some(value) = &self.driver_name {
141            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "driverName", value)?;
142        }
143        if let Some(value) = &self.reserved_for {
144            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "reservedFor", value)?;
145        }
146        crate::serde::ser::SerializeStruct::end(state)
147    }
148}
149
150#[cfg(feature = "schemars")]
151impl crate::schemars::JsonSchema for ResourceClaimStatus {
152    fn schema_name() -> std::borrow::Cow<'static, str> {
153        "io.k8s.api.resource.v1alpha2.ResourceClaimStatus".into()
154    }
155
156    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
157        crate::schemars::json_schema!({
158            "description": "ResourceClaimStatus tracks whether the resource has been allocated and what the resulting attributes are.",
159            "type": "object",
160            "properties": {
161                "allocation": ({
162                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1alpha2::AllocationResult>();
163                    schema_obj.ensure_object().insert("description".into(), "Allocation is set by the resource driver once a resource or set of resources has been allocated successfully. If this is not specified, the resources have not been allocated yet.".into());
164                    schema_obj
165                }),
166                "deallocationRequested": {
167                    "description": "DeallocationRequested indicates that a ResourceClaim is to be deallocated.\n\nThe driver then must deallocate this claim and reset the field together with clearing the Allocation field.\n\nWhile DeallocationRequested is set, no new consumers may be added to ReservedFor.",
168                    "type": "boolean",
169                },
170                "driverName": {
171                    "description": "DriverName is a copy of the driver name from the ResourceClass at the time when allocation started.",
172                    "type": "string",
173                },
174                "reservedFor": {
175                    "description": "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.\n\nThere can be at most 32 such reservations. This may get increased in the future, but not reduced.",
176                    "type": "array",
177                    "items": (__gen.subschema_for::<crate::api::resource::v1alpha2::ResourceClaimConsumerReference>()),
178                },
179            },
180        })
181    }
182}