#
k8s_openapi/v1_35/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::borrow::Cow<'static, str> {
    148        "io.k8s.api.policy.v1.PodDisruptionBudgetSpec".into()
    149    }
    150
    151    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    152        crate::schemars::json_schema!({
    153            "description": "PodDisruptionBudgetSpec is a description of a PodDisruptionBudget.",
    154            "type": "object",
    155            "properties": {
    156                "maxUnavailable": ({
    157                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::util::intstr::IntOrString>();
    158                    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());
    159                    schema_obj
    160                }),
    161                "minAvailable": ({
    162                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::util::intstr::IntOrString>();
    163                    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());
    164                    schema_obj
    165                }),
    166                "selector": ({
    167                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>();
    168                    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());
    169                    schema_obj
    170                }),
    171                "unhealthyPodEvictionPolicy": {
    172                    "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.",
    173                    "type": "string",
    174                },
    175            },
    176        })
    177    }
    178}