k8s_openapi/v1_30/api/autoscaling/v2/
hpa_scaling_policy.rs
1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct HPAScalingPolicy {
6 pub period_seconds: i32,
8
9 pub type_: String,
11
12 pub value: i32,
14}
15
16impl crate::DeepMerge for HPAScalingPolicy {
17 fn merge_from(&mut self, other: Self) {
18 crate::DeepMerge::merge_from(&mut self.period_seconds, other.period_seconds);
19 crate::DeepMerge::merge_from(&mut self.type_, other.type_);
20 crate::DeepMerge::merge_from(&mut self.value, other.value);
21 }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for HPAScalingPolicy {
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_period_seconds,
29 Key_type_,
30 Key_value,
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<'de> crate::serde::de::Visitor<'de> 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 "periodSeconds" => Field::Key_period_seconds,
48 "type" => Field::Key_type_,
49 "value" => Field::Key_value,
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 = HPAScalingPolicy;
63
64 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65 f.write_str("HPAScalingPolicy")
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_period_seconds: Option<i32> = None;
70 let mut value_type_: Option<String> = None;
71 let mut value_value: Option<i32> = None;
72
73 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74 match key {
75 Field::Key_period_seconds => value_period_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
76 Field::Key_type_ => value_type_ = crate::serde::de::MapAccess::next_value(&mut map)?,
77 Field::Key_value => value_value = 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(HPAScalingPolicy {
83 period_seconds: value_period_seconds.unwrap_or_default(),
84 type_: value_type_.unwrap_or_default(),
85 value: value_value.unwrap_or_default(),
86 })
87 }
88 }
89
90 deserializer.deserialize_struct(
91 "HPAScalingPolicy",
92 &[
93 "periodSeconds",
94 "type",
95 "value",
96 ],
97 Visitor,
98 )
99 }
100}
101
102impl crate::serde::Serialize for HPAScalingPolicy {
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 "HPAScalingPolicy",
106 3,
107 )?;
108 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "periodSeconds", &self.period_seconds)?;
109 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "type", &self.type_)?;
110 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "value", &self.value)?;
111 crate::serde::ser::SerializeStruct::end(state)
112 }
113}
114
115#[cfg(feature = "schemars")]
116impl crate::schemars::JsonSchema for HPAScalingPolicy {
117 fn schema_name() -> String {
118 "io.k8s.api.autoscaling.v2.HPAScalingPolicy".to_owned()
119 }
120
121 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
122 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
123 metadata: Some(Box::new(crate::schemars::schema::Metadata {
124 description: Some("HPAScalingPolicy is a single policy which must hold true for a specified past interval.".to_owned()),
125 ..Default::default()
126 })),
127 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
128 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
129 properties: [
130 (
131 "periodSeconds".to_owned(),
132 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
133 metadata: Some(Box::new(crate::schemars::schema::Metadata {
134 description: Some("periodSeconds specifies the window of time for which the policy should hold true. PeriodSeconds must be greater than zero and less than or equal to 1800 (30 min).".to_owned()),
135 ..Default::default()
136 })),
137 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
138 format: Some("int32".to_owned()),
139 ..Default::default()
140 }),
141 ),
142 (
143 "type".to_owned(),
144 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
145 metadata: Some(Box::new(crate::schemars::schema::Metadata {
146 description: Some("type is used to specify the scaling policy.".to_owned()),
147 ..Default::default()
148 })),
149 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
150 ..Default::default()
151 }),
152 ),
153 (
154 "value".to_owned(),
155 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
156 metadata: Some(Box::new(crate::schemars::schema::Metadata {
157 description: Some("value contains the amount of change which is permitted by the policy. It must be greater than zero".to_owned()),
158 ..Default::default()
159 })),
160 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
161 format: Some("int32".to_owned()),
162 ..Default::default()
163 }),
164 ),
165 ].into(),
166 required: [
167 "periodSeconds".to_owned(),
168 "type".to_owned(),
169 "value".to_owned(),
170 ].into(),
171 ..Default::default()
172 })),
173 ..Default::default()
174 })
175 }
176}