#
k8s_openapi/v1_35/api/resource/v1alpha3/
device_taint_selector.rs

    1// Generated from definition io.k8s.api.resource.v1alpha3.DeviceTaintSelector
    2
    3/// DeviceTaintSelector defines which device(s) a DeviceTaintRule applies to. The empty selector matches all devices. Without a selector, no devices are matched.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct DeviceTaintSelector {
    6    /// If device is set, only devices with that name are selected. This field corresponds to slice.spec.devices\[\].name.
    7    ///
    8    /// Setting also driver and pool may be required to avoid ambiguity, but is not required.
    9    pub device: Option<std::string::String>,
    10
    11    /// If driver is set, only devices from that driver are selected. This fields corresponds to slice.spec.driver.
    12    pub driver: Option<std::string::String>,
    13
    14    /// If pool is set, only devices in that pool are selected.
    15    ///
    16    /// Also setting the driver name may be useful to avoid ambiguity when different drivers use the same pool name, but this is not required because selecting pools from different drivers may also be useful, for example when drivers with node-local devices use the node name as their pool name.
    17    pub pool: Option<std::string::String>,
    18}
    19
    20impl crate::DeepMerge for DeviceTaintSelector {
    21    fn merge_from(&mut self, other: Self) {
    22        crate::DeepMerge::merge_from(&mut self.device, other.device);
    23        crate::DeepMerge::merge_from(&mut self.driver, other.driver);
    24        crate::DeepMerge::merge_from(&mut self.pool, other.pool);
    25    }
    26}
    27
    28impl<'de> crate::serde::Deserialize<'de> for DeviceTaintSelector {
    29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    30        #[allow(non_camel_case_types)]
    31        enum Field {
    32            Key_device,
    33            Key_driver,
    34            Key_pool,
    35            Other,
    36        }
    37
    38        impl<'de> crate::serde::Deserialize<'de> for Field {
    39            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    40                struct Visitor;
    41
    42                impl crate::serde::de::Visitor<'_> for Visitor {
    43                    type Value = Field;
    44
    45                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    46                        f.write_str("field identifier")
    47                    }
    48
    49                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    50                        Ok(match v {
    51                            "device" => Field::Key_device,
    52                            "driver" => Field::Key_driver,
    53                            "pool" => Field::Key_pool,
    54                            _ => Field::Other,
    55                        })
    56                    }
    57                }
    58
    59                deserializer.deserialize_identifier(Visitor)
    60            }
    61        }
    62
    63        struct Visitor;
    64
    65        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    66            type Value = DeviceTaintSelector;
    67
    68            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    69                f.write_str("DeviceTaintSelector")
    70            }
    71
    72            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    73                let mut value_device: Option<std::string::String> = None;
    74                let mut value_driver: Option<std::string::String> = None;
    75                let mut value_pool: Option<std::string::String> = None;
    76
    77                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    78                    match key {
    79                        Field::Key_device => value_device = crate::serde::de::MapAccess::next_value(&mut map)?,
    80                        Field::Key_driver => value_driver = crate::serde::de::MapAccess::next_value(&mut map)?,
    81                        Field::Key_pool => value_pool = crate::serde::de::MapAccess::next_value(&mut map)?,
    82                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    83                    }
    84                }
    85
    86                Ok(DeviceTaintSelector {
    87                    device: value_device,
    88                    driver: value_driver,
    89                    pool: value_pool,
    90                })
    91            }
    92        }
    93
    94        deserializer.deserialize_struct(
    95            "DeviceTaintSelector",
    96            &[
    97                "device",
    98                "driver",
    99                "pool",
    100            ],
    101            Visitor,
    102        )
    103    }
    104}
    105
    106impl crate::serde::Serialize for DeviceTaintSelector {
    107    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    108        let mut state = serializer.serialize_struct(
    109            "DeviceTaintSelector",
    110            self.device.as_ref().map_or(0, |_| 1) +
    111            self.driver.as_ref().map_or(0, |_| 1) +
    112            self.pool.as_ref().map_or(0, |_| 1),
    113        )?;
    114        if let Some(value) = &self.device {
    115            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "device", value)?;
    116        }
    117        if let Some(value) = &self.driver {
    118            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "driver", value)?;
    119        }
    120        if let Some(value) = &self.pool {
    121            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "pool", value)?;
    122        }
    123        crate::serde::ser::SerializeStruct::end(state)
    124    }
    125}
    126
    127#[cfg(feature = "schemars")]
    128impl crate::schemars::JsonSchema for DeviceTaintSelector {
    129    fn schema_name() -> std::borrow::Cow<'static, str> {
    130        "io.k8s.api.resource.v1alpha3.DeviceTaintSelector".into()
    131    }
    132
    133    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    134        crate::schemars::json_schema!({
    135            "description": "DeviceTaintSelector defines which device(s) a DeviceTaintRule applies to. The empty selector matches all devices. Without a selector, no devices are matched.",
    136            "type": "object",
    137            "properties": {
    138                "device": {
    139                    "description": "If device is set, only devices with that name are selected. This field corresponds to slice.spec.devices[].name.\n\nSetting also driver and pool may be required to avoid ambiguity, but is not required.",
    140                    "type": "string",
    141                },
    142                "driver": {
    143                    "description": "If driver is set, only devices from that driver are selected. This fields corresponds to slice.spec.driver.",
    144                    "type": "string",
    145                },
    146                "pool": {
    147                    "description": "If pool is set, only devices in that pool are selected.\n\nAlso setting the driver name may be useful to avoid ambiguity when different drivers use the same pool name, but this is not required because selecting pools from different drivers may also be useful, for example when drivers with node-local devices use the node name as their pool name.",
    148                    "type": "string",
    149                },
    150            },
    151        })
    152    }
    153}