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

    1// Generated from definition io.k8s.api.resource.v1beta1.DeviceSubRequest
    2
    3/// DeviceSubRequest describes a request for device provided in the claim.spec.devices.requests\[\].firstAvailable array. Each is typically a request for a single resource like a device, but can also ask for several identical devices.
    4///
    5/// DeviceSubRequest is similar to Request, but doesn't expose the AdminAccess or FirstAvailable fields, as those can only be set on the top-level request. AdminAccess is not supported for requests with a prioritized list, and recursive FirstAvailable fields are not supported.
    6#[derive(Clone, Debug, Default, PartialEq)]
    7pub struct DeviceSubRequest {
    8    /// AllocationMode and its related fields define how devices are allocated to satisfy this subrequest. Supported values are:
    9    ///
    10    /// - ExactCount: This request is for a specific number of devices.
    11    ///   This is the default. The exact number is provided in the
    12    ///   count field.
    13    ///
    14    /// - All: This subrequest is for all of the matching devices in a pool.
    15    ///   Allocation will fail if some devices are already allocated,
    16    ///   unless adminAccess is requested.
    17    ///
    18    /// If AllocationMode is not specified, the default mode is ExactCount. If the mode is ExactCount and count is not specified, the default count is one. Any other subrequests must specify this field.
    19    ///
    20    /// More modes may get added in the future. Clients must refuse to handle requests with unknown modes.
    21    pub allocation_mode: Option<std::string::String>,
    22
    23    /// Capacity define resource requirements against each capacity.
    24    ///
    25    /// If this field is unset and the device supports multiple allocations, the default value will be applied to each capacity according to requestPolicy. For the capacity that has no requestPolicy, default is the full capacity value.
    26    ///
    27    /// Applies to each device allocation. If Count \> 1, the request fails if there aren't enough devices that meet the requirements. If AllocationMode is set to All, the request fails if there are devices that otherwise match the request, and have this capacity, with a value \>= the requested amount, but which cannot be allocated to this request.
    28    pub capacity: Option<crate::api::resource::v1beta1::CapacityRequirements>,
    29
    30    /// Count is used only when the count mode is "ExactCount". Must be greater than zero. If AllocationMode is ExactCount and this field is not specified, the default is one.
    31    pub count: Option<i64>,
    32
    33    /// DeviceClassName references a specific DeviceClass, which can define additional configuration and selectors to be inherited by this subrequest.
    34    ///
    35    /// A class is required. Which classes are available depends on the cluster.
    36    ///
    37    /// Administrators may use this to restrict which devices may get requested by only installing classes with selectors for permitted devices. If users are free to request anything without restrictions, then administrators can create an empty DeviceClass for users to reference.
    38    pub device_class_name: std::string::String,
    39
    40    /// Name can be used to reference this subrequest in the list of constraints or the list of configurations for the claim. References must use the format \<main request\>/\<subrequest\>.
    41    ///
    42    /// Must be a DNS label.
    43    pub name: std::string::String,
    44
    45    /// Selectors define criteria which must be satisfied by a specific device in order for that device to be considered for this subrequest. All selectors must be satisfied for a device to be considered.
    46    pub selectors: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSelector>>,
    47
    48    /// If specified, the request's tolerations.
    49    ///
    50    /// Tolerations for NoSchedule are required to allocate a device which has a taint with that effect. The same applies to NoExecute.
    51    ///
    52    /// In addition, should any of the allocated devices get tainted with NoExecute after allocation and that effect is not tolerated, then all pods consuming the ResourceClaim get deleted to evict them. The scheduler will not let new pods reserve the claim while it has these tainted devices. Once all pods are evicted, the claim will get deallocated.
    53    ///
    54    /// The maximum number of tolerations is 16.
    55    ///
    56    /// This is an alpha field and requires enabling the DRADeviceTaints feature gate.
    57    pub tolerations: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceToleration>>,
    58}
    59
    60impl crate::DeepMerge for DeviceSubRequest {
    61    fn merge_from(&mut self, other: Self) {
    62        crate::DeepMerge::merge_from(&mut self.allocation_mode, other.allocation_mode);
    63        crate::DeepMerge::merge_from(&mut self.capacity, other.capacity);
    64        crate::DeepMerge::merge_from(&mut self.count, other.count);
    65        crate::DeepMerge::merge_from(&mut self.device_class_name, other.device_class_name);
    66        crate::DeepMerge::merge_from(&mut self.name, other.name);
    67        crate::merge_strategies::list::atomic(&mut self.selectors, other.selectors);
    68        crate::merge_strategies::list::atomic(&mut self.tolerations, other.tolerations);
    69    }
    70}
    71
    72impl<'de> crate::serde::Deserialize<'de> for DeviceSubRequest {
    73    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    74        #[allow(non_camel_case_types)]
    75        enum Field {
    76            Key_allocation_mode,
    77            Key_capacity,
    78            Key_count,
    79            Key_device_class_name,
    80            Key_name,
    81            Key_selectors,
    82            Key_tolerations,
    83            Other,
    84        }
    85
    86        impl<'de> crate::serde::Deserialize<'de> for Field {
    87            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    88                struct Visitor;
    89
    90                impl crate::serde::de::Visitor<'_> for Visitor {
    91                    type Value = Field;
    92
    93                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    94                        f.write_str("field identifier")
    95                    }
    96
    97                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    98                        Ok(match v {
    99                            "allocationMode" => Field::Key_allocation_mode,
    100                            "capacity" => Field::Key_capacity,
    101                            "count" => Field::Key_count,
    102                            "deviceClassName" => Field::Key_device_class_name,
    103                            "name" => Field::Key_name,
    104                            "selectors" => Field::Key_selectors,
    105                            "tolerations" => Field::Key_tolerations,
    106                            _ => Field::Other,
    107                        })
    108                    }
    109                }
    110
    111                deserializer.deserialize_identifier(Visitor)
    112            }
    113        }
    114
    115        struct Visitor;
    116
    117        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    118            type Value = DeviceSubRequest;
    119
    120            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    121                f.write_str("DeviceSubRequest")
    122            }
    123
    124            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    125                let mut value_allocation_mode: Option<std::string::String> = None;
    126                let mut value_capacity: Option<crate::api::resource::v1beta1::CapacityRequirements> = None;
    127                let mut value_count: Option<i64> = None;
    128                let mut value_device_class_name: Option<std::string::String> = None;
    129                let mut value_name: Option<std::string::String> = None;
    130                let mut value_selectors: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSelector>> = None;
    131                let mut value_tolerations: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceToleration>> = None;
    132
    133                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    134                    match key {
    135                        Field::Key_allocation_mode => value_allocation_mode = crate::serde::de::MapAccess::next_value(&mut map)?,
    136                        Field::Key_capacity => value_capacity = crate::serde::de::MapAccess::next_value(&mut map)?,
    137                        Field::Key_count => value_count = crate::serde::de::MapAccess::next_value(&mut map)?,
    138                        Field::Key_device_class_name => value_device_class_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    139                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    140                        Field::Key_selectors => value_selectors = crate::serde::de::MapAccess::next_value(&mut map)?,
    141                        Field::Key_tolerations => value_tolerations = crate::serde::de::MapAccess::next_value(&mut map)?,
    142                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    143                    }
    144                }
    145
    146                Ok(DeviceSubRequest {
    147                    allocation_mode: value_allocation_mode,
    148                    capacity: value_capacity,
    149                    count: value_count,
    150                    device_class_name: value_device_class_name.unwrap_or_default(),
    151                    name: value_name.unwrap_or_default(),
    152                    selectors: value_selectors,
    153                    tolerations: value_tolerations,
    154                })
    155            }
    156        }
    157
    158        deserializer.deserialize_struct(
    159            "DeviceSubRequest",
    160            &[
    161                "allocationMode",
    162                "capacity",
    163                "count",
    164                "deviceClassName",
    165                "name",
    166                "selectors",
    167                "tolerations",
    168            ],
    169            Visitor,
    170        )
    171    }
    172}
    173
    174impl crate::serde::Serialize for DeviceSubRequest {
    175    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    176        let mut state = serializer.serialize_struct(
    177            "DeviceSubRequest",
    178            2 +
    179            self.allocation_mode.as_ref().map_or(0, |_| 1) +
    180            self.capacity.as_ref().map_or(0, |_| 1) +
    181            self.count.as_ref().map_or(0, |_| 1) +
    182            self.selectors.as_ref().map_or(0, |_| 1) +
    183            self.tolerations.as_ref().map_or(0, |_| 1),
    184        )?;
    185        if let Some(value) = &self.allocation_mode {
    186            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationMode", value)?;
    187        }
    188        if let Some(value) = &self.capacity {
    189            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "capacity", value)?;
    190        }
    191        if let Some(value) = &self.count {
    192            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "count", value)?;
    193        }
    194        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deviceClassName", &self.device_class_name)?;
    195        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
    196        if let Some(value) = &self.selectors {
    197            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectors", value)?;
    198        }
    199        if let Some(value) = &self.tolerations {
    200            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tolerations", value)?;
    201        }
    202        crate::serde::ser::SerializeStruct::end(state)
    203    }
    204}
    205
    206#[cfg(feature = "schemars")]
    207impl crate::schemars::JsonSchema for DeviceSubRequest {
    208    fn schema_name() -> std::borrow::Cow<'static, str> {
    209        "io.k8s.api.resource.v1beta1.DeviceSubRequest".into()
    210    }
    211
    212    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    213        crate::schemars::json_schema!({
    214            "description": "DeviceSubRequest describes a request for device provided in the claim.spec.devices.requests[].firstAvailable array. Each is typically a request for a single resource like a device, but can also ask for several identical devices.\n\nDeviceSubRequest is similar to Request, but doesn't expose the AdminAccess or FirstAvailable fields, as those can only be set on the top-level request. AdminAccess is not supported for requests with a prioritized list, and recursive FirstAvailable fields are not supported.",
    215            "type": "object",
    216            "properties": {
    217                "allocationMode": {
    218                    "description": "AllocationMode and its related fields define how devices are allocated to satisfy this subrequest. Supported values are:\n\n- ExactCount: This request is for a specific number of devices.\n  This is the default. The exact number is provided in the\n  count field.\n\n- All: This subrequest is for all of the matching devices in a pool.\n  Allocation will fail if some devices are already allocated,\n  unless adminAccess is requested.\n\nIf AllocationMode is not specified, the default mode is ExactCount. If the mode is ExactCount and count is not specified, the default count is one. Any other subrequests must specify this field.\n\nMore modes may get added in the future. Clients must refuse to handle requests with unknown modes.",
    219                    "type": "string",
    220                },
    221                "capacity": ({
    222                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::CapacityRequirements>();
    223                    schema_obj.ensure_object().insert("description".into(), "Capacity define resource requirements against each capacity.\n\nIf this field is unset and the device supports multiple allocations, the default value will be applied to each capacity according to requestPolicy. For the capacity that has no requestPolicy, default is the full capacity value.\n\nApplies to each device allocation. If Count > 1, the request fails if there aren't enough devices that meet the requirements. If AllocationMode is set to All, the request fails if there are devices that otherwise match the request, and have this capacity, with a value >= the requested amount, but which cannot be allocated to this request.".into());
    224                    schema_obj
    225                }),
    226                "count": {
    227                    "description": "Count is used only when the count mode is \"ExactCount\". Must be greater than zero. If AllocationMode is ExactCount and this field is not specified, the default is one.",
    228                    "type": "integer",
    229                    "format": "int64",
    230                },
    231                "deviceClassName": {
    232                    "description": "DeviceClassName references a specific DeviceClass, which can define additional configuration and selectors to be inherited by this subrequest.\n\nA class is required. Which classes are available depends on the cluster.\n\nAdministrators may use this to restrict which devices may get requested by only installing classes with selectors for permitted devices. If users are free to request anything without restrictions, then administrators can create an empty DeviceClass for users to reference.",
    233                    "type": "string",
    234                },
    235                "name": {
    236                    "description": "Name can be used to reference this subrequest in the list of constraints or the list of configurations for the claim. References must use the format <main request>/<subrequest>.\n\nMust be a DNS label.",
    237                    "type": "string",
    238                },
    239                "selectors": {
    240                    "description": "Selectors define criteria which must be satisfied by a specific device in order for that device to be considered for this subrequest. All selectors must be satisfied for a device to be considered.",
    241                    "type": "array",
    242                    "items": (__gen.subschema_for::<crate::api::resource::v1beta1::DeviceSelector>()),
    243                },
    244                "tolerations": {
    245                    "description": "If specified, the request's tolerations.\n\nTolerations for NoSchedule are required to allocate a device which has a taint with that effect. The same applies to NoExecute.\n\nIn addition, should any of the allocated devices get tainted with NoExecute after allocation and that effect is not tolerated, then all pods consuming the ResourceClaim get deleted to evict them. The scheduler will not let new pods reserve the claim while it has these tainted devices. Once all pods are evicted, the claim will get deallocated.\n\nThe maximum number of tolerations is 16.\n\nThis is an alpha field and requires enabling the DRADeviceTaints feature gate.",
    246                    "type": "array",
    247                    "items": (__gen.subschema_for::<crate::api::resource::v1beta1::DeviceToleration>()),
    248                },
    249            },
    250            "required": [
    251                "deviceClassName",
    252                "name",
    253            ],
    254        })
    255    }
    256}