1// Generated from definition io.k8s.api.autoscaling.v2.HPAScalingRules
23/// HPAScalingRules configures the scaling behavior for one direction via scaling Policy Rules and a configurable metric tolerance.
4///
5/// Scaling Policy Rules are applied after calculating DesiredReplicas from metrics for the HPA. They can limit the scaling velocity by specifying scaling policies. They can prevent flapping by specifying the stabilization window, so that the number of replicas is not set instantly, instead, the safest value from the stabilization window is chosen.
6///
7/// The tolerance is applied to the metric values and prevents scaling too eagerly for small metric variations. (Note that setting a tolerance requires enabling the alpha HPAConfigurableTolerance feature gate.)
8#[derive(Clone, Debug, Default, PartialEq)]
9pub struct HPAScalingRules {
10/// policies is a list of potential scaling polices which can be used during scaling. If not set, use the default values: - For scale up: allow doubling the number of pods, or an absolute change of 4 pods in a 15s window. - For scale down: allow all pods to be removed in a 15s window.
11pub policies: Option<std::vec::Vec<crate::api::autoscaling::v2::HPAScalingPolicy>>,
1213/// selectPolicy is used to specify which policy should be used. If not set, the default value Max is used.
14pub select_policy: Option<std::string::String>,
1516/// stabilizationWindowSeconds is the number of seconds for which past recommendations should be considered while scaling up or scaling down. StabilizationWindowSeconds must be greater than or equal to zero and less than or equal to 3600 (one hour). If not set, use the default values: - For scale up: 0 (i.e. no stabilization is done). - For scale down: 300 (i.e. the stabilization window is 300 seconds long).
17pub stabilization_window_seconds: Option<i32>,
1819/// tolerance is the tolerance on the ratio between the current and desired metric value under which no updates are made to the desired number of replicas (e.g. 0.01 for 1%). Must be greater than or equal to zero. If not set, the default cluster-wide tolerance is applied (by default 10%).
20 ///
21 /// For example, if autoscaling is configured with a memory consumption target of 100Mi, and scale-down and scale-up tolerances of 5% and 1% respectively, scaling will be triggered when the actual consumption falls below 95Mi or exceeds 101Mi.
22 ///
23 /// This is an alpha field and requires enabling the HPAConfigurableTolerance feature gate.
24pub tolerance: Option<crate::apimachinery::pkg::api::resource::Quantity>,
25}
2627impl crate::DeepMerge for HPAScalingRules {
28fn merge_from(&mut self, other: Self) {
29crate::merge_strategies::list::atomic(&mut self.policies, other.policies);
30crate::DeepMerge::merge_from(&mut self.select_policy, other.select_policy);
31crate::DeepMerge::merge_from(&mut self.stabilization_window_seconds, other.stabilization_window_seconds);
32crate::DeepMerge::merge_from(&mut self.tolerance, other.tolerance);
33 }
34}
3536impl<'de> crate::serde::Deserialize<'de> for HPAScalingRules {
37fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38#[allow(non_camel_case_types)]
39enum Field {
40 Key_policies,
41 Key_select_policy,
42 Key_stabilization_window_seconds,
43 Key_tolerance,
44 Other,
45 }
4647impl<'de> crate::serde::Deserialize<'de> for Field {
48fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
49struct Visitor;
5051impl crate::serde::de::Visitor<'_> for Visitor {
52type Value = Field;
5354fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
55 f.write_str("field identifier")
56 }
5758fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
59Ok(match v {
60"policies" => Field::Key_policies,
61"selectPolicy" => Field::Key_select_policy,
62"stabilizationWindowSeconds" => Field::Key_stabilization_window_seconds,
63"tolerance" => Field::Key_tolerance,
64_ => Field::Other,
65 })
66 }
67 }
6869 deserializer.deserialize_identifier(Visitor)
70 }
71 }
7273struct Visitor;
7475impl<'de> crate::serde::de::Visitor<'de> for Visitor {
76type Value = HPAScalingRules;
7778fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
79 f.write_str("HPAScalingRules")
80 }
8182fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
83let mut value_policies: Option<std::vec::Vec<crate::api::autoscaling::v2::HPAScalingPolicy>> = None;
84let mut value_select_policy: Option<std::string::String> = None;
85let mut value_stabilization_window_seconds: Option<i32> = None;
86let mut value_tolerance: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
8788while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
89match key {
90 Field::Key_policies => value_policies = crate::serde::de::MapAccess::next_value(&mut map)?,
91 Field::Key_select_policy => value_select_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
92 Field::Key_stabilization_window_seconds => value_stabilization_window_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
93 Field::Key_tolerance => value_tolerance = 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 }
9798Ok(HPAScalingRules {
99 policies: value_policies,
100 select_policy: value_select_policy,
101 stabilization_window_seconds: value_stabilization_window_seconds,
102 tolerance: value_tolerance,
103 })
104 }
105 }
106107 deserializer.deserialize_struct(
108"HPAScalingRules",
109&[
110"policies",
111"selectPolicy",
112"stabilizationWindowSeconds",
113"tolerance",
114 ],
115 Visitor,
116 )
117 }
118}
119120impl crate::serde::Serialize for HPAScalingRules {
121fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
122let mut state = serializer.serialize_struct(
123"HPAScalingRules",
124self.policies.as_ref().map_or(0, |_| 1) +
125self.select_policy.as_ref().map_or(0, |_| 1) +
126self.stabilization_window_seconds.as_ref().map_or(0, |_| 1) +
127self.tolerance.as_ref().map_or(0, |_| 1),
128 )?;
129if let Some(value) = &self.policies {
130crate::serde::ser::SerializeStruct::serialize_field(&mut state, "policies", value)?;
131 }
132if let Some(value) = &self.select_policy {
133crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectPolicy", value)?;
134 }
135if let Some(value) = &self.stabilization_window_seconds {
136crate::serde::ser::SerializeStruct::serialize_field(&mut state, "stabilizationWindowSeconds", value)?;
137 }
138if let Some(value) = &self.tolerance {
139crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tolerance", value)?;
140 }
141crate::serde::ser::SerializeStruct::end(state)
142 }
143}
144145#[cfg(feature = "schemars")]
146impl crate::schemars::JsonSchema for HPAScalingRules {
147fn schema_name() -> std::string::String {
148"io.k8s.api.autoscaling.v2.HPAScalingRules".into()
149 }
150151fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
152crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
153 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
154 description: Some("HPAScalingRules configures the scaling behavior for one direction via scaling Policy Rules and a configurable metric tolerance.\n\nScaling Policy Rules are applied after calculating DesiredReplicas from metrics for the HPA. They can limit the scaling velocity by specifying scaling policies. They can prevent flapping by specifying the stabilization window, so that the number of replicas is not set instantly, instead, the safest value from the stabilization window is chosen.\n\nThe tolerance is applied to the metric values and prevents scaling too eagerly for small metric variations. (Note that setting a tolerance requires enabling the alpha HPAConfigurableTolerance feature gate.)".into()),
155 ..Default::default()
156 })),
157 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
158 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
159 properties: [
160 (
161"policies".into(),
162crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
163 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
164 description: Some("policies is a list of potential scaling polices which can be used during scaling. If not set, use the default values: - For scale up: allow doubling the number of pods, or an absolute change of 4 pods in a 15s window. - For scale down: allow all pods to be removed in a 15s window.".into()),
165 ..Default::default()
166 })),
167 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
168 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
169 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::autoscaling::v2::HPAScalingPolicy>()))),
170 ..Default::default()
171 })),
172 ..Default::default()
173 }),
174 ),
175 (
176"selectPolicy".into(),
177crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
178 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
179 description: Some("selectPolicy is used to specify which policy should be used. If not set, the default value Max is used.".into()),
180 ..Default::default()
181 })),
182 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
183 ..Default::default()
184 }),
185 ),
186 (
187"stabilizationWindowSeconds".into(),
188crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
189 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
190 description: Some("stabilizationWindowSeconds is the number of seconds for which past recommendations should be considered while scaling up or scaling down. StabilizationWindowSeconds must be greater than or equal to zero and less than or equal to 3600 (one hour). If not set, use the default values: - For scale up: 0 (i.e. no stabilization is done). - For scale down: 300 (i.e. the stabilization window is 300 seconds long).".into()),
191 ..Default::default()
192 })),
193 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
194 format: Some("int32".into()),
195 ..Default::default()
196 }),
197 ),
198 (
199"tolerance".into(),
200 {
201let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>().into_object();
202 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
203 description: Some("tolerance is the tolerance on the ratio between the current and desired metric value under which no updates are made to the desired number of replicas (e.g. 0.01 for 1%). Must be greater than or equal to zero. If not set, the default cluster-wide tolerance is applied (by default 10%).\n\nFor example, if autoscaling is configured with a memory consumption target of 100Mi, and scale-down and scale-up tolerances of 5% and 1% respectively, scaling will be triggered when the actual consumption falls below 95Mi or exceeds 101Mi.\n\nThis is an alpha field and requires enabling the HPAConfigurableTolerance feature gate.".into()),
204 ..Default::default()
205 }));
206crate::schemars::schema::Schema::Object(schema_obj)
207 },
208 ),
209 ].into(),
210 ..Default::default()
211 })),
212 ..Default::default()
213 })
214 }
215}