k8s_openapi/v1_37/api/lifecycle/v1alpha1/
eviction.rs1#[derive(Clone, Debug, Default, PartialEq)]
13pub struct Eviction {
14 pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
20
21 pub spec: crate::api::lifecycle::v1alpha1::EvictionSpec,
23
24 pub status: Option<crate::api::lifecycle::v1alpha1::EvictionStatus>,
26}
27
28impl crate::Resource for Eviction {
29 const API_VERSION: &'static str = "lifecycle.k8s.io/v1alpha1";
30 const GROUP: &'static str = "lifecycle.k8s.io";
31 const KIND: &'static str = "Eviction";
32 const VERSION: &'static str = "v1alpha1";
33 const URL_PATH_SEGMENT: &'static str = "evictions";
34 type Scope = crate::NamespaceResourceScope;
35}
36
37impl crate::ListableResource for Eviction {
38 const LIST_KIND: &'static str = "EvictionList";
39}
40
41impl crate::Metadata for Eviction {
42 type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
43
44 fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
45 &self.metadata
46 }
47
48 fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
49 &mut self.metadata
50 }
51}
52
53impl crate::DeepMerge for Eviction {
54 fn merge_from(&mut self, other: Self) {
55 crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
56 crate::DeepMerge::merge_from(&mut self.spec, other.spec);
57 crate::DeepMerge::merge_from(&mut self.status, other.status);
58 }
59}
60
61impl<'de> crate::serde::Deserialize<'de> for Eviction {
62 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
63 #[allow(non_camel_case_types)]
64 enum Field {
65 Key_api_version,
66 Key_kind,
67 Key_metadata,
68 Key_spec,
69 Key_status,
70 Other,
71 }
72
73 impl<'de> crate::serde::Deserialize<'de> for Field {
74 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
75 struct Visitor;
76
77 impl crate::serde::de::Visitor<'_> for Visitor {
78 type Value = Field;
79
80 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
81 f.write_str("field identifier")
82 }
83
84 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
85 Ok(match v {
86 "apiVersion" => Field::Key_api_version,
87 "kind" => Field::Key_kind,
88 "metadata" => Field::Key_metadata,
89 "spec" => Field::Key_spec,
90 "status" => Field::Key_status,
91 _ => Field::Other,
92 })
93 }
94 }
95
96 deserializer.deserialize_identifier(Visitor)
97 }
98 }
99
100 struct Visitor;
101
102 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
103 type Value = Eviction;
104
105 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
106 f.write_str(<Self::Value as crate::Resource>::KIND)
107 }
108
109 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
110 let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
111 let mut value_spec: Option<crate::api::lifecycle::v1alpha1::EvictionSpec> = None;
112 let mut value_status: Option<crate::api::lifecycle::v1alpha1::EvictionStatus> = None;
113
114 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
115 match key {
116 Field::Key_api_version => {
117 let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
118 if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
119 return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
120 }
121 },
122 Field::Key_kind => {
123 let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
124 if value_kind != <Self::Value as crate::Resource>::KIND {
125 return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
126 }
127 },
128 Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
129 Field::Key_spec => value_spec = crate::serde::de::MapAccess::next_value(&mut map)?,
130 Field::Key_status => value_status = crate::serde::de::MapAccess::next_value(&mut map)?,
131 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
132 }
133 }
134
135 Ok(Eviction {
136 metadata: value_metadata.unwrap_or_default(),
137 spec: value_spec.unwrap_or_default(),
138 status: value_status,
139 })
140 }
141 }
142
143 deserializer.deserialize_struct(
144 <Self as crate::Resource>::KIND,
145 &[
146 "apiVersion",
147 "kind",
148 "metadata",
149 "spec",
150 "status",
151 ],
152 Visitor,
153 )
154 }
155}
156
157impl crate::serde::Serialize for Eviction {
158 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
159 let mut state = serializer.serialize_struct(
160 <Self as crate::Resource>::KIND,
161 4 +
162 self.status.as_ref().map_or(0, |_| 1),
163 )?;
164 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
165 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
166 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
167 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "spec", &self.spec)?;
168 if let Some(value) = &self.status {
169 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "status", value)?;
170 }
171 crate::serde::ser::SerializeStruct::end(state)
172 }
173}
174
175#[cfg(feature = "schemars")]
176impl crate::schemars::JsonSchema for Eviction {
177 fn schema_name() -> std::borrow::Cow<'static, str> {
178 "io.k8s.api.lifecycle.v1alpha1.Eviction".into()
179 }
180
181 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
182 crate::schemars::json_schema!({
183 "description": "Eviction initiates an eviction process, which 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. It manages the Eviction lifecycle. Requesters are preserved in .status.requesters even after they have withdrawn their request. If all requesters withdraw their eviction intent for a common target, the eviction will be canceled. Once all EvictionRequest corresponding to this Eviction .spec.target have been removed, this Eviction object will eventually be garbage collected.\n\nIf the target is a pod, the .status.targetResponders is populated from Pod's .spec.evictionResponders.\n\nResponders should observe and communicate through the .status to help with the eviction of the target when they see their state == Active in .status.targetResponders. ResponderStatus struct should then be periodically updated to indicate the progress or completion of the eviction process by each responder in .status.responders. If .status.responders[].heartbeatTime is not updated within the heartbeat deadline defined by the Eviction API (currently 20 minutes), the eviction is passed over to the next responder with a lower priority.\n\nIf there are no other responders and the target is a pod, the last default imperative-eviction.k8s.io/evictor responder with a priority of 100 will evict the pod using the imperative Eviction API (pods/<name>/eviction subresource).",
184 "type": "object",
185 "properties": {
186 "apiVersion": {
187 "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",
188 "type": "string",
189 },
190 "kind": {
191 "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",
192 "type": "string",
193 },
194 "metadata": ({
195 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
196 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. .metadata.name set by the evictionrequest-controller is purely informative and subject to change. .spec.target field should be used to identify the target precisesly.\n\nThe requester and responder names will be used as label keys and added to the labels of the eviction in one of the following formats: 1. acme.io/foo: \"requester\" 2. acme.io/foo: \"responder\" 3. acme.io/foo: \"requester-responder\"\n\nPlease see EvictionParticipantRole for available role label values.".into());
197 schema_obj
198 }),
199 "spec": ({
200 let mut schema_obj = __gen.subschema_for::<crate::api::lifecycle::v1alpha1::EvictionSpec>();
201 schema_obj.ensure_object().insert("description".into(), "spec defines the eviction specification. https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status".into());
202 schema_obj
203 }),
204 "status": ({
205 let mut schema_obj = __gen.subschema_for::<crate::api::lifecycle::v1alpha1::EvictionStatus>();
206 schema_obj.ensure_object().insert("description".into(), "status represents the most recently observed status of the eviction. Populated by responders and evictionrequest-controller. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status".into());
207 schema_obj
208 }),
209 },
210 "required": [
211 "metadata",
212 "spec",
213 ],
214 })
215 }
216}