k8s_openapi/v1_32/api/autoscaling/v2/
hpa_scaling_rules.rs

1// Generated from definition io.k8s.api.autoscaling.v2.HPAScalingRules
2
3/// HPAScalingRules configures the scaling behavior for one direction. These 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.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct HPAScalingRules {
6    /// policies is a list of potential scaling polices which can be used during scaling. At least one policy must be specified, otherwise the HPAScalingRules will be discarded as invalid
7    pub policies: Option<Vec<crate::api::autoscaling::v2::HPAScalingPolicy>>,
8
9    /// selectPolicy is used to specify which policy should be used. If not set, the default value Max is used.
10    pub select_policy: Option<String>,
11
12    /// 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).
13    pub stabilization_window_seconds: Option<i32>,
14}
15
16impl crate::DeepMerge for HPAScalingRules {
17    fn merge_from(&mut self, other: Self) {
18        crate::merge_strategies::list::atomic(&mut self.policies, other.policies);
19        crate::DeepMerge::merge_from(&mut self.select_policy, other.select_policy);
20        crate::DeepMerge::merge_from(&mut self.stabilization_window_seconds, other.stabilization_window_seconds);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for HPAScalingRules {
25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26        #[allow(non_camel_case_types)]
27        enum Field {
28            Key_policies,
29            Key_select_policy,
30            Key_stabilization_window_seconds,
31            Other,
32        }
33
34        impl<'de> crate::serde::Deserialize<'de> for Field {
35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36                struct Visitor;
37
38                impl crate::serde::de::Visitor<'_> for Visitor {
39                    type Value = Field;
40
41                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42                        f.write_str("field identifier")
43                    }
44
45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46                        Ok(match v {
47                            "policies" => Field::Key_policies,
48                            "selectPolicy" => Field::Key_select_policy,
49                            "stabilizationWindowSeconds" => Field::Key_stabilization_window_seconds,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = HPAScalingRules;
63
64            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65                f.write_str("HPAScalingRules")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_policies: Option<Vec<crate::api::autoscaling::v2::HPAScalingPolicy>> = None;
70                let mut value_select_policy: Option<String> = None;
71                let mut value_stabilization_window_seconds: Option<i32> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_policies => value_policies = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_select_policy => value_select_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_stabilization_window_seconds => value_stabilization_window_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79                    }
80                }
81
82                Ok(HPAScalingRules {
83                    policies: value_policies,
84                    select_policy: value_select_policy,
85                    stabilization_window_seconds: value_stabilization_window_seconds,
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "HPAScalingRules",
92            &[
93                "policies",
94                "selectPolicy",
95                "stabilizationWindowSeconds",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for HPAScalingRules {
103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104        let mut state = serializer.serialize_struct(
105            "HPAScalingRules",
106            self.policies.as_ref().map_or(0, |_| 1) +
107            self.select_policy.as_ref().map_or(0, |_| 1) +
108            self.stabilization_window_seconds.as_ref().map_or(0, |_| 1),
109        )?;
110        if let Some(value) = &self.policies {
111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "policies", value)?;
112        }
113        if let Some(value) = &self.select_policy {
114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectPolicy", value)?;
115        }
116        if let Some(value) = &self.stabilization_window_seconds {
117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "stabilizationWindowSeconds", value)?;
118        }
119        crate::serde::ser::SerializeStruct::end(state)
120    }
121}
122
123#[cfg(feature = "schemars")]
124impl crate::schemars::JsonSchema for HPAScalingRules {
125    fn schema_name() -> String {
126        "io.k8s.api.autoscaling.v2.HPAScalingRules".to_owned()
127    }
128
129    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
130        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
131            metadata: Some(Box::new(crate::schemars::schema::Metadata {
132                description: Some("HPAScalingRules configures the scaling behavior for one direction. These 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.".to_owned()),
133                ..Default::default()
134            })),
135            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
136            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
137                properties: [
138                    (
139                        "policies".to_owned(),
140                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
141                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
142                                description: Some("policies is a list of potential scaling polices which can be used during scaling. At least one policy must be specified, otherwise the HPAScalingRules will be discarded as invalid".to_owned()),
143                                ..Default::default()
144                            })),
145                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
146                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
147                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::autoscaling::v2::HPAScalingPolicy>()))),
148                                ..Default::default()
149                            })),
150                            ..Default::default()
151                        }),
152                    ),
153                    (
154                        "selectPolicy".to_owned(),
155                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
156                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
157                                description: Some("selectPolicy is used to specify which policy should be used. If not set, the default value Max is used.".to_owned()),
158                                ..Default::default()
159                            })),
160                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
161                            ..Default::default()
162                        }),
163                    ),
164                    (
165                        "stabilizationWindowSeconds".to_owned(),
166                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
167                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
168                                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).".to_owned()),
169                                ..Default::default()
170                            })),
171                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
172                            format: Some("int32".to_owned()),
173                            ..Default::default()
174                        }),
175                    ),
176                ].into(),
177                ..Default::default()
178            })),
179            ..Default::default()
180        })
181    }
182}