k8s_openapi/v1_30/api/autoscaling/v2/
horizontal_pod_autoscaler_spec.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct HorizontalPodAutoscalerSpec {
6 pub behavior: Option<crate::api::autoscaling::v2::HorizontalPodAutoscalerBehavior>,
8
9 pub max_replicas: i32,
11
12 pub metrics: Option<std::vec::Vec<crate::api::autoscaling::v2::MetricSpec>>,
14
15 pub min_replicas: Option<i32>,
17
18 pub scale_target_ref: crate::api::autoscaling::v2::CrossVersionObjectReference,
20}
21
22impl crate::DeepMerge for HorizontalPodAutoscalerSpec {
23 fn merge_from(&mut self, other: Self) {
24 crate::DeepMerge::merge_from(&mut self.behavior, other.behavior);
25 crate::DeepMerge::merge_from(&mut self.max_replicas, other.max_replicas);
26 crate::merge_strategies::list::atomic(&mut self.metrics, other.metrics);
27 crate::DeepMerge::merge_from(&mut self.min_replicas, other.min_replicas);
28 crate::DeepMerge::merge_from(&mut self.scale_target_ref, other.scale_target_ref);
29 }
30}
31
32impl<'de> crate::serde::Deserialize<'de> for HorizontalPodAutoscalerSpec {
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_behavior,
37 Key_max_replicas,
38 Key_metrics,
39 Key_min_replicas,
40 Key_scale_target_ref,
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 "behavior" => Field::Key_behavior,
58 "maxReplicas" => Field::Key_max_replicas,
59 "metrics" => Field::Key_metrics,
60 "minReplicas" => Field::Key_min_replicas,
61 "scaleTargetRef" => Field::Key_scale_target_ref,
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 = HorizontalPodAutoscalerSpec;
75
76 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77 f.write_str("HorizontalPodAutoscalerSpec")
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_behavior: Option<crate::api::autoscaling::v2::HorizontalPodAutoscalerBehavior> = None;
82 let mut value_max_replicas: Option<i32> = None;
83 let mut value_metrics: Option<std::vec::Vec<crate::api::autoscaling::v2::MetricSpec>> = None;
84 let mut value_min_replicas: Option<i32> = None;
85 let mut value_scale_target_ref: Option<crate::api::autoscaling::v2::CrossVersionObjectReference> = None;
86
87 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
88 match key {
89 Field::Key_behavior => value_behavior = crate::serde::de::MapAccess::next_value(&mut map)?,
90 Field::Key_max_replicas => value_max_replicas = crate::serde::de::MapAccess::next_value(&mut map)?,
91 Field::Key_metrics => value_metrics = crate::serde::de::MapAccess::next_value(&mut map)?,
92 Field::Key_min_replicas => value_min_replicas = crate::serde::de::MapAccess::next_value(&mut map)?,
93 Field::Key_scale_target_ref => value_scale_target_ref = 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(HorizontalPodAutoscalerSpec {
99 behavior: value_behavior,
100 max_replicas: value_max_replicas.unwrap_or_default(),
101 metrics: value_metrics,
102 min_replicas: value_min_replicas,
103 scale_target_ref: value_scale_target_ref.unwrap_or_default(),
104 })
105 }
106 }
107
108 deserializer.deserialize_struct(
109 "HorizontalPodAutoscalerSpec",
110 &[
111 "behavior",
112 "maxReplicas",
113 "metrics",
114 "minReplicas",
115 "scaleTargetRef",
116 ],
117 Visitor,
118 )
119 }
120}
121
122impl crate::serde::Serialize for HorizontalPodAutoscalerSpec {
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 "HorizontalPodAutoscalerSpec",
126 2 +
127 self.behavior.as_ref().map_or(0, |_| 1) +
128 self.metrics.as_ref().map_or(0, |_| 1) +
129 self.min_replicas.as_ref().map_or(0, |_| 1),
130 )?;
131 if let Some(value) = &self.behavior {
132 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "behavior", value)?;
133 }
134 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "maxReplicas", &self.max_replicas)?;
135 if let Some(value) = &self.metrics {
136 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metrics", value)?;
137 }
138 if let Some(value) = &self.min_replicas {
139 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "minReplicas", value)?;
140 }
141 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "scaleTargetRef", &self.scale_target_ref)?;
142 crate::serde::ser::SerializeStruct::end(state)
143 }
144}
145
146#[cfg(feature = "schemars")]
147impl crate::schemars::JsonSchema for HorizontalPodAutoscalerSpec {
148 fn schema_name() -> std::borrow::Cow<'static, str> {
149 "io.k8s.api.autoscaling.v2.HorizontalPodAutoscalerSpec".into()
150 }
151
152 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
153 crate::schemars::json_schema!({
154 "description": "HorizontalPodAutoscalerSpec describes the desired functionality of the HorizontalPodAutoscaler.",
155 "type": "object",
156 "properties": {
157 "behavior": ({
158 let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::HorizontalPodAutoscalerBehavior>();
159 schema_obj.ensure_object().insert("description".into(), "behavior configures the scaling behavior of the target in both Up and Down directions (scaleUp and scaleDown fields respectively). If not set, the default HPAScalingRules for scale up and scale down are used.".into());
160 schema_obj
161 }),
162 "maxReplicas": {
163 "description": "maxReplicas is the upper limit for the number of replicas to which the autoscaler can scale up. It cannot be less that minReplicas.",
164 "type": "integer",
165 "format": "int32",
166 },
167 "metrics": {
168 "description": "metrics contains the specifications for which to use to calculate the desired replica count (the maximum replica count across all metrics will be used). The desired replica count is calculated multiplying the ratio between the target value and the current value by the current number of pods. Ergo, metrics used must decrease as the pod count is increased, and vice-versa. See the individual metric source types for more information about how each type of metric must respond. If not set, the default metric will be set to 80% average CPU utilization.",
169 "type": "array",
170 "items": (__gen.subschema_for::<crate::api::autoscaling::v2::MetricSpec>()),
171 },
172 "minReplicas": {
173 "description": "minReplicas is the lower limit for the number of replicas to which the autoscaler can scale down. It defaults to 1 pod. minReplicas is allowed to be 0 if the alpha feature gate HPAScaleToZero is enabled and at least one Object or External metric is configured. Scaling is active as long as at least one metric value is available.",
174 "type": "integer",
175 "format": "int32",
176 },
177 "scaleTargetRef": ({
178 let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::CrossVersionObjectReference>();
179 schema_obj.ensure_object().insert("description".into(), "scaleTargetRef points to the target resource to scale, and is used to the pods for which metrics should be collected, as well as to actually change the replica count.".into());
180 schema_obj
181 }),
182 },
183 "required": [
184 "maxReplicas",
185 "scaleTargetRef",
186 ],
187 })
188 }
189}