k8s_openapi/v1_33/api/policy/v1/
pod_disruption_budget_spec.rs

1// Generated from definition io.k8s.api.policy.v1.PodDisruptionBudgetSpec
2
3/// 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".
7    pub max_unavailable: Option<crate::apimachinery::pkg::util::intstr::IntOrString>,
8
9    /// 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%".
10    pub min_available: Option<crate::apimachinery::pkg::util::intstr::IntOrString>,
11
12    /// 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.
13    pub selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
14
15    /// 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.
24    pub unhealthy_pod_eviction_policy: Option<std::string::String>,
25}
26
27impl crate::DeepMerge for PodDisruptionBudgetSpec {
28    fn merge_from(&mut self, other: Self) {
29        crate::DeepMerge::merge_from(&mut self.max_unavailable, other.max_unavailable);
30        crate::DeepMerge::merge_from(&mut self.min_available, other.min_available);
31        crate::DeepMerge::merge_from(&mut self.selector, other.selector);
32        crate::DeepMerge::merge_from(&mut self.unhealthy_pod_eviction_policy, other.unhealthy_pod_eviction_policy);
33    }
34}
35
36impl<'de> crate::serde::Deserialize<'de> for PodDisruptionBudgetSpec {
37    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38        #[allow(non_camel_case_types)]
39        enum Field {
40            Key_max_unavailable,
41            Key_min_available,
42            Key_selector,
43            Key_unhealthy_pod_eviction_policy,
44            Other,
45        }
46
47        impl<'de> crate::serde::Deserialize<'de> for Field {
48            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
49                struct Visitor;
50
51                impl crate::serde::de::Visitor<'_> for Visitor {
52                    type Value = Field;
53
54                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
55                        f.write_str("field identifier")
56                    }
57
58                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
59                        Ok(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                }
68
69                deserializer.deserialize_identifier(Visitor)
70            }
71        }
72
73        struct Visitor;
74
75        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
76            type Value = PodDisruptionBudgetSpec;
77
78            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
79                f.write_str("PodDisruptionBudgetSpec")
80            }
81
82            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
83                let mut value_max_unavailable: Option<crate::apimachinery::pkg::util::intstr::IntOrString> = None;
84                let mut value_min_available: Option<crate::apimachinery::pkg::util::intstr::IntOrString> = None;
85                let mut value_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
86                let mut value_unhealthy_pod_eviction_policy: Option<std::string::String> = None;
87
88                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
89                    match 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                }
97
98                Ok(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        }
106
107        deserializer.deserialize_struct(
108            "PodDisruptionBudgetSpec",
109            &[
110                "maxUnavailable",
111                "minAvailable",
112                "selector",
113                "unhealthyPodEvictionPolicy",
114            ],
115            Visitor,
116        )
117    }
118}
119
120impl crate::serde::Serialize for PodDisruptionBudgetSpec {
121    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
122        let mut state = serializer.serialize_struct(
123            "PodDisruptionBudgetSpec",
124            self.max_unavailable.as_ref().map_or(0, |_| 1) +
125            self.min_available.as_ref().map_or(0, |_| 1) +
126            self.selector.as_ref().map_or(0, |_| 1) +
127            self.unhealthy_pod_eviction_policy.as_ref().map_or(0, |_| 1),
128        )?;
129        if let Some(value) = &self.max_unavailable {
130            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "maxUnavailable", value)?;
131        }
132        if let Some(value) = &self.min_available {
133            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "minAvailable", value)?;
134        }
135        if let Some(value) = &self.selector {
136            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selector", value)?;
137        }
138        if let Some(value) = &self.unhealthy_pod_eviction_policy {
139            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "unhealthyPodEvictionPolicy", value)?;
140        }
141        crate::serde::ser::SerializeStruct::end(state)
142    }
143}
144
145#[cfg(feature = "schemars")]
146impl crate::schemars::JsonSchema for PodDisruptionBudgetSpec {
147    fn schema_name() -> std::string::String {
148        "io.k8s.api.policy.v1.PodDisruptionBudgetSpec".into()
149    }
150
151    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
152        crate::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                        {
163                            let 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                            }));
168                            crate::schemars::schema::Schema::Object(schema_obj)
169                        },
170                    ),
171                    (
172                        "minAvailable".into(),
173                        {
174                            let 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                            }));
179                            crate::schemars::schema::Schema::Object(schema_obj)
180                        },
181                    ),
182                    (
183                        "selector".into(),
184                        {
185                            let 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                            }));
190                            crate::schemars::schema::Schema::Object(schema_obj)
191                        },
192                    ),
193                    (
194                        "unhealthyPodEvictionPolicy".into(),
195                        crate::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}