#
k8s_openapi/v1_35/api/resource/v1beta1/
allocation_result.rs

    1// Generated from definition io.k8s.api.resource.v1beta1.AllocationResult
    2
    3/// AllocationResult contains attributes of an allocated resource.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct AllocationResult {
    6    /// AllocationTimestamp stores the time when the resources were allocated. This field is not guaranteed to be set, in which case that time is unknown.
    7    ///
    8    /// This is an alpha field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gate.
    9    pub allocation_timestamp: Option<crate::apimachinery::pkg::apis::meta::v1::Time>,
    10
    11    /// Devices is the result of allocating devices.
    12    pub devices: Option<crate::api::resource::v1beta1::DeviceAllocationResult>,
    13
    14    /// NodeSelector defines where the allocated resources are available. If unset, they are available everywhere.
    15    pub node_selector: Option<crate::api::core::v1::NodeSelector>,
    16}
    17
    18impl crate::DeepMerge for AllocationResult {
    19    fn merge_from(&mut self, other: Self) {
    20        crate::DeepMerge::merge_from(&mut self.allocation_timestamp, other.allocation_timestamp);
    21        crate::DeepMerge::merge_from(&mut self.devices, other.devices);
    22        crate::DeepMerge::merge_from(&mut self.node_selector, other.node_selector);
    23    }
    24}
    25
    26impl<'de> crate::serde::Deserialize<'de> for AllocationResult {
    27    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    28        #[allow(non_camel_case_types)]
    29        enum Field {
    30            Key_allocation_timestamp,
    31            Key_devices,
    32            Key_node_selector,
    33            Other,
    34        }
    35
    36        impl<'de> crate::serde::Deserialize<'de> for Field {
    37            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    38                struct Visitor;
    39
    40                impl crate::serde::de::Visitor<'_> for Visitor {
    41                    type Value = Field;
    42
    43                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    44                        f.write_str("field identifier")
    45                    }
    46
    47                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    48                        Ok(match v {
    49                            "allocationTimestamp" => Field::Key_allocation_timestamp,
    50                            "devices" => Field::Key_devices,
    51                            "nodeSelector" => Field::Key_node_selector,
    52                            _ => Field::Other,
    53                        })
    54                    }
    55                }
    56
    57                deserializer.deserialize_identifier(Visitor)
    58            }
    59        }
    60
    61        struct Visitor;
    62
    63        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    64            type Value = AllocationResult;
    65
    66            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    67                f.write_str("AllocationResult")
    68            }
    69
    70            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    71                let mut value_allocation_timestamp: Option<crate::apimachinery::pkg::apis::meta::v1::Time> = None;
    72                let mut value_devices: Option<crate::api::resource::v1beta1::DeviceAllocationResult> = None;
    73                let mut value_node_selector: Option<crate::api::core::v1::NodeSelector> = None;
    74
    75                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    76                    match key {
    77                        Field::Key_allocation_timestamp => value_allocation_timestamp = crate::serde::de::MapAccess::next_value(&mut map)?,
    78                        Field::Key_devices => value_devices = crate::serde::de::MapAccess::next_value(&mut map)?,
    79                        Field::Key_node_selector => value_node_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
    80                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    81                    }
    82                }
    83
    84                Ok(AllocationResult {
    85                    allocation_timestamp: value_allocation_timestamp,
    86                    devices: value_devices,
    87                    node_selector: value_node_selector,
    88                })
    89            }
    90        }
    91
    92        deserializer.deserialize_struct(
    93            "AllocationResult",
    94            &[
    95                "allocationTimestamp",
    96                "devices",
    97                "nodeSelector",
    98            ],
    99            Visitor,
    100        )
    101    }
    102}
    103
    104impl crate::serde::Serialize for AllocationResult {
    105    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    106        let mut state = serializer.serialize_struct(
    107            "AllocationResult",
    108            self.allocation_timestamp.as_ref().map_or(0, |_| 1) +
    109            self.devices.as_ref().map_or(0, |_| 1) +
    110            self.node_selector.as_ref().map_or(0, |_| 1),
    111        )?;
    112        if let Some(value) = &self.allocation_timestamp {
    113            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationTimestamp", value)?;
    114        }
    115        if let Some(value) = &self.devices {
    116            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "devices", value)?;
    117        }
    118        if let Some(value) = &self.node_selector {
    119            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeSelector", value)?;
    120        }
    121        crate::serde::ser::SerializeStruct::end(state)
    122    }
    123}
    124
    125#[cfg(feature = "schemars")]
    126impl crate::schemars::JsonSchema for AllocationResult {
    127    fn schema_name() -> std::borrow::Cow<'static, str> {
    128        "io.k8s.api.resource.v1beta1.AllocationResult".into()
    129    }
    130
    131    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    132        crate::schemars::json_schema!({
    133            "description": "AllocationResult contains attributes of an allocated resource.",
    134            "type": "object",
    135            "properties": {
    136                "allocationTimestamp": ({
    137                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::Time>();
    138                    schema_obj.ensure_object().insert("description".into(), "AllocationTimestamp stores the time when the resources were allocated. This field is not guaranteed to be set, in which case that time is unknown.\n\nThis is an alpha field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gate.".into());
    139                    schema_obj
    140                }),
    141                "devices": ({
    142                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::DeviceAllocationResult>();
    143                    schema_obj.ensure_object().insert("description".into(), "Devices is the result of allocating devices.".into());
    144                    schema_obj
    145                }),
    146                "nodeSelector": ({
    147                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>();
    148                    schema_obj.ensure_object().insert("description".into(), "NodeSelector defines where the allocated resources are available. If unset, they are available everywhere.".into());
    149                    schema_obj
    150                }),
    151            },
    152        })
    153    }
    154}