1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ContainerStatus {
6 pub allocated_resources: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
8
9 pub container_id: Option<std::string::String>,
11
12 pub image: std::string::String,
14
15 pub image_id: std::string::String,
17
18 pub last_state: Option<crate::api::core::v1::ContainerState>,
20
21 pub name: std::string::String,
23
24 pub ready: bool,
28
29 pub resources: Option<crate::api::core::v1::ResourceRequirements>,
31
32 pub restart_count: i32,
34
35 pub started: Option<bool>,
37
38 pub state: Option<crate::api::core::v1::ContainerState>,
40
41 pub volume_mounts: Option<std::vec::Vec<crate::api::core::v1::VolumeMountStatus>>,
43}
44
45impl crate::DeepMerge for ContainerStatus {
46 fn merge_from(&mut self, other: Self) {
47 crate::merge_strategies::map::granular(&mut self.allocated_resources, other.allocated_resources, |current_item, other_item| {
48 crate::DeepMerge::merge_from(current_item, other_item);
49 });
50 crate::DeepMerge::merge_from(&mut self.container_id, other.container_id);
51 crate::DeepMerge::merge_from(&mut self.image, other.image);
52 crate::DeepMerge::merge_from(&mut self.image_id, other.image_id);
53 crate::DeepMerge::merge_from(&mut self.last_state, other.last_state);
54 crate::DeepMerge::merge_from(&mut self.name, other.name);
55 crate::DeepMerge::merge_from(&mut self.ready, other.ready);
56 crate::DeepMerge::merge_from(&mut self.resources, other.resources);
57 crate::DeepMerge::merge_from(&mut self.restart_count, other.restart_count);
58 crate::DeepMerge::merge_from(&mut self.started, other.started);
59 crate::DeepMerge::merge_from(&mut self.state, other.state);
60 crate::merge_strategies::list::map(
61 &mut self.volume_mounts,
62 other.volume_mounts,
63 &[|lhs, rhs| lhs.mount_path == rhs.mount_path],
64 |current_item, other_item| {
65 crate::DeepMerge::merge_from(current_item, other_item);
66 },
67 );
68 }
69}
70
71impl<'de> crate::serde::Deserialize<'de> for ContainerStatus {
72 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
73 #[allow(non_camel_case_types)]
74 enum Field {
75 Key_allocated_resources,
76 Key_container_id,
77 Key_image,
78 Key_image_id,
79 Key_last_state,
80 Key_name,
81 Key_ready,
82 Key_resources,
83 Key_restart_count,
84 Key_started,
85 Key_state,
86 Key_volume_mounts,
87 Other,
88 }
89
90 impl<'de> crate::serde::Deserialize<'de> for Field {
91 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
92 struct Visitor;
93
94 impl crate::serde::de::Visitor<'_> for Visitor {
95 type Value = Field;
96
97 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
98 f.write_str("field identifier")
99 }
100
101 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
102 Ok(match v {
103 "allocatedResources" => Field::Key_allocated_resources,
104 "containerID" => Field::Key_container_id,
105 "image" => Field::Key_image,
106 "imageID" => Field::Key_image_id,
107 "lastState" => Field::Key_last_state,
108 "name" => Field::Key_name,
109 "ready" => Field::Key_ready,
110 "resources" => Field::Key_resources,
111 "restartCount" => Field::Key_restart_count,
112 "started" => Field::Key_started,
113 "state" => Field::Key_state,
114 "volumeMounts" => Field::Key_volume_mounts,
115 _ => Field::Other,
116 })
117 }
118 }
119
120 deserializer.deserialize_identifier(Visitor)
121 }
122 }
123
124 struct Visitor;
125
126 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
127 type Value = ContainerStatus;
128
129 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
130 f.write_str("ContainerStatus")
131 }
132
133 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
134 let mut value_allocated_resources: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
135 let mut value_container_id: Option<std::string::String> = None;
136 let mut value_image: Option<std::string::String> = None;
137 let mut value_image_id: Option<std::string::String> = None;
138 let mut value_last_state: Option<crate::api::core::v1::ContainerState> = None;
139 let mut value_name: Option<std::string::String> = None;
140 let mut value_ready: Option<bool> = None;
141 let mut value_resources: Option<crate::api::core::v1::ResourceRequirements> = None;
142 let mut value_restart_count: Option<i32> = None;
143 let mut value_started: Option<bool> = None;
144 let mut value_state: Option<crate::api::core::v1::ContainerState> = None;
145 let mut value_volume_mounts: Option<std::vec::Vec<crate::api::core::v1::VolumeMountStatus>> = None;
146
147 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
148 match key {
149 Field::Key_allocated_resources => value_allocated_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
150 Field::Key_container_id => value_container_id = crate::serde::de::MapAccess::next_value(&mut map)?,
151 Field::Key_image => value_image = crate::serde::de::MapAccess::next_value(&mut map)?,
152 Field::Key_image_id => value_image_id = crate::serde::de::MapAccess::next_value(&mut map)?,
153 Field::Key_last_state => value_last_state = crate::serde::de::MapAccess::next_value(&mut map)?,
154 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
155 Field::Key_ready => value_ready = crate::serde::de::MapAccess::next_value(&mut map)?,
156 Field::Key_resources => value_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
157 Field::Key_restart_count => value_restart_count = crate::serde::de::MapAccess::next_value(&mut map)?,
158 Field::Key_started => value_started = crate::serde::de::MapAccess::next_value(&mut map)?,
159 Field::Key_state => value_state = crate::serde::de::MapAccess::next_value(&mut map)?,
160 Field::Key_volume_mounts => value_volume_mounts = crate::serde::de::MapAccess::next_value(&mut map)?,
161 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
162 }
163 }
164
165 Ok(ContainerStatus {
166 allocated_resources: value_allocated_resources,
167 container_id: value_container_id,
168 image: value_image.unwrap_or_default(),
169 image_id: value_image_id.unwrap_or_default(),
170 last_state: value_last_state,
171 name: value_name.unwrap_or_default(),
172 ready: value_ready.unwrap_or_default(),
173 resources: value_resources,
174 restart_count: value_restart_count.unwrap_or_default(),
175 started: value_started,
176 state: value_state,
177 volume_mounts: value_volume_mounts,
178 })
179 }
180 }
181
182 deserializer.deserialize_struct(
183 "ContainerStatus",
184 &[
185 "allocatedResources",
186 "containerID",
187 "image",
188 "imageID",
189 "lastState",
190 "name",
191 "ready",
192 "resources",
193 "restartCount",
194 "started",
195 "state",
196 "volumeMounts",
197 ],
198 Visitor,
199 )
200 }
201}
202
203impl crate::serde::Serialize for ContainerStatus {
204 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
205 let mut state = serializer.serialize_struct(
206 "ContainerStatus",
207 5 +
208 self.allocated_resources.as_ref().map_or(0, |_| 1) +
209 self.container_id.as_ref().map_or(0, |_| 1) +
210 self.last_state.as_ref().map_or(0, |_| 1) +
211 self.resources.as_ref().map_or(0, |_| 1) +
212 self.started.as_ref().map_or(0, |_| 1) +
213 self.state.as_ref().map_or(0, |_| 1) +
214 self.volume_mounts.as_ref().map_or(0, |_| 1),
215 )?;
216 if let Some(value) = &self.allocated_resources {
217 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocatedResources", value)?;
218 }
219 if let Some(value) = &self.container_id {
220 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "containerID", value)?;
221 }
222 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "image", &self.image)?;
223 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "imageID", &self.image_id)?;
224 if let Some(value) = &self.last_state {
225 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "lastState", value)?;
226 }
227 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
228 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "ready", &self.ready)?;
229 if let Some(value) = &self.resources {
230 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resources", value)?;
231 }
232 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "restartCount", &self.restart_count)?;
233 if let Some(value) = &self.started {
234 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "started", value)?;
235 }
236 if let Some(value) = &self.state {
237 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "state", value)?;
238 }
239 if let Some(value) = &self.volume_mounts {
240 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "volumeMounts", value)?;
241 }
242 crate::serde::ser::SerializeStruct::end(state)
243 }
244}
245
246#[cfg(feature = "schemars")]
247impl crate::schemars::JsonSchema for ContainerStatus {
248 fn schema_name() -> std::borrow::Cow<'static, str> {
249 "io.k8s.api.core.v1.ContainerStatus".into()
250 }
251
252 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
253 crate::schemars::json_schema!({
254 "description": "ContainerStatus contains details for the current status of this container.",
255 "type": "object",
256 "properties": {
257 "allocatedResources": {
258 "description": "AllocatedResources represents the compute resources allocated for this container by the node. Kubelet sets this value to Container.Resources.Requests upon successful pod admission and after successfully admitting desired pod resize.",
259 "type": "object",
260 "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
261 },
262 "containerID": {
263 "description": "ContainerID is the ID of the container in the format '<type>://<container_id>'. Where type is a container runtime identifier, returned from Version call of CRI API (for example \"containerd\").",
264 "type": "string",
265 },
266 "image": {
267 "description": "Image is the name of container image that the container is running. The container image may not match the image used in the PodSpec, as it may have been resolved by the runtime. More info: https://kubernetes.io/docs/concepts/containers/images.",
268 "type": "string",
269 },
270 "imageID": {
271 "description": "ImageID is the image ID of the container's image. The image ID may not match the image ID of the image used in the PodSpec, as it may have been resolved by the runtime.",
272 "type": "string",
273 },
274 "lastState": ({
275 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ContainerState>();
276 schema_obj.ensure_object().insert("description".into(), "LastTerminationState holds the last termination state of the container to help debug container crashes and restarts. This field is not populated if the container is still running and RestartCount is 0.".into());
277 schema_obj
278 }),
279 "name": {
280 "description": "Name is a DNS_LABEL representing the unique name of the container. Each container in a pod must have a unique name across all container types. Cannot be updated.",
281 "type": "string",
282 },
283 "ready": {
284 "description": "Ready specifies whether the container is currently passing its readiness check. The value will change as readiness probes keep executing. If no readiness probes are specified, this field defaults to true once the container is fully started (see Started field).\n\nThe value is typically used to determine whether a container is ready to accept traffic.",
285 "type": "boolean",
286 },
287 "resources": ({
288 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ResourceRequirements>();
289 schema_obj.ensure_object().insert("description".into(), "Resources represents the compute resource requests and limits that have been successfully enacted on the running container after it has been started or has been successfully resized.".into());
290 schema_obj
291 }),
292 "restartCount": {
293 "description": "RestartCount holds the number of times the container has been restarted. Kubelet makes an effort to always increment the value, but there are cases when the state may be lost due to node restarts and then the value may be reset to 0. The value is never negative.",
294 "type": "integer",
295 "format": "int32",
296 },
297 "started": {
298 "description": "Started indicates whether the container has finished its postStart lifecycle hook and passed its startup probe. Initialized as false, becomes true after startupProbe is considered successful. Resets to false when the container is restarted, or if kubelet loses state temporarily. In both cases, startup probes will run again. Is always true when no startupProbe is defined and container is running and has passed the postStart lifecycle hook. The null value must be treated the same as false.",
299 "type": "boolean",
300 },
301 "state": ({
302 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ContainerState>();
303 schema_obj.ensure_object().insert("description".into(), "State holds details about the container's current condition.".into());
304 schema_obj
305 }),
306 "volumeMounts": {
307 "description": "Status of volume mounts.",
308 "type": "array",
309 "items": (__gen.subschema_for::<crate::api::core::v1::VolumeMountStatus>()),
310 },
311 },
312 "required": [
313 "image",
314 "imageID",
315 "name",
316 "ready",
317 "restartCount",
318 ],
319 })
320 }
321}