k8s_openapi/v1_34/api/autoscaling/v1/
horizontal_pod_autoscaler_status.rs

1// Generated from definition io.k8s.api.autoscaling.v1.HorizontalPodAutoscalerStatus
2
3/// current status of a horizontal pod autoscaler
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct HorizontalPodAutoscalerStatus {
6    /// currentCPUUtilizationPercentage is the current average CPU utilization over all pods, represented as a percentage of requested CPU, e.g. 70 means that an average pod is using now 70% of its requested CPU.
7    pub current_cpu_utilization_percentage: Option<i32>,
8
9    /// currentReplicas is the current number of replicas of pods managed by this autoscaler.
10    pub current_replicas: i32,
11
12    /// desiredReplicas is the  desired number of replicas of pods managed by this autoscaler.
13    pub desired_replicas: i32,
14
15    /// 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.
16    pub last_scale_time: Option<crate::apimachinery::pkg::apis::meta::v1::Time>,
17
18    /// observedGeneration is the most recent generation observed by this autoscaler.
19    pub observed_generation: Option<i64>,
20}
21
22impl crate::DeepMerge for HorizontalPodAutoscalerStatus {
23    fn merge_from(&mut self, other: Self) {
24        crate::DeepMerge::merge_from(&mut self.current_cpu_utilization_percentage, other.current_cpu_utilization_percentage);
25        crate::DeepMerge::merge_from(&mut self.current_replicas, other.current_replicas);
26        crate::DeepMerge::merge_from(&mut self.desired_replicas, other.desired_replicas);
27        crate::DeepMerge::merge_from(&mut self.last_scale_time, other.last_scale_time);
28        crate::DeepMerge::merge_from(&mut self.observed_generation, other.observed_generation);
29    }
30}
31
32impl<'de> crate::serde::Deserialize<'de> for HorizontalPodAutoscalerStatus {
33    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
34        #[allow(non_camel_case_types)]
35        enum Field {
36            Key_current_cpu_utilization_percentage,
37            Key_current_replicas,
38            Key_desired_replicas,
39            Key_last_scale_time,
40            Key_observed_generation,
41            Other,
42        }
43
44        impl<'de> crate::serde::Deserialize<'de> for Field {
45            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
46                struct Visitor;
47
48                impl crate::serde::de::Visitor<'_> for Visitor {
49                    type Value = Field;
50
51                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
52                        f.write_str("field identifier")
53                    }
54
55                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
56                        Ok(match v {
57                            "currentCPUUtilizationPercentage" => Field::Key_current_cpu_utilization_percentage,
58                            "currentReplicas" => Field::Key_current_replicas,
59                            "desiredReplicas" => Field::Key_desired_replicas,
60                            "lastScaleTime" => Field::Key_last_scale_time,
61                            "observedGeneration" => Field::Key_observed_generation,
62                            _ => Field::Other,
63                        })
64                    }
65                }
66
67                deserializer.deserialize_identifier(Visitor)
68            }
69        }
70
71        struct Visitor;
72
73        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
74            type Value = HorizontalPodAutoscalerStatus;
75
76            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77                f.write_str("HorizontalPodAutoscalerStatus")
78            }
79
80            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
81                let mut value_current_cpu_utilization_percentage: Option<i32> = None;
82                let mut value_current_replicas: Option<i32> = None;
83                let mut value_desired_replicas: Option<i32> = None;
84                let mut value_last_scale_time: Option<crate::apimachinery::pkg::apis::meta::v1::Time> = None;
85                let mut value_observed_generation: Option<i64> = None;
86
87                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
88                    match key {
89                        Field::Key_current_cpu_utilization_percentage => value_current_cpu_utilization_percentage = crate::serde::de::MapAccess::next_value(&mut map)?,
90                        Field::Key_current_replicas => value_current_replicas = crate::serde::de::MapAccess::next_value(&mut map)?,
91                        Field::Key_desired_replicas => value_desired_replicas = crate::serde::de::MapAccess::next_value(&mut map)?,
92                        Field::Key_last_scale_time => value_last_scale_time = crate::serde::de::MapAccess::next_value(&mut map)?,
93                        Field::Key_observed_generation => value_observed_generation = crate::serde::de::MapAccess::next_value(&mut map)?,
94                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
95                    }
96                }
97
98                Ok(HorizontalPodAutoscalerStatus {
99                    current_cpu_utilization_percentage: value_current_cpu_utilization_percentage,
100                    current_replicas: value_current_replicas.unwrap_or_default(),
101                    desired_replicas: value_desired_replicas.unwrap_or_default(),
102                    last_scale_time: value_last_scale_time,
103                    observed_generation: value_observed_generation,
104                })
105            }
106        }
107
108        deserializer.deserialize_struct(
109            "HorizontalPodAutoscalerStatus",
110            &[
111                "currentCPUUtilizationPercentage",
112                "currentReplicas",
113                "desiredReplicas",
114                "lastScaleTime",
115                "observedGeneration",
116            ],
117            Visitor,
118        )
119    }
120}
121
122impl crate::serde::Serialize for HorizontalPodAutoscalerStatus {
123    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
124        let mut state = serializer.serialize_struct(
125            "HorizontalPodAutoscalerStatus",
126            2 +
127            self.current_cpu_utilization_percentage.as_ref().map_or(0, |_| 1) +
128            self.last_scale_time.as_ref().map_or(0, |_| 1) +
129            self.observed_generation.as_ref().map_or(0, |_| 1),
130        )?;
131        if let Some(value) = &self.current_cpu_utilization_percentage {
132            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "currentCPUUtilizationPercentage", value)?;
133        }
134        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "currentReplicas", &self.current_replicas)?;
135        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "desiredReplicas", &self.desired_replicas)?;
136        if let Some(value) = &self.last_scale_time {
137            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "lastScaleTime", value)?;
138        }
139        if let Some(value) = &self.observed_generation {
140            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "observedGeneration", value)?;
141        }
142        crate::serde::ser::SerializeStruct::end(state)
143    }
144}
145
146#[cfg(feature = "schemars")]
147impl crate::schemars::JsonSchema for HorizontalPodAutoscalerStatus {
148    fn schema_name() -> std::borrow::Cow<'static, str> {
149        "io.k8s.api.autoscaling.v1.HorizontalPodAutoscalerStatus".into()
150    }
151
152    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
153        crate::schemars::json_schema!({
154            "description": "current status of a horizontal pod autoscaler",
155            "type": "object",
156            "properties": {
157                "currentCPUUtilizationPercentage": {
158                    "description": "currentCPUUtilizationPercentage is the current average CPU utilization over all pods, represented as a percentage of requested CPU, e.g. 70 means that an average pod is using now 70% of its requested CPU.",
159                    "type": "integer",
160                    "format": "int32",
161                },
162                "currentReplicas": {
163                    "description": "currentReplicas is the current number of replicas of pods managed by this autoscaler.",
164                    "type": "integer",
165                    "format": "int32",
166                },
167                "desiredReplicas": {
168                    "description": "desiredReplicas is the  desired number of replicas of pods managed by this autoscaler.",
169                    "type": "integer",
170                    "format": "int32",
171                },
172                "lastScaleTime": ({
173                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::Time>();
174                    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());
175                    schema_obj
176                }),
177                "observedGeneration": {
178                    "description": "observedGeneration is the most recent generation observed by this autoscaler.",
179                    "type": "integer",
180                    "format": "int64",
181                },
182            },
183            "required": [
184                "currentReplicas",
185                "desiredReplicas",
186            ],
187        })
188    }
189}