k8s_openapi/v1_30/api/autoscaling/v2/
horizontal_pod_autoscaler_status.rs

1// Generated from definition io.k8s.api.autoscaling.v2.HorizontalPodAutoscalerStatus
2
3/// HorizontalPodAutoscalerStatus describes the current status of a horizontal pod autoscaler.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct HorizontalPodAutoscalerStatus {
6    /// conditions is the set of conditions required for this autoscaler to scale its target, and indicates whether or not those conditions are met.
7    pub conditions: Option<std::vec::Vec<crate::api::autoscaling::v2::HorizontalPodAutoscalerCondition>>,
8
9    /// currentMetrics is the last read state of the metrics used by this autoscaler.
10    pub current_metrics: Option<std::vec::Vec<crate::api::autoscaling::v2::MetricStatus>>,
11
12    /// currentReplicas is current number of replicas of pods managed by this autoscaler, as last seen by the autoscaler.
13    pub current_replicas: Option<i32>,
14
15    /// desiredReplicas is the desired number of replicas of pods managed by this autoscaler, as last calculated by the autoscaler.
16    pub desired_replicas: i32,
17
18    /// lastScaleTime is the last time the HorizontalPodAutoscaler scaled the number of pods, used by the autoscaler to control how often the number of pods is changed.
19    pub last_scale_time: Option<crate::apimachinery::pkg::apis::meta::v1::Time>,
20
21    /// observedGeneration is the most recent generation observed by this autoscaler.
22    pub observed_generation: Option<i64>,
23}
24
25impl crate::DeepMerge for HorizontalPodAutoscalerStatus {
26    fn merge_from(&mut self, other: Self) {
27        crate::merge_strategies::list::map(
28            &mut self.conditions,
29            other.conditions,
30            &[|lhs, rhs| lhs.type_ == rhs.type_],
31            |current_item, other_item| {
32                crate::DeepMerge::merge_from(current_item, other_item);
33            },
34        );
35        crate::merge_strategies::list::atomic(&mut self.current_metrics, other.current_metrics);
36        crate::DeepMerge::merge_from(&mut self.current_replicas, other.current_replicas);
37        crate::DeepMerge::merge_from(&mut self.desired_replicas, other.desired_replicas);
38        crate::DeepMerge::merge_from(&mut self.last_scale_time, other.last_scale_time);
39        crate::DeepMerge::merge_from(&mut self.observed_generation, other.observed_generation);
40    }
41}
42
43impl<'de> crate::serde::Deserialize<'de> for HorizontalPodAutoscalerStatus {
44    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
45        #[allow(non_camel_case_types)]
46        enum Field {
47            Key_conditions,
48            Key_current_metrics,
49            Key_current_replicas,
50            Key_desired_replicas,
51            Key_last_scale_time,
52            Key_observed_generation,
53            Other,
54        }
55
56        impl<'de> crate::serde::Deserialize<'de> for Field {
57            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
58                struct Visitor;
59
60                impl crate::serde::de::Visitor<'_> for Visitor {
61                    type Value = Field;
62
63                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
64                        f.write_str("field identifier")
65                    }
66
67                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
68                        Ok(match v {
69                            "conditions" => Field::Key_conditions,
70                            "currentMetrics" => Field::Key_current_metrics,
71                            "currentReplicas" => Field::Key_current_replicas,
72                            "desiredReplicas" => Field::Key_desired_replicas,
73                            "lastScaleTime" => Field::Key_last_scale_time,
74                            "observedGeneration" => Field::Key_observed_generation,
75                            _ => Field::Other,
76                        })
77                    }
78                }
79
80                deserializer.deserialize_identifier(Visitor)
81            }
82        }
83
84        struct Visitor;
85
86        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
87            type Value = HorizontalPodAutoscalerStatus;
88
89            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
90                f.write_str("HorizontalPodAutoscalerStatus")
91            }
92
93            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
94                let mut value_conditions: Option<std::vec::Vec<crate::api::autoscaling::v2::HorizontalPodAutoscalerCondition>> = None;
95                let mut value_current_metrics: Option<std::vec::Vec<crate::api::autoscaling::v2::MetricStatus>> = None;
96                let mut value_current_replicas: Option<i32> = None;
97                let mut value_desired_replicas: Option<i32> = None;
98                let mut value_last_scale_time: Option<crate::apimachinery::pkg::apis::meta::v1::Time> = None;
99                let mut value_observed_generation: Option<i64> = None;
100
101                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
102                    match key {
103                        Field::Key_conditions => value_conditions = crate::serde::de::MapAccess::next_value(&mut map)?,
104                        Field::Key_current_metrics => value_current_metrics = crate::serde::de::MapAccess::next_value(&mut map)?,
105                        Field::Key_current_replicas => value_current_replicas = crate::serde::de::MapAccess::next_value(&mut map)?,
106                        Field::Key_desired_replicas => value_desired_replicas = crate::serde::de::MapAccess::next_value(&mut map)?,
107                        Field::Key_last_scale_time => value_last_scale_time = crate::serde::de::MapAccess::next_value(&mut map)?,
108                        Field::Key_observed_generation => value_observed_generation = crate::serde::de::MapAccess::next_value(&mut map)?,
109                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
110                    }
111                }
112
113                Ok(HorizontalPodAutoscalerStatus {
114                    conditions: value_conditions,
115                    current_metrics: value_current_metrics,
116                    current_replicas: value_current_replicas,
117                    desired_replicas: value_desired_replicas.unwrap_or_default(),
118                    last_scale_time: value_last_scale_time,
119                    observed_generation: value_observed_generation,
120                })
121            }
122        }
123
124        deserializer.deserialize_struct(
125            "HorizontalPodAutoscalerStatus",
126            &[
127                "conditions",
128                "currentMetrics",
129                "currentReplicas",
130                "desiredReplicas",
131                "lastScaleTime",
132                "observedGeneration",
133            ],
134            Visitor,
135        )
136    }
137}
138
139impl crate::serde::Serialize for HorizontalPodAutoscalerStatus {
140    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
141        let mut state = serializer.serialize_struct(
142            "HorizontalPodAutoscalerStatus",
143            1 +
144            self.conditions.as_ref().map_or(0, |_| 1) +
145            self.current_metrics.as_ref().map_or(0, |_| 1) +
146            self.current_replicas.as_ref().map_or(0, |_| 1) +
147            self.last_scale_time.as_ref().map_or(0, |_| 1) +
148            self.observed_generation.as_ref().map_or(0, |_| 1),
149        )?;
150        if let Some(value) = &self.conditions {
151            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "conditions", value)?;
152        }
153        if let Some(value) = &self.current_metrics {
154            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "currentMetrics", value)?;
155        }
156        if let Some(value) = &self.current_replicas {
157            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "currentReplicas", value)?;
158        }
159        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "desiredReplicas", &self.desired_replicas)?;
160        if let Some(value) = &self.last_scale_time {
161            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "lastScaleTime", value)?;
162        }
163        if let Some(value) = &self.observed_generation {
164            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "observedGeneration", value)?;
165        }
166        crate::serde::ser::SerializeStruct::end(state)
167    }
168}
169
170#[cfg(feature = "schemars")]
171impl crate::schemars::JsonSchema for HorizontalPodAutoscalerStatus {
172    fn schema_name() -> std::borrow::Cow<'static, str> {
173        "io.k8s.api.autoscaling.v2.HorizontalPodAutoscalerStatus".into()
174    }
175
176    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
177        crate::schemars::json_schema!({
178            "description": "HorizontalPodAutoscalerStatus describes the current status of a horizontal pod autoscaler.",
179            "type": "object",
180            "properties": {
181                "conditions": {
182                    "description": "conditions is the set of conditions required for this autoscaler to scale its target, and indicates whether or not those conditions are met.",
183                    "type": "array",
184                    "items": (__gen.subschema_for::<crate::api::autoscaling::v2::HorizontalPodAutoscalerCondition>()),
185                },
186                "currentMetrics": {
187                    "description": "currentMetrics is the last read state of the metrics used by this autoscaler.",
188                    "type": "array",
189                    "items": (__gen.subschema_for::<crate::api::autoscaling::v2::MetricStatus>()),
190                },
191                "currentReplicas": {
192                    "description": "currentReplicas is current number of replicas of pods managed by this autoscaler, as last seen by the autoscaler.",
193                    "type": "integer",
194                    "format": "int32",
195                },
196                "desiredReplicas": {
197                    "description": "desiredReplicas is the desired number of replicas of pods managed by this autoscaler, as last calculated by the autoscaler.",
198                    "type": "integer",
199                    "format": "int32",
200                },
201                "lastScaleTime": ({
202                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::Time>();
203                    schema_obj.ensure_object().insert("description".into(), "lastScaleTime is the last time the HorizontalPodAutoscaler scaled the number of pods, used by the autoscaler to control how often the number of pods is changed.".into());
204                    schema_obj
205                }),
206                "observedGeneration": {
207                    "description": "observedGeneration is the most recent generation observed by this autoscaler.",
208                    "type": "integer",
209                    "format": "int64",
210                },
211            },
212            "required": [
213                "desiredReplicas",
214            ],
215        })
216    }
217}