1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PodDisruptionBudgetStatus {
6 pub conditions: Option<std::vec::Vec<crate::apimachinery::pkg::apis::meta::v1::Condition>>,
16
17 pub current_healthy: i32,
19
20 pub desired_healthy: i32,
22
23 pub disrupted_pods: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::apis::meta::v1::Time>>,
25
26 pub disruptions_allowed: i32,
28
29 pub expected_pods: i32,
31
32 pub observed_generation: Option<i64>,
34}
35
36impl crate::DeepMerge for PodDisruptionBudgetStatus {
37 fn merge_from(&mut self, other: Self) {
38 crate::merge_strategies::list::map(
39 &mut self.conditions,
40 other.conditions,
41 &[|lhs, rhs| lhs.type_ == rhs.type_],
42 |current_item, other_item| {
43 crate::DeepMerge::merge_from(current_item, other_item);
44 },
45 );
46 crate::DeepMerge::merge_from(&mut self.current_healthy, other.current_healthy);
47 crate::DeepMerge::merge_from(&mut self.desired_healthy, other.desired_healthy);
48 crate::merge_strategies::map::granular(&mut self.disrupted_pods, other.disrupted_pods, |current_item, other_item| {
49 crate::DeepMerge::merge_from(current_item, other_item);
50 });
51 crate::DeepMerge::merge_from(&mut self.disruptions_allowed, other.disruptions_allowed);
52 crate::DeepMerge::merge_from(&mut self.expected_pods, other.expected_pods);
53 crate::DeepMerge::merge_from(&mut self.observed_generation, other.observed_generation);
54 }
55}
56
57impl<'de> crate::serde::Deserialize<'de> for PodDisruptionBudgetStatus {
58 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
59 #[allow(non_camel_case_types)]
60 enum Field {
61 Key_conditions,
62 Key_current_healthy,
63 Key_desired_healthy,
64 Key_disrupted_pods,
65 Key_disruptions_allowed,
66 Key_expected_pods,
67 Key_observed_generation,
68 Other,
69 }
70
71 impl<'de> crate::serde::Deserialize<'de> for Field {
72 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
73 struct Visitor;
74
75 impl crate::serde::de::Visitor<'_> for Visitor {
76 type Value = Field;
77
78 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
79 f.write_str("field identifier")
80 }
81
82 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
83 Ok(match v {
84 "conditions" => Field::Key_conditions,
85 "currentHealthy" => Field::Key_current_healthy,
86 "desiredHealthy" => Field::Key_desired_healthy,
87 "disruptedPods" => Field::Key_disrupted_pods,
88 "disruptionsAllowed" => Field::Key_disruptions_allowed,
89 "expectedPods" => Field::Key_expected_pods,
90 "observedGeneration" => Field::Key_observed_generation,
91 _ => Field::Other,
92 })
93 }
94 }
95
96 deserializer.deserialize_identifier(Visitor)
97 }
98 }
99
100 struct Visitor;
101
102 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
103 type Value = PodDisruptionBudgetStatus;
104
105 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
106 f.write_str("PodDisruptionBudgetStatus")
107 }
108
109 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
110 let mut value_conditions: Option<std::vec::Vec<crate::apimachinery::pkg::apis::meta::v1::Condition>> = None;
111 let mut value_current_healthy: Option<i32> = None;
112 let mut value_desired_healthy: Option<i32> = None;
113 let mut value_disrupted_pods: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::apis::meta::v1::Time>> = None;
114 let mut value_disruptions_allowed: Option<i32> = None;
115 let mut value_expected_pods: Option<i32> = None;
116 let mut value_observed_generation: Option<i64> = None;
117
118 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
119 match key {
120 Field::Key_conditions => value_conditions = crate::serde::de::MapAccess::next_value(&mut map)?,
121 Field::Key_current_healthy => value_current_healthy = crate::serde::de::MapAccess::next_value(&mut map)?,
122 Field::Key_desired_healthy => value_desired_healthy = crate::serde::de::MapAccess::next_value(&mut map)?,
123 Field::Key_disrupted_pods => value_disrupted_pods = crate::serde::de::MapAccess::next_value(&mut map)?,
124 Field::Key_disruptions_allowed => value_disruptions_allowed = crate::serde::de::MapAccess::next_value(&mut map)?,
125 Field::Key_expected_pods => value_expected_pods = crate::serde::de::MapAccess::next_value(&mut map)?,
126 Field::Key_observed_generation => value_observed_generation = crate::serde::de::MapAccess::next_value(&mut map)?,
127 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
128 }
129 }
130
131 Ok(PodDisruptionBudgetStatus {
132 conditions: value_conditions,
133 current_healthy: value_current_healthy.unwrap_or_default(),
134 desired_healthy: value_desired_healthy.unwrap_or_default(),
135 disrupted_pods: value_disrupted_pods,
136 disruptions_allowed: value_disruptions_allowed.unwrap_or_default(),
137 expected_pods: value_expected_pods.unwrap_or_default(),
138 observed_generation: value_observed_generation,
139 })
140 }
141 }
142
143 deserializer.deserialize_struct(
144 "PodDisruptionBudgetStatus",
145 &[
146 "conditions",
147 "currentHealthy",
148 "desiredHealthy",
149 "disruptedPods",
150 "disruptionsAllowed",
151 "expectedPods",
152 "observedGeneration",
153 ],
154 Visitor,
155 )
156 }
157}
158
159impl crate::serde::Serialize for PodDisruptionBudgetStatus {
160 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
161 let mut state = serializer.serialize_struct(
162 "PodDisruptionBudgetStatus",
163 4 +
164 self.conditions.as_ref().map_or(0, |_| 1) +
165 self.disrupted_pods.as_ref().map_or(0, |_| 1) +
166 self.observed_generation.as_ref().map_or(0, |_| 1),
167 )?;
168 if let Some(value) = &self.conditions {
169 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "conditions", value)?;
170 }
171 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "currentHealthy", &self.current_healthy)?;
172 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "desiredHealthy", &self.desired_healthy)?;
173 if let Some(value) = &self.disrupted_pods {
174 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "disruptedPods", value)?;
175 }
176 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "disruptionsAllowed", &self.disruptions_allowed)?;
177 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "expectedPods", &self.expected_pods)?;
178 if let Some(value) = &self.observed_generation {
179 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "observedGeneration", value)?;
180 }
181 crate::serde::ser::SerializeStruct::end(state)
182 }
183}
184
185#[cfg(feature = "schemars")]
186impl crate::schemars::JsonSchema for PodDisruptionBudgetStatus {
187 fn schema_name() -> std::string::String {
188 "io.k8s.api.policy.v1.PodDisruptionBudgetStatus".into()
189 }
190
191 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
192 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
193 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
194 description: Some("PodDisruptionBudgetStatus represents information about the status of a PodDisruptionBudget. Status may trail the actual state of a system.".into()),
195 ..Default::default()
196 })),
197 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
198 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
199 properties: [
200 (
201 "conditions".into(),
202 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
203 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
204 description: Some("Conditions contain conditions for PDB. The disruption controller sets the DisruptionAllowed condition. The following are known values for the reason field (additional reasons could be added in the future): - SyncFailed: The controller encountered an error and wasn't able to compute\n the number of allowed disruptions. Therefore no disruptions are\n allowed and the status of the condition will be False.\n- InsufficientPods: The number of pods are either at or below the number\n required by the PodDisruptionBudget. No disruptions are\n allowed and the status of the condition will be False.\n- SufficientPods: There are more pods than required by the PodDisruptionBudget.\n The condition will be True, and the number of allowed\n disruptions are provided by the disruptionsAllowed property.".into()),
205 ..Default::default()
206 })),
207 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
208 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
209 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::Condition>()))),
210 ..Default::default()
211 })),
212 ..Default::default()
213 }),
214 ),
215 (
216 "currentHealthy".into(),
217 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
218 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
219 description: Some("current number of healthy pods".into()),
220 ..Default::default()
221 })),
222 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
223 format: Some("int32".into()),
224 ..Default::default()
225 }),
226 ),
227 (
228 "desiredHealthy".into(),
229 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
230 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
231 description: Some("minimum desired number of healthy pods".into()),
232 ..Default::default()
233 })),
234 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
235 format: Some("int32".into()),
236 ..Default::default()
237 }),
238 ),
239 (
240 "disruptedPods".into(),
241 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
242 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
243 description: Some("DisruptedPods contains information about pods whose eviction was processed by the API server eviction subresource handler but has not yet been observed by the PodDisruptionBudget controller. A pod will be in this map from the time when the API server processed the eviction request to the time when the pod is seen by PDB controller as having been marked for deletion (or after a timeout). The key in the map is the name of the pod and the value is the time when the API server processed the eviction request. If the deletion didn't occur and a pod is still there it will be removed from the list automatically by PodDisruptionBudget controller after some time. If everything goes smooth this map should be empty for the most of the time. Large number of entries in the map may indicate problems with pod deletions.".into()),
244 ..Default::default()
245 })),
246 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
247 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
248 additional_properties: Some(std::boxed::Box::new(__gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::Time>())),
249 ..Default::default()
250 })),
251 ..Default::default()
252 }),
253 ),
254 (
255 "disruptionsAllowed".into(),
256 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
257 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
258 description: Some("Number of pod disruptions that are currently allowed.".into()),
259 ..Default::default()
260 })),
261 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
262 format: Some("int32".into()),
263 ..Default::default()
264 }),
265 ),
266 (
267 "expectedPods".into(),
268 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
269 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
270 description: Some("total number of pods counted by this disruption budget".into()),
271 ..Default::default()
272 })),
273 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
274 format: Some("int32".into()),
275 ..Default::default()
276 }),
277 ),
278 (
279 "observedGeneration".into(),
280 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
281 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
282 description: Some("Most recent generation observed when updating this PDB status. DisruptionsAllowed and other status information is valid only if observedGeneration equals to PDB's object generation.".into()),
283 ..Default::default()
284 })),
285 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
286 format: Some("int64".into()),
287 ..Default::default()
288 }),
289 ),
290 ].into(),
291 required: [
292 "currentHealthy".into(),
293 "desiredHealthy".into(),
294 "disruptionsAllowed".into(),
295 "expectedPods".into(),
296 ].into(),
297 ..Default::default()
298 })),
299 ..Default::default()
300 })
301 }
302}