k8s_openapi/v1_34/api/autoscaling/v2/
metric_target.rs

1// Generated from definition io.k8s.api.autoscaling.v2.MetricTarget
2
3/// MetricTarget defines the target value, average value, or average utilization of a specific metric
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct MetricTarget {
6    /// averageUtilization is the target 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. Currently only valid for Resource metric source type
7    pub average_utilization: Option<i32>,
8
9    /// averageValue is the target 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    /// type represents whether the metric type is Utilization, Value, or AverageValue
13    pub type_: std::string::String,
14
15    /// value is the target value of the metric (as a quantity).
16    pub value: Option<crate::apimachinery::pkg::api::resource::Quantity>,
17}
18
19impl crate::DeepMerge for MetricTarget {
20    fn merge_from(&mut self, other: Self) {
21        crate::DeepMerge::merge_from(&mut self.average_utilization, other.average_utilization);
22        crate::DeepMerge::merge_from(&mut self.average_value, other.average_value);
23        crate::DeepMerge::merge_from(&mut self.type_, other.type_);
24        crate::DeepMerge::merge_from(&mut self.value, other.value);
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for MetricTarget {
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_average_utilization,
33            Key_average_value,
34            Key_type_,
35            Key_value,
36            Other,
37        }
38
39        impl<'de> crate::serde::Deserialize<'de> for Field {
40            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
41                struct Visitor;
42
43                impl crate::serde::de::Visitor<'_> for Visitor {
44                    type Value = Field;
45
46                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
47                        f.write_str("field identifier")
48                    }
49
50                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
51                        Ok(match v {
52                            "averageUtilization" => Field::Key_average_utilization,
53                            "averageValue" => Field::Key_average_value,
54                            "type" => Field::Key_type_,
55                            "value" => Field::Key_value,
56                            _ => Field::Other,
57                        })
58                    }
59                }
60
61                deserializer.deserialize_identifier(Visitor)
62            }
63        }
64
65        struct Visitor;
66
67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68            type Value = MetricTarget;
69
70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71                f.write_str("MetricTarget")
72            }
73
74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
75                let mut value_average_utilization: Option<i32> = None;
76                let mut value_average_value: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
77                let mut value_type_: Option<std::string::String> = None;
78                let mut value_value: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
79
80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81                    match key {
82                        Field::Key_average_utilization => value_average_utilization = crate::serde::de::MapAccess::next_value(&mut map)?,
83                        Field::Key_average_value => value_average_value = crate::serde::de::MapAccess::next_value(&mut map)?,
84                        Field::Key_type_ => value_type_ = crate::serde::de::MapAccess::next_value(&mut map)?,
85                        Field::Key_value => value_value = crate::serde::de::MapAccess::next_value(&mut map)?,
86                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
87                    }
88                }
89
90                Ok(MetricTarget {
91                    average_utilization: value_average_utilization,
92                    average_value: value_average_value,
93                    type_: value_type_.unwrap_or_default(),
94                    value: value_value,
95                })
96            }
97        }
98
99        deserializer.deserialize_struct(
100            "MetricTarget",
101            &[
102                "averageUtilization",
103                "averageValue",
104                "type",
105                "value",
106            ],
107            Visitor,
108        )
109    }
110}
111
112impl crate::serde::Serialize for MetricTarget {
113    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
114        let mut state = serializer.serialize_struct(
115            "MetricTarget",
116            1 +
117            self.average_utilization.as_ref().map_or(0, |_| 1) +
118            self.average_value.as_ref().map_or(0, |_| 1) +
119            self.value.as_ref().map_or(0, |_| 1),
120        )?;
121        if let Some(value) = &self.average_utilization {
122            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "averageUtilization", value)?;
123        }
124        if let Some(value) = &self.average_value {
125            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "averageValue", value)?;
126        }
127        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "type", &self.type_)?;
128        if let Some(value) = &self.value {
129            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "value", value)?;
130        }
131        crate::serde::ser::SerializeStruct::end(state)
132    }
133}
134
135#[cfg(feature = "schemars")]
136impl crate::schemars::JsonSchema for MetricTarget {
137    fn schema_name() -> std::borrow::Cow<'static, str> {
138        "io.k8s.api.autoscaling.v2.MetricTarget".into()
139    }
140
141    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
142        crate::schemars::json_schema!({
143            "description": "MetricTarget defines the target value, average value, or average utilization of a specific metric",
144            "type": "object",
145            "properties": {
146                "averageUtilization": {
147                    "description": "averageUtilization is the target 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. Currently only valid for Resource metric source type",
148                    "type": "integer",
149                    "format": "int32",
150                },
151                "averageValue": ({
152                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
153                    schema_obj.ensure_object().insert("description".into(), "averageValue is the target value of the average of the metric across all relevant pods (as a quantity)".into());
154                    schema_obj
155                }),
156                "type": {
157                    "description": "type represents whether the metric type is Utilization, Value, or AverageValue",
158                    "type": "string",
159                },
160                "value": ({
161                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
162                    schema_obj.ensure_object().insert("description".into(), "value is the target value of the metric (as a quantity).".into());
163                    schema_obj
164                }),
165            },
166            "required": [
167                "type",
168            ],
169        })
170    }
171}