k8s_openapi/v1_30/api/autoscaling/v1/
horizontal_pod_autoscaler_spec.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct HorizontalPodAutoscalerSpec {
6 pub max_replicas: i32,
8
9 pub min_replicas: Option<i32>,
11
12 pub scale_target_ref: crate::api::autoscaling::v1::CrossVersionObjectReference,
14
15 pub target_cpu_utilization_percentage: Option<i32>,
17}
18
19impl crate::DeepMerge for HorizontalPodAutoscalerSpec {
20 fn merge_from(&mut self, other: Self) {
21 crate::DeepMerge::merge_from(&mut self.max_replicas, other.max_replicas);
22 crate::DeepMerge::merge_from(&mut self.min_replicas, other.min_replicas);
23 crate::DeepMerge::merge_from(&mut self.scale_target_ref, other.scale_target_ref);
24 crate::DeepMerge::merge_from(&mut self.target_cpu_utilization_percentage, other.target_cpu_utilization_percentage);
25 }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for HorizontalPodAutoscalerSpec {
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_max_replicas,
33 Key_min_replicas,
34 Key_scale_target_ref,
35 Key_target_cpu_utilization_percentage,
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 "maxReplicas" => Field::Key_max_replicas,
53 "minReplicas" => Field::Key_min_replicas,
54 "scaleTargetRef" => Field::Key_scale_target_ref,
55 "targetCPUUtilizationPercentage" => Field::Key_target_cpu_utilization_percentage,
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 = HorizontalPodAutoscalerSpec;
69
70 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71 f.write_str("HorizontalPodAutoscalerSpec")
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_max_replicas: Option<i32> = None;
76 let mut value_min_replicas: Option<i32> = None;
77 let mut value_scale_target_ref: Option<crate::api::autoscaling::v1::CrossVersionObjectReference> = None;
78 let mut value_target_cpu_utilization_percentage: Option<i32> = None;
79
80 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81 match key {
82 Field::Key_max_replicas => value_max_replicas = crate::serde::de::MapAccess::next_value(&mut map)?,
83 Field::Key_min_replicas => value_min_replicas = crate::serde::de::MapAccess::next_value(&mut map)?,
84 Field::Key_scale_target_ref => value_scale_target_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
85 Field::Key_target_cpu_utilization_percentage => value_target_cpu_utilization_percentage = 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(HorizontalPodAutoscalerSpec {
91 max_replicas: value_max_replicas.unwrap_or_default(),
92 min_replicas: value_min_replicas,
93 scale_target_ref: value_scale_target_ref.unwrap_or_default(),
94 target_cpu_utilization_percentage: value_target_cpu_utilization_percentage,
95 })
96 }
97 }
98
99 deserializer.deserialize_struct(
100 "HorizontalPodAutoscalerSpec",
101 &[
102 "maxReplicas",
103 "minReplicas",
104 "scaleTargetRef",
105 "targetCPUUtilizationPercentage",
106 ],
107 Visitor,
108 )
109 }
110}
111
112impl crate::serde::Serialize for HorizontalPodAutoscalerSpec {
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 "HorizontalPodAutoscalerSpec",
116 2 +
117 self.min_replicas.as_ref().map_or(0, |_| 1) +
118 self.target_cpu_utilization_percentage.as_ref().map_or(0, |_| 1),
119 )?;
120 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "maxReplicas", &self.max_replicas)?;
121 if let Some(value) = &self.min_replicas {
122 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "minReplicas", value)?;
123 }
124 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "scaleTargetRef", &self.scale_target_ref)?;
125 if let Some(value) = &self.target_cpu_utilization_percentage {
126 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "targetCPUUtilizationPercentage", value)?;
127 }
128 crate::serde::ser::SerializeStruct::end(state)
129 }
130}
131
132#[cfg(feature = "schemars")]
133impl crate::schemars::JsonSchema for HorizontalPodAutoscalerSpec {
134 fn schema_name() -> std::borrow::Cow<'static, str> {
135 "io.k8s.api.autoscaling.v1.HorizontalPodAutoscalerSpec".into()
136 }
137
138 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
139 crate::schemars::json_schema!({
140 "description": "specification of a horizontal pod autoscaler.",
141 "type": "object",
142 "properties": {
143 "maxReplicas": {
144 "description": "maxReplicas is the upper limit for the number of pods that can be set by the autoscaler; cannot be smaller than MinReplicas.",
145 "type": "integer",
146 "format": "int32",
147 },
148 "minReplicas": {
149 "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.",
150 "type": "integer",
151 "format": "int32",
152 },
153 "scaleTargetRef": ({
154 let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v1::CrossVersionObjectReference>();
155 schema_obj.ensure_object().insert("description".into(), "reference to scaled resource; horizontal pod autoscaler will learn the current resource consumption and will set the desired number of pods by using its Scale subresource.".into());
156 schema_obj
157 }),
158 "targetCPUUtilizationPercentage": {
159 "description": "targetCPUUtilizationPercentage is the target average CPU utilization (represented as a percentage of requested CPU) over all the pods; if not specified the default autoscaling policy will be used.",
160 "type": "integer",
161 "format": "int32",
162 },
163 },
164 "required": [
165 "maxReplicas",
166 "scaleTargetRef",
167 ],
168 })
169 }
170}