1// Generated from definition io.k8s.api.policy.v1.PodDisruptionBudgetSpec
23/// PodDisruptionBudgetSpec is a description of a PodDisruptionBudget.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PodDisruptionBudgetSpec {
6/// 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".
7pub max_unavailable: Option<crate::apimachinery::pkg::util::intstr::IntOrString>,
89/// 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%".
10pub min_available: Option<crate::apimachinery::pkg::util::intstr::IntOrString>,
1112/// 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.
13pub selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
1415/// 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".
16 ///
17 /// Valid policies are IfHealthyBudget and AlwaysAllow. If no policy is specified, the default behavior will be used, which corresponds to the IfHealthyBudget policy.
18 ///
19 /// IfHealthyBudget 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.
20 ///
21 /// AlwaysAllow 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.
22 ///
23 /// Additional 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.
24pub unhealthy_pod_eviction_policy: Option<std::string::String>,
25}
2627impl crate::DeepMerge for PodDisruptionBudgetSpec {
28fn merge_from(&mut self, other: Self) {
29crate::DeepMerge::merge_from(&mut self.max_unavailable, other.max_unavailable);
30crate::DeepMerge::merge_from(&mut self.min_available, other.min_available);
31crate::DeepMerge::merge_from(&mut self.selector, other.selector);
32crate::DeepMerge::merge_from(&mut self.unhealthy_pod_eviction_policy, other.unhealthy_pod_eviction_policy);
33 }
34}
3536impl<'de> crate::serde::Deserialize<'de> for PodDisruptionBudgetSpec {
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_max_unavailable,
41 Key_min_available,
42 Key_selector,
43 Key_unhealthy_pod_eviction_policy,
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"maxUnavailable" => Field::Key_max_unavailable,
61"minAvailable" => Field::Key_min_available,
62"selector" => Field::Key_selector,
63"unhealthyPodEvictionPolicy" => Field::Key_unhealthy_pod_eviction_policy,
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 = PodDisruptionBudgetSpec;
7778fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
79 f.write_str("PodDisruptionBudgetSpec")
80 }
8182fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
83let mut value_max_unavailable: Option<crate::apimachinery::pkg::util::intstr::IntOrString> = None;
84let mut value_min_available: Option<crate::apimachinery::pkg::util::intstr::IntOrString> = None;
85let mut value_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
86let mut value_unhealthy_pod_eviction_policy: Option<std::string::String> = None;
8788while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
89match key {
90 Field::Key_max_unavailable => value_max_unavailable = crate::serde::de::MapAccess::next_value(&mut map)?,
91 Field::Key_min_available => value_min_available = crate::serde::de::MapAccess::next_value(&mut map)?,
92 Field::Key_selector => value_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
93 Field::Key_unhealthy_pod_eviction_policy => value_unhealthy_pod_eviction_policy = 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(PodDisruptionBudgetSpec {
99 max_unavailable: value_max_unavailable,
100 min_available: value_min_available,
101 selector: value_selector,
102 unhealthy_pod_eviction_policy: value_unhealthy_pod_eviction_policy,
103 })
104 }
105 }
106107 deserializer.deserialize_struct(
108"PodDisruptionBudgetSpec",
109&[
110"maxUnavailable",
111"minAvailable",
112"selector",
113"unhealthyPodEvictionPolicy",
114 ],
115 Visitor,
116 )
117 }
118}
119120impl crate::serde::Serialize for PodDisruptionBudgetSpec {
121fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
122let mut state = serializer.serialize_struct(
123"PodDisruptionBudgetSpec",
124self.max_unavailable.as_ref().map_or(0, |_| 1) +
125self.min_available.as_ref().map_or(0, |_| 1) +
126self.selector.as_ref().map_or(0, |_| 1) +
127self.unhealthy_pod_eviction_policy.as_ref().map_or(0, |_| 1),
128 )?;
129if let Some(value) = &self.max_unavailable {
130crate::serde::ser::SerializeStruct::serialize_field(&mut state, "maxUnavailable", value)?;
131 }
132if let Some(value) = &self.min_available {
133crate::serde::ser::SerializeStruct::serialize_field(&mut state, "minAvailable", value)?;
134 }
135if let Some(value) = &self.selector {
136crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selector", value)?;
137 }
138if let Some(value) = &self.unhealthy_pod_eviction_policy {
139crate::serde::ser::SerializeStruct::serialize_field(&mut state, "unhealthyPodEvictionPolicy", value)?;
140 }
141crate::serde::ser::SerializeStruct::end(state)
142 }
143}
144145#[cfg(feature = "schemars")]
146impl crate::schemars::JsonSchema for PodDisruptionBudgetSpec {
147fn schema_name() -> std::string::String {
148"io.k8s.api.policy.v1.PodDisruptionBudgetSpec".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("PodDisruptionBudgetSpec is a description of a PodDisruptionBudget.".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"maxUnavailable".into(),
162 {
163let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::util::intstr::IntOrString>().into_object();
164 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
165 description: Some("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()),
166 ..Default::default()
167 }));
168crate::schemars::schema::Schema::Object(schema_obj)
169 },
170 ),
171 (
172"minAvailable".into(),
173 {
174let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::util::intstr::IntOrString>().into_object();
175 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
176 description: Some("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()),
177 ..Default::default()
178 }));
179crate::schemars::schema::Schema::Object(schema_obj)
180 },
181 ),
182 (
183"selector".into(),
184 {
185let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>().into_object();
186 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
187 description: Some("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()),
188 ..Default::default()
189 }));
190crate::schemars::schema::Schema::Object(schema_obj)
191 },
192 ),
193 (
194"unhealthyPodEvictionPolicy".into(),
195crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
196 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
197 description: Some("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.".into()),
198 ..Default::default()
199 })),
200 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
201 ..Default::default()
202 }),
203 ),
204 ].into(),
205 ..Default::default()
206 })),
207 ..Default::default()
208 })
209 }
210}