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

    1// Generated from definition io.k8s.api.resource.v1beta2.ExactDeviceRequest
    2
    3/// ExactDeviceRequest is a request for one or more identical devices.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct ExactDeviceRequest {
    6    /// AdminAccess indicates that this is a claim for administrative access to the device(s). Claims with AdminAccess are expected to be used for monitoring or other management services for a device.  They ignore all ordinary claims to the device with respect to access modes and any resource allocations.
    7    ///
    8    /// This is an alpha field and requires enabling the DRAAdminAccess feature gate. Admin access is disabled if this field is unset or set to false, otherwise it is enabled.
    9    pub admin_access: Option<bool>,
    10
    11    /// AllocationMode and its related fields define how devices are allocated to satisfy this request. Supported values are:
    12    ///
    13    /// - ExactCount: This request is for a specific number of devices.
    14    ///   This is the default. The exact number is provided in the
    15    ///   count field.
    16    ///
    17    /// - All: This request is for all of the matching devices in a pool.
    18    ///   At least one device must exist on the node for the allocation to succeed.
    19    ///   Allocation will fail if some devices are already allocated,
    20    ///   unless adminAccess is requested.
    21    ///
    22    /// 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 requests must specify this field.
    23    ///
    24    /// More modes may get added in the future. Clients must refuse to handle requests with unknown modes.
    25    pub allocation_mode: Option<std::string::String>,
    26
    27    /// Capacity define resource requirements against each capacity.
    28    ///
    29    /// 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.
    30    ///
    31    /// 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.
    32    pub capacity: Option<crate::api::resource::v1beta2::CapacityRequirements>,
    33
    34    /// 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.
    35    pub count: Option<i64>,
    36
    37    /// DeviceClassName references a specific DeviceClass, which can define additional configuration and selectors to be inherited by this request.
    38    ///
    39    /// A DeviceClassName is required.
    40    ///
    41    /// 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.
    42    pub device_class_name: std::string::String,
    43
    44    /// Selectors define criteria which must be satisfied by a specific device in order for that device to be considered for this request. All selectors must be satisfied for a device to be considered.
    45    pub selectors: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSelector>>,
    46
    47    /// If specified, the request's tolerations.
    48    ///
    49    /// Tolerations for NoSchedule are required to allocate a device which has a taint with that effect. The same applies to NoExecute.
    50    ///
    51    /// 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.
    52    ///
    53    /// The maximum number of tolerations is 16.
    54    ///
    55    /// This is an alpha field and requires enabling the DRADeviceTaints feature gate.
    56    pub tolerations: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceToleration>>,
    57}
    58
    59impl crate::DeepMerge for ExactDeviceRequest {
    60    fn merge_from(&mut self, other: Self) {
    61        crate::DeepMerge::merge_from(&mut self.admin_access, other.admin_access);
    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::merge_strategies::list::atomic(&mut self.selectors, other.selectors);
    67        crate::merge_strategies::list::atomic(&mut self.tolerations, other.tolerations);
    68    }
    69}
    70
    71impl<'de> crate::serde::Deserialize<'de> for ExactDeviceRequest {
    72    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    73        #[allow(non_camel_case_types)]
    74        enum Field {
    75            Key_admin_access,
    76            Key_allocation_mode,
    77            Key_capacity,
    78            Key_count,
    79            Key_device_class_name,
    80            Key_selectors,
    81            Key_tolerations,
    82            Other,
    83        }
    84
    85        impl<'de> crate::serde::Deserialize<'de> for Field {
    86            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    87                struct Visitor;
    88
    89                impl crate::serde::de::Visitor<'_> for Visitor {
    90                    type Value = Field;
    91
    92                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    93                        f.write_str("field identifier")
    94                    }
    95
    96                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    97                        Ok(match v {
    98                            "adminAccess" => Field::Key_admin_access,
    99                            "allocationMode" => Field::Key_allocation_mode,
    100                            "capacity" => Field::Key_capacity,
    101                            "count" => Field::Key_count,
    102                            "deviceClassName" => Field::Key_device_class_name,
    103                            "selectors" => Field::Key_selectors,
    104                            "tolerations" => Field::Key_tolerations,
    105                            _ => Field::Other,
    106                        })
    107                    }
    108                }
    109
    110                deserializer.deserialize_identifier(Visitor)
    111            }
    112        }
    113
    114        struct Visitor;
    115
    116        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    117            type Value = ExactDeviceRequest;
    118
    119            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    120                f.write_str("ExactDeviceRequest")
    121            }
    122
    123            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    124                let mut value_admin_access: Option<bool> = None;
    125                let mut value_allocation_mode: Option<std::string::String> = None;
    126                let mut value_capacity: Option<crate::api::resource::v1beta2::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_selectors: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSelector>> = None;
    130                let mut value_tolerations: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceToleration>> = None;
    131
    132                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    133                    match key {
    134                        Field::Key_admin_access => value_admin_access = crate::serde::de::MapAccess::next_value(&mut map)?,
    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_selectors => value_selectors = crate::serde::de::MapAccess::next_value(&mut map)?,
    140                        Field::Key_tolerations => value_tolerations = crate::serde::de::MapAccess::next_value(&mut map)?,
    141                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    142                    }
    143                }
    144
    145                Ok(ExactDeviceRequest {
    146                    admin_access: value_admin_access,
    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                    selectors: value_selectors,
    152                    tolerations: value_tolerations,
    153                })
    154            }
    155        }
    156
    157        deserializer.deserialize_struct(
    158            "ExactDeviceRequest",
    159            &[
    160                "adminAccess",
    161                "allocationMode",
    162                "capacity",
    163                "count",
    164                "deviceClassName",
    165                "selectors",
    166                "tolerations",
    167            ],
    168            Visitor,
    169        )
    170    }
    171}
    172
    173impl crate::serde::Serialize for ExactDeviceRequest {
    174    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    175        let mut state = serializer.serialize_struct(
    176            "ExactDeviceRequest",
    177            1 +
    178            self.admin_access.as_ref().map_or(0, |_| 1) +
    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.admin_access {
    186            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "adminAccess", value)?;
    187        }
    188        if let Some(value) = &self.allocation_mode {
    189            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationMode", value)?;
    190        }
    191        if let Some(value) = &self.capacity {
    192            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "capacity", value)?;
    193        }
    194        if let Some(value) = &self.count {
    195            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "count", value)?;
    196        }
    197        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deviceClassName", &self.device_class_name)?;
    198        if let Some(value) = &self.selectors {
    199            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectors", value)?;
    200        }
    201        if let Some(value) = &self.tolerations {
    202            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tolerations", value)?;
    203        }
    204        crate::serde::ser::SerializeStruct::end(state)
    205    }
    206}
    207
    208#[cfg(feature = "schemars")]
    209impl crate::schemars::JsonSchema for ExactDeviceRequest {
    210    fn schema_name() -> std::borrow::Cow<'static, str> {
    211        "io.k8s.api.resource.v1beta2.ExactDeviceRequest".into()
    212    }
    213
    214    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    215        crate::schemars::json_schema!({
    216            "description": "ExactDeviceRequest is a request for one or more identical devices.",
    217            "type": "object",
    218            "properties": {
    219                "adminAccess": {
    220                    "description": "AdminAccess indicates that this is a claim for administrative access to the device(s). Claims with AdminAccess are expected to be used for monitoring or other management services for a device.  They ignore all ordinary claims to the device with respect to access modes and any resource allocations.\n\nThis is an alpha field and requires enabling the DRAAdminAccess feature gate. Admin access is disabled if this field is unset or set to false, otherwise it is enabled.",
    221                    "type": "boolean",
    222                },
    223                "allocationMode": {
    224                    "description": "AllocationMode and its related fields define how devices are allocated to satisfy this request. 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 request is for all of the matching devices in a pool.\n  At least one device must exist on the node for the allocation to succeed.\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 requests must specify this field.\n\nMore modes may get added in the future. Clients must refuse to handle requests with unknown modes.",
    225                    "type": "string",
    226                },
    227                "capacity": ({
    228                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta2::CapacityRequirements>();
    229                    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());
    230                    schema_obj
    231                }),
    232                "count": {
    233                    "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.",
    234                    "type": "integer",
    235                    "format": "int64",
    236                },
    237                "deviceClassName": {
    238                    "description": "DeviceClassName references a specific DeviceClass, which can define additional configuration and selectors to be inherited by this request.\n\nA DeviceClassName is required.\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.",
    239                    "type": "string",
    240                },
    241                "selectors": {
    242                    "description": "Selectors define criteria which must be satisfied by a specific device in order for that device to be considered for this request. All selectors must be satisfied for a device to be considered.",
    243                    "type": "array",
    244                    "items": (__gen.subschema_for::<crate::api::resource::v1beta2::DeviceSelector>()),
    245                },
    246                "tolerations": {
    247                    "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.",
    248                    "type": "array",
    249                    "items": (__gen.subschema_for::<crate::api::resource::v1beta2::DeviceToleration>()),
    250                },
    251            },
    252            "required": [
    253                "deviceClassName",
    254            ],
    255        })
    256    }
    257}