#
k8s_openapi/v1_35/api/resource/v1beta2/
device_request.rs

    1// Generated from definition io.k8s.api.resource.v1beta2.DeviceRequest
    2
    3/// DeviceRequest is a request for devices required for a claim. This is typically a request for a single resource like a device, but can also ask for several identical devices. With FirstAvailable it is also possible to provide a prioritized list of requests.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct DeviceRequest {
    6    /// Exactly specifies the details for a single request that must be met exactly for the request to be satisfied.
    7    ///
    8    /// One of Exactly or FirstAvailable must be set.
    9    pub exactly: Option<crate::api::resource::v1beta2::ExactDeviceRequest>,
    10
    11    /// FirstAvailable contains subrequests, of which exactly one will be selected by the scheduler. It tries to satisfy them in the order in which they are listed here. So if there are two entries in the list, the scheduler will only check the second one if it determines that the first one can not be used.
    12    ///
    13    /// DRA does not yet implement scoring, so the scheduler will select the first set of devices that satisfies all the requests in the claim. And if the requirements can be satisfied on more than one node, other scheduling features will determine which node is chosen. This means that the set of devices allocated to a claim might not be the optimal set available to the cluster. Scoring will be implemented later.
    14    pub first_available: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSubRequest>>,
    15
    16    /// Name can be used to reference this request in a pod.spec.containers\[\].resources.claims entry and in a constraint of the claim.
    17    ///
    18    /// References using the name in the DeviceRequest will uniquely identify a request when the Exactly field is set. When the FirstAvailable field is set, a reference to the name of the DeviceRequest will match whatever subrequest is chosen by the scheduler.
    19    ///
    20    /// Must be a DNS label.
    21    pub name: std::string::String,
    22}
    23
    24impl crate::DeepMerge for DeviceRequest {
    25    fn merge_from(&mut self, other: Self) {
    26        crate::DeepMerge::merge_from(&mut self.exactly, other.exactly);
    27        crate::merge_strategies::list::atomic(&mut self.first_available, other.first_available);
    28        crate::DeepMerge::merge_from(&mut self.name, other.name);
    29    }
    30}
    31
    32impl<'de> crate::serde::Deserialize<'de> for DeviceRequest {
    33    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    34        #[allow(non_camel_case_types)]
    35        enum Field {
    36            Key_exactly,
    37            Key_first_available,
    38            Key_name,
    39            Other,
    40        }
    41
    42        impl<'de> crate::serde::Deserialize<'de> for Field {
    43            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    44                struct Visitor;
    45
    46                impl crate::serde::de::Visitor<'_> for Visitor {
    47                    type Value = Field;
    48
    49                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    50                        f.write_str("field identifier")
    51                    }
    52
    53                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    54                        Ok(match v {
    55                            "exactly" => Field::Key_exactly,
    56                            "firstAvailable" => Field::Key_first_available,
    57                            "name" => Field::Key_name,
    58                            _ => Field::Other,
    59                        })
    60                    }
    61                }
    62
    63                deserializer.deserialize_identifier(Visitor)
    64            }
    65        }
    66
    67        struct Visitor;
    68
    69        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    70            type Value = DeviceRequest;
    71
    72            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    73                f.write_str("DeviceRequest")
    74            }
    75
    76            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    77                let mut value_exactly: Option<crate::api::resource::v1beta2::ExactDeviceRequest> = None;
    78                let mut value_first_available: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSubRequest>> = None;
    79                let mut value_name: Option<std::string::String> = None;
    80
    81                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    82                    match key {
    83                        Field::Key_exactly => value_exactly = crate::serde::de::MapAccess::next_value(&mut map)?,
    84                        Field::Key_first_available => value_first_available = crate::serde::de::MapAccess::next_value(&mut map)?,
    85                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    86                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    87                    }
    88                }
    89
    90                Ok(DeviceRequest {
    91                    exactly: value_exactly,
    92                    first_available: value_first_available,
    93                    name: value_name.unwrap_or_default(),
    94                })
    95            }
    96        }
    97
    98        deserializer.deserialize_struct(
    99            "DeviceRequest",
    100            &[
    101                "exactly",
    102                "firstAvailable",
    103                "name",
    104            ],
    105            Visitor,
    106        )
    107    }
    108}
    109
    110impl crate::serde::Serialize for DeviceRequest {
    111    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    112        let mut state = serializer.serialize_struct(
    113            "DeviceRequest",
    114            1 +
    115            self.exactly.as_ref().map_or(0, |_| 1) +
    116            self.first_available.as_ref().map_or(0, |_| 1),
    117        )?;
    118        if let Some(value) = &self.exactly {
    119            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "exactly", value)?;
    120        }
    121        if let Some(value) = &self.first_available {
    122            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "firstAvailable", value)?;
    123        }
    124        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
    125        crate::serde::ser::SerializeStruct::end(state)
    126    }
    127}
    128
    129#[cfg(feature = "schemars")]
    130impl crate::schemars::JsonSchema for DeviceRequest {
    131    fn schema_name() -> std::borrow::Cow<'static, str> {
    132        "io.k8s.api.resource.v1beta2.DeviceRequest".into()
    133    }
    134
    135    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    136        crate::schemars::json_schema!({
    137            "description": "DeviceRequest is a request for devices required for a claim. This is typically a request for a single resource like a device, but can also ask for several identical devices. With FirstAvailable it is also possible to provide a prioritized list of requests.",
    138            "type": "object",
    139            "properties": {
    140                "exactly": ({
    141                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta2::ExactDeviceRequest>();
    142                    schema_obj.ensure_object().insert("description".into(), "Exactly specifies the details for a single request that must be met exactly for the request to be satisfied.\n\nOne of Exactly or FirstAvailable must be set.".into());
    143                    schema_obj
    144                }),
    145                "firstAvailable": {
    146                    "description": "FirstAvailable contains subrequests, of which exactly one will be selected by the scheduler. It tries to satisfy them in the order in which they are listed here. So if there are two entries in the list, the scheduler will only check the second one if it determines that the first one can not be used.\n\nDRA does not yet implement scoring, so the scheduler will select the first set of devices that satisfies all the requests in the claim. And if the requirements can be satisfied on more than one node, other scheduling features will determine which node is chosen. This means that the set of devices allocated to a claim might not be the optimal set available to the cluster. Scoring will be implemented later.",
    147                    "type": "array",
    148                    "items": (__gen.subschema_for::<crate::api::resource::v1beta2::DeviceSubRequest>()),
    149                },
    150                "name": {
    151                    "description": "Name can be used to reference this request in a pod.spec.containers[].resources.claims entry and in a constraint of the claim.\n\nReferences using the name in the DeviceRequest will uniquely identify a request when the Exactly field is set. When the FirstAvailable field is set, a reference to the name of the DeviceRequest will match whatever subrequest is chosen by the scheduler.\n\nMust be a DNS label.",
    152                    "type": "string",
    153                },
    154            },
    155            "required": [
    156                "name",
    157            ],
    158        })
    159    }
    160}