k8s_openapi/v1_32/api/autoscaling/v2/
metric_status.rs

1// Generated from definition io.k8s.api.autoscaling.v2.MetricStatus
2
3/// MetricStatus describes the last-read state of a single metric.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct MetricStatus {
6    /// container resource refers to a resource metric (such as those specified in requests and limits) known to Kubernetes describing a single container in each pod in the current scale target (e.g. CPU or memory). Such metrics are built in to Kubernetes, and have special scaling options on top of those available to normal per-pod metrics using the "pods" source.
7    pub container_resource: Option<crate::api::autoscaling::v2::ContainerResourceMetricStatus>,
8
9    /// external refers to a global metric that is not associated with any Kubernetes object. It allows autoscaling based on information coming from components running outside of cluster (for example length of queue in cloud messaging service, or QPS from loadbalancer running outside of cluster).
10    pub external: Option<crate::api::autoscaling::v2::ExternalMetricStatus>,
11
12    /// object refers to a metric describing a single kubernetes object (for example, hits-per-second on an Ingress object).
13    pub object: Option<crate::api::autoscaling::v2::ObjectMetricStatus>,
14
15    /// pods refers to a metric describing each pod in the current scale target (for example, transactions-processed-per-second).  The values will be averaged together before being compared to the target value.
16    pub pods: Option<crate::api::autoscaling::v2::PodsMetricStatus>,
17
18    /// resource refers to a resource metric (such as those specified in requests and limits) known to Kubernetes describing each pod in the current scale target (e.g. CPU or memory). Such metrics are built in to Kubernetes, and have special scaling options on top of those available to normal per-pod metrics using the "pods" source.
19    pub resource: Option<crate::api::autoscaling::v2::ResourceMetricStatus>,
20
21    /// type is the type of metric source.  It will be one of "ContainerResource", "External", "Object", "Pods" or "Resource", each corresponds to a matching field in the object.
22    pub type_: String,
23}
24
25impl crate::DeepMerge for MetricStatus {
26    fn merge_from(&mut self, other: Self) {
27        crate::DeepMerge::merge_from(&mut self.container_resource, other.container_resource);
28        crate::DeepMerge::merge_from(&mut self.external, other.external);
29        crate::DeepMerge::merge_from(&mut self.object, other.object);
30        crate::DeepMerge::merge_from(&mut self.pods, other.pods);
31        crate::DeepMerge::merge_from(&mut self.resource, other.resource);
32        crate::DeepMerge::merge_from(&mut self.type_, other.type_);
33    }
34}
35
36impl<'de> crate::serde::Deserialize<'de> for MetricStatus {
37    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38        #[allow(non_camel_case_types)]
39        enum Field {
40            Key_container_resource,
41            Key_external,
42            Key_object,
43            Key_pods,
44            Key_resource,
45            Key_type_,
46            Other,
47        }
48
49        impl<'de> crate::serde::Deserialize<'de> for Field {
50            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
51                struct Visitor;
52
53                impl crate::serde::de::Visitor<'_> for Visitor {
54                    type Value = Field;
55
56                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57                        f.write_str("field identifier")
58                    }
59
60                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
61                        Ok(match v {
62                            "containerResource" => Field::Key_container_resource,
63                            "external" => Field::Key_external,
64                            "object" => Field::Key_object,
65                            "pods" => Field::Key_pods,
66                            "resource" => Field::Key_resource,
67                            "type" => Field::Key_type_,
68                            _ => Field::Other,
69                        })
70                    }
71                }
72
73                deserializer.deserialize_identifier(Visitor)
74            }
75        }
76
77        struct Visitor;
78
79        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
80            type Value = MetricStatus;
81
82            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83                f.write_str("MetricStatus")
84            }
85
86            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
87                let mut value_container_resource: Option<crate::api::autoscaling::v2::ContainerResourceMetricStatus> = None;
88                let mut value_external: Option<crate::api::autoscaling::v2::ExternalMetricStatus> = None;
89                let mut value_object: Option<crate::api::autoscaling::v2::ObjectMetricStatus> = None;
90                let mut value_pods: Option<crate::api::autoscaling::v2::PodsMetricStatus> = None;
91                let mut value_resource: Option<crate::api::autoscaling::v2::ResourceMetricStatus> = None;
92                let mut value_type_: Option<String> = None;
93
94                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
95                    match key {
96                        Field::Key_container_resource => value_container_resource = crate::serde::de::MapAccess::next_value(&mut map)?,
97                        Field::Key_external => value_external = crate::serde::de::MapAccess::next_value(&mut map)?,
98                        Field::Key_object => value_object = crate::serde::de::MapAccess::next_value(&mut map)?,
99                        Field::Key_pods => value_pods = crate::serde::de::MapAccess::next_value(&mut map)?,
100                        Field::Key_resource => value_resource = crate::serde::de::MapAccess::next_value(&mut map)?,
101                        Field::Key_type_ => value_type_ = crate::serde::de::MapAccess::next_value(&mut map)?,
102                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
103                    }
104                }
105
106                Ok(MetricStatus {
107                    container_resource: value_container_resource,
108                    external: value_external,
109                    object: value_object,
110                    pods: value_pods,
111                    resource: value_resource,
112                    type_: value_type_.unwrap_or_default(),
113                })
114            }
115        }
116
117        deserializer.deserialize_struct(
118            "MetricStatus",
119            &[
120                "containerResource",
121                "external",
122                "object",
123                "pods",
124                "resource",
125                "type",
126            ],
127            Visitor,
128        )
129    }
130}
131
132impl crate::serde::Serialize for MetricStatus {
133    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
134        let mut state = serializer.serialize_struct(
135            "MetricStatus",
136            1 +
137            self.container_resource.as_ref().map_or(0, |_| 1) +
138            self.external.as_ref().map_or(0, |_| 1) +
139            self.object.as_ref().map_or(0, |_| 1) +
140            self.pods.as_ref().map_or(0, |_| 1) +
141            self.resource.as_ref().map_or(0, |_| 1),
142        )?;
143        if let Some(value) = &self.container_resource {
144            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "containerResource", value)?;
145        }
146        if let Some(value) = &self.external {
147            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "external", value)?;
148        }
149        if let Some(value) = &self.object {
150            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "object", value)?;
151        }
152        if let Some(value) = &self.pods {
153            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "pods", value)?;
154        }
155        if let Some(value) = &self.resource {
156            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resource", value)?;
157        }
158        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "type", &self.type_)?;
159        crate::serde::ser::SerializeStruct::end(state)
160    }
161}
162
163#[cfg(feature = "schemars")]
164impl crate::schemars::JsonSchema for MetricStatus {
165    fn schema_name() -> String {
166        "io.k8s.api.autoscaling.v2.MetricStatus".to_owned()
167    }
168
169    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
170        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
171            metadata: Some(Box::new(crate::schemars::schema::Metadata {
172                description: Some("MetricStatus describes the last-read state of a single metric.".to_owned()),
173                ..Default::default()
174            })),
175            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
176            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
177                properties: [
178                    (
179                        "containerResource".to_owned(),
180                        {
181                            let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::ContainerResourceMetricStatus>().into_object();
182                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
183                                description: Some("container resource refers to a resource metric (such as those specified in requests and limits) known to Kubernetes describing a single container in each pod in the current scale target (e.g. CPU or memory). Such metrics are built in to Kubernetes, and have special scaling options on top of those available to normal per-pod metrics using the \"pods\" source.".to_owned()),
184                                ..Default::default()
185                            }));
186                            crate::schemars::schema::Schema::Object(schema_obj)
187                        },
188                    ),
189                    (
190                        "external".to_owned(),
191                        {
192                            let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::ExternalMetricStatus>().into_object();
193                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
194                                description: Some("external refers to a global metric that is not associated with any Kubernetes object. It allows autoscaling based on information coming from components running outside of cluster (for example length of queue in cloud messaging service, or QPS from loadbalancer running outside of cluster).".to_owned()),
195                                ..Default::default()
196                            }));
197                            crate::schemars::schema::Schema::Object(schema_obj)
198                        },
199                    ),
200                    (
201                        "object".to_owned(),
202                        {
203                            let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::ObjectMetricStatus>().into_object();
204                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
205                                description: Some("object refers to a metric describing a single kubernetes object (for example, hits-per-second on an Ingress object).".to_owned()),
206                                ..Default::default()
207                            }));
208                            crate::schemars::schema::Schema::Object(schema_obj)
209                        },
210                    ),
211                    (
212                        "pods".to_owned(),
213                        {
214                            let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::PodsMetricStatus>().into_object();
215                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
216                                description: Some("pods refers to a metric describing each pod in the current scale target (for example, transactions-processed-per-second).  The values will be averaged together before being compared to the target value.".to_owned()),
217                                ..Default::default()
218                            }));
219                            crate::schemars::schema::Schema::Object(schema_obj)
220                        },
221                    ),
222                    (
223                        "resource".to_owned(),
224                        {
225                            let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::ResourceMetricStatus>().into_object();
226                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
227                                description: Some("resource refers to a resource metric (such as those specified in requests and limits) known to Kubernetes describing each pod in the current scale target (e.g. CPU or memory). Such metrics are built in to Kubernetes, and have special scaling options on top of those available to normal per-pod metrics using the \"pods\" source.".to_owned()),
228                                ..Default::default()
229                            }));
230                            crate::schemars::schema::Schema::Object(schema_obj)
231                        },
232                    ),
233                    (
234                        "type".to_owned(),
235                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
236                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
237                                description: Some("type is the type of metric source.  It will be one of \"ContainerResource\", \"External\", \"Object\", \"Pods\" or \"Resource\", each corresponds to a matching field in the object.".to_owned()),
238                                ..Default::default()
239                            })),
240                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
241                            ..Default::default()
242                        }),
243                    ),
244                ].into(),
245                required: [
246                    "type".to_owned(),
247                ].into(),
248                ..Default::default()
249            })),
250            ..Default::default()
251        })
252    }
253}