k8s_openapi/v1_30/api/policy/v1/
pod_disruption_budget_spec.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PodDisruptionBudgetSpec {
6 pub max_unavailable: Option<crate::apimachinery::pkg::util::intstr::IntOrString>,
8
9 pub min_available: Option<crate::apimachinery::pkg::util::intstr::IntOrString>,
11
12 pub selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
14
15 pub unhealthy_pod_eviction_policy: Option<std::string::String>,
27}
28
29impl crate::DeepMerge for PodDisruptionBudgetSpec {
30 fn merge_from(&mut self, other: Self) {
31 crate::DeepMerge::merge_from(&mut self.max_unavailable, other.max_unavailable);
32 crate::DeepMerge::merge_from(&mut self.min_available, other.min_available);
33 crate::DeepMerge::merge_from(&mut self.selector, other.selector);
34 crate::DeepMerge::merge_from(&mut self.unhealthy_pod_eviction_policy, other.unhealthy_pod_eviction_policy);
35 }
36}
37
38impl<'de> crate::serde::Deserialize<'de> for PodDisruptionBudgetSpec {
39 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
40 #[allow(non_camel_case_types)]
41 enum Field {
42 Key_max_unavailable,
43 Key_min_available,
44 Key_selector,
45 Key_unhealthy_pod_eviction_policy,
46 Other,
47 }
48
49 impl<'de> crate::serde::Deserialize<'de> for Field {
50 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
51 struct Visitor;
52
53 impl crate::serde::de::Visitor<'_> for Visitor {
54 type Value = Field;
55
56 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
57 f.write_str("field identifier")
58 }
59
60 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
61 Ok(match v {
62 "maxUnavailable" => Field::Key_max_unavailable,
63 "minAvailable" => Field::Key_min_available,
64 "selector" => Field::Key_selector,
65 "unhealthyPodEvictionPolicy" => Field::Key_unhealthy_pod_eviction_policy,
66 _ => Field::Other,
67 })
68 }
69 }
70
71 deserializer.deserialize_identifier(Visitor)
72 }
73 }
74
75 struct Visitor;
76
77 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
78 type Value = PodDisruptionBudgetSpec;
79
80 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
81 f.write_str("PodDisruptionBudgetSpec")
82 }
83
84 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
85 let mut value_max_unavailable: Option<crate::apimachinery::pkg::util::intstr::IntOrString> = None;
86 let mut value_min_available: Option<crate::apimachinery::pkg::util::intstr::IntOrString> = None;
87 let mut value_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
88 let mut value_unhealthy_pod_eviction_policy: Option<std::string::String> = None;
89
90 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
91 match key {
92 Field::Key_max_unavailable => value_max_unavailable = crate::serde::de::MapAccess::next_value(&mut map)?,
93 Field::Key_min_available => value_min_available = crate::serde::de::MapAccess::next_value(&mut map)?,
94 Field::Key_selector => value_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
95 Field::Key_unhealthy_pod_eviction_policy => value_unhealthy_pod_eviction_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
96 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
97 }
98 }
99
100 Ok(PodDisruptionBudgetSpec {
101 max_unavailable: value_max_unavailable,
102 min_available: value_min_available,
103 selector: value_selector,
104 unhealthy_pod_eviction_policy: value_unhealthy_pod_eviction_policy,
105 })
106 }
107 }
108
109 deserializer.deserialize_struct(
110 "PodDisruptionBudgetSpec",
111 &[
112 "maxUnavailable",
113 "minAvailable",
114 "selector",
115 "unhealthyPodEvictionPolicy",
116 ],
117 Visitor,
118 )
119 }
120}
121
122impl crate::serde::Serialize for PodDisruptionBudgetSpec {
123 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
124 let mut state = serializer.serialize_struct(
125 "PodDisruptionBudgetSpec",
126 self.max_unavailable.as_ref().map_or(0, |_| 1) +
127 self.min_available.as_ref().map_or(0, |_| 1) +
128 self.selector.as_ref().map_or(0, |_| 1) +
129 self.unhealthy_pod_eviction_policy.as_ref().map_or(0, |_| 1),
130 )?;
131 if let Some(value) = &self.max_unavailable {
132 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "maxUnavailable", value)?;
133 }
134 if let Some(value) = &self.min_available {
135 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "minAvailable", value)?;
136 }
137 if let Some(value) = &self.selector {
138 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selector", value)?;
139 }
140 if let Some(value) = &self.unhealthy_pod_eviction_policy {
141 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "unhealthyPodEvictionPolicy", value)?;
142 }
143 crate::serde::ser::SerializeStruct::end(state)
144 }
145}
146
147#[cfg(feature = "schemars")]
148impl crate::schemars::JsonSchema for PodDisruptionBudgetSpec {
149 fn schema_name() -> std::borrow::Cow<'static, str> {
150 "io.k8s.api.policy.v1.PodDisruptionBudgetSpec".into()
151 }
152
153 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
154 crate::schemars::json_schema!({
155 "description": "PodDisruptionBudgetSpec is a description of a PodDisruptionBudget.",
156 "type": "object",
157 "properties": {
158 "maxUnavailable": ({
159 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::util::intstr::IntOrString>();
160 schema_obj.ensure_object().insert("description".into(), "An eviction is allowed if at most \"maxUnavailable\" pods selected by \"selector\" are unavailable after the eviction, i.e. even in absence of the evicted pod. For example, one can prevent all voluntary evictions by specifying 0. This is a mutually exclusive setting with \"minAvailable\".".into());
161 schema_obj
162 }),
163 "minAvailable": ({
164 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::util::intstr::IntOrString>();
165 schema_obj.ensure_object().insert("description".into(), "An eviction is allowed if at least \"minAvailable\" pods selected by \"selector\" will still be available after the eviction, i.e. even in the absence of the evicted pod. So for example you can prevent all voluntary evictions by specifying \"100%\".".into());
166 schema_obj
167 }),
168 "selector": ({
169 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>();
170 schema_obj.ensure_object().insert("description".into(), "Label query over pods whose evictions are managed by the disruption budget. A null selector will match no pods, while an empty ({}) selector will select all pods within the namespace.".into());
171 schema_obj
172 }),
173 "unhealthyPodEvictionPolicy": {
174 "description": "UnhealthyPodEvictionPolicy defines the criteria for when unhealthy pods should be considered for eviction. Current implementation considers healthy pods, as pods that have status.conditions item with type=\"Ready\",status=\"True\".\n\nValid policies are IfHealthyBudget and AlwaysAllow. If no policy is specified, the default behavior will be used, which corresponds to the IfHealthyBudget policy.\n\nIfHealthyBudget policy means that running pods (status.phase=\"Running\"), but not yet healthy can be evicted only if the guarded application is not disrupted (status.currentHealthy is at least equal to status.desiredHealthy). Healthy pods will be subject to the PDB for eviction.\n\nAlwaysAllow policy means that all running pods (status.phase=\"Running\"), but not yet healthy are considered disrupted and can be evicted regardless of whether the criteria in a PDB is met. This means perspective running pods of a disrupted application might not get a chance to become healthy. Healthy pods will be subject to the PDB for eviction.\n\nAdditional policies may be added in the future. Clients making eviction decisions should disallow eviction of unhealthy pods if they encounter an unrecognized policy in this field.\n\nThis field is beta-level. The eviction API uses this field when the feature gate PDBUnhealthyPodEvictionPolicy is enabled (enabled by default).",
175 "type": "string",
176 },
177 },
178 })
179 }
180}