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

    1// Generated from definition io.k8s.api.resource.v1beta1.OpaqueDeviceConfiguration
    2
    3/// OpaqueDeviceConfiguration contains configuration parameters for a driver in a format defined by the driver vendor.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct OpaqueDeviceConfiguration {
    6    /// Driver is used to determine which kubelet plugin needs to be passed these configuration parameters.
    7    ///
    8    /// An admission policy provided by the driver developer could use this to decide whether it needs to validate them.
    9    ///
    10    /// Must be a DNS subdomain and should end with a DNS domain owned by the vendor of the driver. It should use only lower case characters.
    11    pub driver: std::string::String,
    12
    13    /// Parameters can contain arbitrary data. It is the responsibility of the driver developer to handle validation and versioning. Typically this includes self-identification and a version ("kind" + "apiVersion" for Kubernetes types), with conversion between different versions.
    14    ///
    15    /// The length of the raw data must be smaller or equal to 10 Ki.
    16    pub parameters: crate::apimachinery::pkg::runtime::RawExtension,
    17}
    18
    19impl crate::DeepMerge for OpaqueDeviceConfiguration {
    20    fn merge_from(&mut self, other: Self) {
    21        crate::DeepMerge::merge_from(&mut self.driver, other.driver);
    22        crate::DeepMerge::merge_from(&mut self.parameters, other.parameters);
    23    }
    24}
    25
    26impl<'de> crate::serde::Deserialize<'de> for OpaqueDeviceConfiguration {
    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_driver,
    31            Key_parameters,
    32            Other,
    33        }
    34
    35        impl<'de> crate::serde::Deserialize<'de> for Field {
    36            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    37                struct Visitor;
    38
    39                impl crate::serde::de::Visitor<'_> for Visitor {
    40                    type Value = Field;
    41
    42                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    43                        f.write_str("field identifier")
    44                    }
    45
    46                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    47                        Ok(match v {
    48                            "driver" => Field::Key_driver,
    49                            "parameters" => Field::Key_parameters,
    50                            _ => Field::Other,
    51                        })
    52                    }
    53                }
    54
    55                deserializer.deserialize_identifier(Visitor)
    56            }
    57        }
    58
    59        struct Visitor;
    60
    61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    62            type Value = OpaqueDeviceConfiguration;
    63
    64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    65                f.write_str("OpaqueDeviceConfiguration")
    66            }
    67
    68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    69                let mut value_driver: Option<std::string::String> = None;
    70                let mut value_parameters: Option<crate::apimachinery::pkg::runtime::RawExtension> = None;
    71
    72                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    73                    match key {
    74                        Field::Key_driver => value_driver = crate::serde::de::MapAccess::next_value(&mut map)?,
    75                        Field::Key_parameters => value_parameters = crate::serde::de::MapAccess::next_value(&mut map)?,
    76                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    77                    }
    78                }
    79
    80                Ok(OpaqueDeviceConfiguration {
    81                    driver: value_driver.unwrap_or_default(),
    82                    parameters: value_parameters.unwrap_or_default(),
    83                })
    84            }
    85        }
    86
    87        deserializer.deserialize_struct(
    88            "OpaqueDeviceConfiguration",
    89            &[
    90                "driver",
    91                "parameters",
    92            ],
    93            Visitor,
    94        )
    95    }
    96}
    97
    98impl crate::serde::Serialize for OpaqueDeviceConfiguration {
    99    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    100        let mut state = serializer.serialize_struct(
    101            "OpaqueDeviceConfiguration",
    102            2,
    103        )?;
    104        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "driver", &self.driver)?;
    105        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "parameters", &self.parameters)?;
    106        crate::serde::ser::SerializeStruct::end(state)
    107    }
    108}
    109
    110#[cfg(feature = "schemars")]
    111impl crate::schemars::JsonSchema for OpaqueDeviceConfiguration {
    112    fn schema_name() -> std::borrow::Cow<'static, str> {
    113        "io.k8s.api.resource.v1beta1.OpaqueDeviceConfiguration".into()
    114    }
    115
    116    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    117        crate::schemars::json_schema!({
    118            "description": "OpaqueDeviceConfiguration contains configuration parameters for a driver in a format defined by the driver vendor.",
    119            "type": "object",
    120            "properties": {
    121                "driver": {
    122                    "description": "Driver is used to determine which kubelet plugin needs to be passed these configuration parameters.\n\nAn admission policy provided by the driver developer could use this to decide whether it needs to validate them.\n\nMust be a DNS subdomain and should end with a DNS domain owned by the vendor of the driver. It should use only lower case characters.",
    123                    "type": "string",
    124                },
    125                "parameters": ({
    126                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::runtime::RawExtension>();
    127                    schema_obj.ensure_object().insert("description".into(), "Parameters can contain arbitrary data. It is the responsibility of the driver developer to handle validation and versioning. Typically this includes self-identification and a version (\"kind\" + \"apiVersion\" for Kubernetes types), with conversion between different versions.\n\nThe length of the raw data must be smaller or equal to 10 Ki.".into());
    128                    schema_obj
    129                }),
    130            },
    131            "required": [
    132                "driver",
    133                "parameters",
    134            ],
    135        })
    136    }
    137}