#
k8s_openapi/v1_35/api/policy/v1/
eviction.rs

    1// Generated from definition io.k8s.api.policy.v1.Eviction
    2
    3/// Eviction evicts a pod from its node subject to certain policies and safety constraints. This is a subresource of Pod.  A request to cause such an eviction is created by POSTing to .../pods/\<pod name\>/evictions.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct Eviction {
    6    /// DeleteOptions may be provided
    7    pub delete_options: Option<crate::apimachinery::pkg::apis::meta::v1::DeleteOptions>,
    8
    9    /// ObjectMeta describes the pod that is being evicted.
    10    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    11}
    12
    13impl crate::Resource for Eviction {
    14    const API_VERSION: &'static str = "policy/v1";
    15    const GROUP: &'static str = "policy";
    16    const KIND: &'static str = "Eviction";
    17    const VERSION: &'static str = "v1";
    18    const URL_PATH_SEGMENT: &'static str = "eviction";
    19    type Scope = crate::SubResourceScope;
    20}
    21
    22impl crate::Metadata for Eviction {
    23    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
    24
    25    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
    26        &self.metadata
    27    }
    28
    29    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
    30        &mut self.metadata
    31    }
    32}
    33
    34impl crate::DeepMerge for Eviction {
    35    fn merge_from(&mut self, other: Self) {
    36        crate::DeepMerge::merge_from(&mut self.delete_options, other.delete_options);
    37        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
    38    }
    39}
    40
    41impl<'de> crate::serde::Deserialize<'de> for Eviction {
    42    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    43        #[allow(non_camel_case_types)]
    44        enum Field {
    45            Key_api_version,
    46            Key_kind,
    47            Key_delete_options,
    48            Key_metadata,
    49            Other,
    50        }
    51
    52        impl<'de> crate::serde::Deserialize<'de> for Field {
    53            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    54                struct Visitor;
    55
    56                impl crate::serde::de::Visitor<'_> for Visitor {
    57                    type Value = Field;
    58
    59                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    60                        f.write_str("field identifier")
    61                    }
    62
    63                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    64                        Ok(match v {
    65                            "apiVersion" => Field::Key_api_version,
    66                            "kind" => Field::Key_kind,
    67                            "deleteOptions" => Field::Key_delete_options,
    68                            "metadata" => Field::Key_metadata,
    69                            _ => Field::Other,
    70                        })
    71                    }
    72                }
    73
    74                deserializer.deserialize_identifier(Visitor)
    75            }
    76        }
    77
    78        struct Visitor;
    79
    80        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    81            type Value = Eviction;
    82
    83            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    84                f.write_str(<Self::Value as crate::Resource>::KIND)
    85            }
    86
    87            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    88                let mut value_delete_options: Option<crate::apimachinery::pkg::apis::meta::v1::DeleteOptions> = None;
    89                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
    90
    91                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    92                    match key {
    93                        Field::Key_api_version => {
    94                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    95                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    96                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    97                            }
    98                        },
    99                        Field::Key_kind => {
    100                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    101                            if value_kind != <Self::Value as crate::Resource>::KIND {
    102                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    103                            }
    104                        },
    105                        Field::Key_delete_options => value_delete_options = crate::serde::de::MapAccess::next_value(&mut map)?,
    106                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
    107                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    108                    }
    109                }
    110
    111                Ok(Eviction {
    112                    delete_options: value_delete_options,
    113                    metadata: value_metadata.unwrap_or_default(),
    114                })
    115            }
    116        }
    117
    118        deserializer.deserialize_struct(
    119            <Self as crate::Resource>::KIND,
    120            &[
    121                "apiVersion",
    122                "kind",
    123                "deleteOptions",
    124                "metadata",
    125            ],
    126            Visitor,
    127        )
    128    }
    129}
    130
    131impl crate::serde::Serialize for Eviction {
    132    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    133        let mut state = serializer.serialize_struct(
    134            <Self as crate::Resource>::KIND,
    135            3 +
    136            self.delete_options.as_ref().map_or(0, |_| 1),
    137        )?;
    138        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
    139        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
    140        if let Some(value) = &self.delete_options {
    141            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deleteOptions", value)?;
    142        }
    143        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
    144        crate::serde::ser::SerializeStruct::end(state)
    145    }
    146}
    147
    148#[cfg(feature = "schemars")]
    149impl crate::schemars::JsonSchema for Eviction {
    150    fn schema_name() -> std::borrow::Cow<'static, str> {
    151        "io.k8s.api.policy.v1.Eviction".into()
    152    }
    153
    154    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    155        crate::schemars::json_schema!({
    156            "description": "Eviction evicts a pod from its node subject to certain policies and safety constraints. This is a subresource of Pod.  A request to cause such an eviction is created by POSTing to .../pods/<pod name>/evictions.",
    157            "type": "object",
    158            "properties": {
    159                "apiVersion": {
    160                    "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
    161                    "type": "string",
    162                },
    163                "deleteOptions": ({
    164                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::DeleteOptions>();
    165                    schema_obj.ensure_object().insert("description".into(), "DeleteOptions may be provided".into());
    166                    schema_obj
    167                }),
    168                "kind": {
    169                    "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
    170                    "type": "string",
    171                },
    172                "metadata": ({
    173                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    174                    schema_obj.ensure_object().insert("description".into(), "ObjectMeta describes the pod that is being evicted.".into());
    175                    schema_obj
    176                }),
    177            },
    178            "required": [
    179                "metadata",
    180            ],
    181        })
    182    }
    183}