#
k8s_openapi/v1_35/api/resource/v1/
resource_claim_status.rs

    1// Generated from definition io.k8s.api.resource.v1.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::v1::AllocationResult>,
    8
    9    /// 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.
    10    pub devices: Option<std::vec::Vec<crate::api::resource::v1::AllocatedDeviceStatus>>,
    11
    12    /// 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.
    19    pub reserved_for: Option<std::vec::Vec<crate::api::resource::v1::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, |lhs, rhs| lhs.share_id == rhs.share_id],
    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 core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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::v1::AllocationResult> = None;
    90                let mut value_devices: Option<std::vec::Vec<crate::api::resource::v1::AllocatedDeviceStatus>> = None;
    91                let mut value_reserved_for: Option<std::vec::Vec<crate::api::resource::v1::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() -> std::borrow::Cow<'static, str> {
    146        "io.k8s.api.resource.v1.ResourceClaimStatus".into()
    147    }
    148
    149    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    150        crate::schemars::json_schema!({
    151            "description": "ResourceClaimStatus tracks whether the resource has been allocated and what the result of that was.",
    152            "type": "object",
    153            "properties": {
    154                "allocation": ({
    155                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1::AllocationResult>();
    156                    schema_obj.ensure_object().insert("description".into(), "Allocation is set once the claim has been allocated successfully.".into());
    157                    schema_obj
    158                }),
    159                "devices": {
    160                    "description": "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.",
    161                    "type": "array",
    162                    "items": (__gen.subschema_for::<crate::api::resource::v1::AllocatedDeviceStatus>()),
    163                },
    164                "reservedFor": {
    165                    "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. 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.",
    166                    "type": "array",
    167                    "items": (__gen.subschema_for::<crate::api::resource::v1::ResourceClaimConsumerReference>()),
    168                },
    169            },
    170        })
    171    }
    172}