#
k8s_openapi/v1_35/api/autoscaling/v2/
metric_value_status.rs

    1// Generated from definition io.k8s.api.autoscaling.v2.MetricValueStatus
    2
    3/// MetricValueStatus holds the current value for a metric
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct MetricValueStatus {
    6    /// currentAverageUtilization is the current value of the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods.
    7    pub average_utilization: Option<i32>,
    8
    9    /// averageValue is the current value of the average of the metric across all relevant pods (as a quantity)
    10    pub average_value: Option<crate::apimachinery::pkg::api::resource::Quantity>,
    11
    12    /// value is the current value of the metric (as a quantity).
    13    pub value: Option<crate::apimachinery::pkg::api::resource::Quantity>,
    14}
    15
    16impl crate::DeepMerge for MetricValueStatus {
    17    fn merge_from(&mut self, other: Self) {
    18        crate::DeepMerge::merge_from(&mut self.average_utilization, other.average_utilization);
    19        crate::DeepMerge::merge_from(&mut self.average_value, other.average_value);
    20        crate::DeepMerge::merge_from(&mut self.value, other.value);
    21    }
    22}
    23
    24impl<'de> crate::serde::Deserialize<'de> for MetricValueStatus {
    25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    26        #[allow(non_camel_case_types)]
    27        enum Field {
    28            Key_average_utilization,
    29            Key_average_value,
    30            Key_value,
    31            Other,
    32        }
    33
    34        impl<'de> crate::serde::Deserialize<'de> for Field {
    35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    36                struct Visitor;
    37
    38                impl crate::serde::de::Visitor<'_> for Visitor {
    39                    type Value = Field;
    40
    41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    42                        f.write_str("field identifier")
    43                    }
    44
    45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    46                        Ok(match v {
    47                            "averageUtilization" => Field::Key_average_utilization,
    48                            "averageValue" => Field::Key_average_value,
    49                            "value" => Field::Key_value,
    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 = MetricValueStatus;
    63
    64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    65                f.write_str("MetricValueStatus")
    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_average_utilization: Option<i32> = None;
    70                let mut value_average_value: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
    71                let mut value_value: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
    72
    73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    74                    match key {
    75                        Field::Key_average_utilization => value_average_utilization = crate::serde::de::MapAccess::next_value(&mut map)?,
    76                        Field::Key_average_value => value_average_value = crate::serde::de::MapAccess::next_value(&mut map)?,
    77                        Field::Key_value => value_value = crate::serde::de::MapAccess::next_value(&mut map)?,
    78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    79                    }
    80                }
    81
    82                Ok(MetricValueStatus {
    83                    average_utilization: value_average_utilization,
    84                    average_value: value_average_value,
    85                    value: value_value,
    86                })
    87            }
    88        }
    89
    90        deserializer.deserialize_struct(
    91            "MetricValueStatus",
    92            &[
    93                "averageUtilization",
    94                "averageValue",
    95                "value",
    96            ],
    97            Visitor,
    98        )
    99    }
    100}
    101
    102impl crate::serde::Serialize for MetricValueStatus {
    103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    104        let mut state = serializer.serialize_struct(
    105            "MetricValueStatus",
    106            self.average_utilization.as_ref().map_or(0, |_| 1) +
    107            self.average_value.as_ref().map_or(0, |_| 1) +
    108            self.value.as_ref().map_or(0, |_| 1),
    109        )?;
    110        if let Some(value) = &self.average_utilization {
    111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "averageUtilization", value)?;
    112        }
    113        if let Some(value) = &self.average_value {
    114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "averageValue", value)?;
    115        }
    116        if let Some(value) = &self.value {
    117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "value", value)?;
    118        }
    119        crate::serde::ser::SerializeStruct::end(state)
    120    }
    121}
    122
    123#[cfg(feature = "schemars")]
    124impl crate::schemars::JsonSchema for MetricValueStatus {
    125    fn schema_name() -> std::borrow::Cow<'static, str> {
    126        "io.k8s.api.autoscaling.v2.MetricValueStatus".into()
    127    }
    128
    129    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    130        crate::schemars::json_schema!({
    131            "description": "MetricValueStatus holds the current value for a metric",
    132            "type": "object",
    133            "properties": {
    134                "averageUtilization": {
    135                    "description": "currentAverageUtilization is the current value of the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods.",
    136                    "type": "integer",
    137                    "format": "int32",
    138                },
    139                "averageValue": ({
    140                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
    141                    schema_obj.ensure_object().insert("description".into(), "averageValue is the current value of the average of the metric across all relevant pods (as a quantity)".into());
    142                    schema_obj
    143                }),
    144                "value": ({
    145                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
    146                    schema_obj.ensure_object().insert("description".into(), "value is the current value of the metric (as a quantity).".into());
    147                    schema_obj
    148                }),
    149            },
    150        })
    151    }
    152}