Skip to main content

k8s_openapi/v1_37/api/lifecycle/v1alpha1/
eviction_request.rs

1// Generated from definition io.k8s.api.lifecycle.v1alpha1.EvictionRequest
2
3/// EvictionRequest defines a request that should ideally result in a graceful eviction of a .spec.target (e.g. termination of a pod).
4///
5/// The evictionrequest-controller observes intents of all EvictionRequests and transforms them into Evictions.
6///   - .spec.requester is set as a label on the Eviction for easier lookup.
7///   - Each target can have a set of responders assigned to it. Eviction objects are observed by
8///     these responders, who implement the eviction logic and update the Eviction's status with
9///     progress.
10///
11/// There is many-to-many relationship between EvictionRequests and Evictions in general. And many-to-one if the target is a  pod.
12///
13/// If all requesters withdraw their eviction intent for a common target, the eviction will be canceled. Deleting an EvictionRequest also counts as a withdrawal. Once all EvictionRequest of a target are removed, the corresponding Evictions are eventually garbage collected.
14#[derive(Clone, Debug, Default, PartialEq)]
15pub struct EvictionRequest {
16    /// metadata is the standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.
17    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
18
19    /// spec defines the eviction request specification. https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
20    pub spec: crate::api::lifecycle::v1alpha1::EvictionRequestSpec,
21
22    /// status represents the most recently observed status of the eviction request. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
23    pub status: Option<crate::api::lifecycle::v1alpha1::EvictionRequestStatus>,
24}
25
26impl crate::Resource for EvictionRequest {
27    const API_VERSION: &'static str = "lifecycle.k8s.io/v1alpha1";
28    const GROUP: &'static str = "lifecycle.k8s.io";
29    const KIND: &'static str = "EvictionRequest";
30    const VERSION: &'static str = "v1alpha1";
31    const URL_PATH_SEGMENT: &'static str = "evictionrequests";
32    type Scope = crate::NamespaceResourceScope;
33}
34
35impl crate::ListableResource for EvictionRequest {
36    const LIST_KIND: &'static str = "EvictionRequestList";
37}
38
39impl crate::Metadata for EvictionRequest {
40    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
41
42    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
43        &self.metadata
44    }
45
46    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
47        &mut self.metadata
48    }
49}
50
51impl crate::DeepMerge for EvictionRequest {
52    fn merge_from(&mut self, other: Self) {
53        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
54        crate::DeepMerge::merge_from(&mut self.spec, other.spec);
55        crate::DeepMerge::merge_from(&mut self.status, other.status);
56    }
57}
58
59impl<'de> crate::serde::Deserialize<'de> for EvictionRequest {
60    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
61        #[allow(non_camel_case_types)]
62        enum Field {
63            Key_api_version,
64            Key_kind,
65            Key_metadata,
66            Key_spec,
67            Key_status,
68            Other,
69        }
70
71        impl<'de> crate::serde::Deserialize<'de> for Field {
72            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
73                struct Visitor;
74
75                impl crate::serde::de::Visitor<'_> for Visitor {
76                    type Value = Field;
77
78                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
79                        f.write_str("field identifier")
80                    }
81
82                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
83                        Ok(match v {
84                            "apiVersion" => Field::Key_api_version,
85                            "kind" => Field::Key_kind,
86                            "metadata" => Field::Key_metadata,
87                            "spec" => Field::Key_spec,
88                            "status" => Field::Key_status,
89                            _ => Field::Other,
90                        })
91                    }
92                }
93
94                deserializer.deserialize_identifier(Visitor)
95            }
96        }
97
98        struct Visitor;
99
100        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
101            type Value = EvictionRequest;
102
103            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
104                f.write_str(<Self::Value as crate::Resource>::KIND)
105            }
106
107            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
108                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
109                let mut value_spec: Option<crate::api::lifecycle::v1alpha1::EvictionRequestSpec> = None;
110                let mut value_status: Option<crate::api::lifecycle::v1alpha1::EvictionRequestStatus> = None;
111
112                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
113                    match key {
114                        Field::Key_api_version => {
115                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
116                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
117                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
118                            }
119                        },
120                        Field::Key_kind => {
121                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
122                            if value_kind != <Self::Value as crate::Resource>::KIND {
123                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
124                            }
125                        },
126                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
127                        Field::Key_spec => value_spec = crate::serde::de::MapAccess::next_value(&mut map)?,
128                        Field::Key_status => value_status = crate::serde::de::MapAccess::next_value(&mut map)?,
129                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
130                    }
131                }
132
133                Ok(EvictionRequest {
134                    metadata: value_metadata.unwrap_or_default(),
135                    spec: value_spec.unwrap_or_default(),
136                    status: value_status,
137                })
138            }
139        }
140
141        deserializer.deserialize_struct(
142            <Self as crate::Resource>::KIND,
143            &[
144                "apiVersion",
145                "kind",
146                "metadata",
147                "spec",
148                "status",
149            ],
150            Visitor,
151        )
152    }
153}
154
155impl crate::serde::Serialize for EvictionRequest {
156    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
157        let mut state = serializer.serialize_struct(
158            <Self as crate::Resource>::KIND,
159            4 +
160            self.status.as_ref().map_or(0, |_| 1),
161        )?;
162        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
163        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
164        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
165        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "spec", &self.spec)?;
166        if let Some(value) = &self.status {
167            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "status", value)?;
168        }
169        crate::serde::ser::SerializeStruct::end(state)
170    }
171}
172
173#[cfg(feature = "schemars")]
174impl crate::schemars::JsonSchema for EvictionRequest {
175    fn schema_name() -> std::borrow::Cow<'static, str> {
176        "io.k8s.api.lifecycle.v1alpha1.EvictionRequest".into()
177    }
178
179    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
180        crate::schemars::json_schema!({
181            "description": "EvictionRequest defines a request that should ideally result in a graceful eviction of a .spec.target (e.g. termination of a pod).\n\nThe evictionrequest-controller observes intents of all EvictionRequests and transforms them into Evictions.\n  - .spec.requester is set as a label on the Eviction for easier lookup.\n  - Each target can have a set of responders assigned to it. Eviction objects are observed by\n    these responders, who implement the eviction logic and update the Eviction's status with\n    progress.\n\nThere is many-to-many relationship between EvictionRequests and Evictions in general. And many-to-one if the target is a  pod.\n\nIf all requesters withdraw their eviction intent for a common target, the eviction will be canceled. Deleting an EvictionRequest also counts as a withdrawal. Once all EvictionRequest of a target are removed, the corresponding Evictions are eventually garbage collected.",
182            "type": "object",
183            "properties": {
184                "apiVersion": {
185                    "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",
186                    "type": "string",
187                },
188                "kind": {
189                    "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",
190                    "type": "string",
191                },
192                "metadata": ({
193                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
194                    schema_obj.ensure_object().insert("description".into(), "metadata is the standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.".into());
195                    schema_obj
196                }),
197                "spec": ({
198                    let mut schema_obj = __gen.subschema_for::<crate::api::lifecycle::v1alpha1::EvictionRequestSpec>();
199                    schema_obj.ensure_object().insert("description".into(), "spec defines the eviction request specification. https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status".into());
200                    schema_obj
201                }),
202                "status": ({
203                    let mut schema_obj = __gen.subschema_for::<crate::api::lifecycle::v1alpha1::EvictionRequestStatus>();
204                    schema_obj.ensure_object().insert("description".into(), "status represents the most recently observed status of the eviction request. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status".into());
205                    schema_obj
206                }),
207            },
208            "required": [
209                "metadata",
210                "spec",
211            ],
212        })
213    }
214}