k8s_openapi/v1_35/api/core/v1/
container_status.rs

1// Generated from definition io.k8s.api.core.v1.ContainerStatus
2
3/// ContainerStatus contains details for the current status of this container.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ContainerStatus {
6    /// 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.
7    pub allocated_resources: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
8
9    /// AllocatedResourcesStatus represents the status of various resources allocated for this Pod.
10    pub allocated_resources_status: Option<std::vec::Vec<crate::api::core::v1::ResourceStatus>>,
11
12    /// 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").
13    pub container_id: Option<std::string::String>,
14
15    /// 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.
16    pub image: std::string::String,
17
18    /// 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.
19    pub image_id: std::string::String,
20
21    /// 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.
22    pub last_state: Option<crate::api::core::v1::ContainerState>,
23
24    /// 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.
25    pub name: std::string::String,
26
27    /// 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).
28    ///
29    /// The value is typically used to determine whether a container is ready to accept traffic.
30    pub ready: bool,
31
32    /// 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.
33    pub resources: Option<crate::api::core::v1::ResourceRequirements>,
34
35    /// 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.
36    pub restart_count: i32,
37
38    /// 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.
39    pub started: Option<bool>,
40
41    /// State holds details about the container's current condition.
42    pub state: Option<crate::api::core::v1::ContainerState>,
43
44    /// StopSignal reports the effective stop signal for this container
45    pub stop_signal: Option<std::string::String>,
46
47    /// User represents user identity information initially attached to the first process of the container
48    pub user: Option<crate::api::core::v1::ContainerUser>,
49
50    /// Status of volume mounts.
51    pub volume_mounts: Option<std::vec::Vec<crate::api::core::v1::VolumeMountStatus>>,
52}
53
54impl crate::DeepMerge for ContainerStatus {
55    fn merge_from(&mut self, other: Self) {
56        crate::merge_strategies::map::granular(&mut self.allocated_resources, other.allocated_resources, |current_item, other_item| {
57            crate::DeepMerge::merge_from(current_item, other_item);
58        });
59        crate::merge_strategies::list::map(
60            &mut self.allocated_resources_status,
61            other.allocated_resources_status,
62            &[|lhs, rhs| lhs.name == rhs.name],
63            |current_item, other_item| {
64                crate::DeepMerge::merge_from(current_item, other_item);
65            },
66        );
67        crate::DeepMerge::merge_from(&mut self.container_id, other.container_id);
68        crate::DeepMerge::merge_from(&mut self.image, other.image);
69        crate::DeepMerge::merge_from(&mut self.image_id, other.image_id);
70        crate::DeepMerge::merge_from(&mut self.last_state, other.last_state);
71        crate::DeepMerge::merge_from(&mut self.name, other.name);
72        crate::DeepMerge::merge_from(&mut self.ready, other.ready);
73        crate::DeepMerge::merge_from(&mut self.resources, other.resources);
74        crate::DeepMerge::merge_from(&mut self.restart_count, other.restart_count);
75        crate::DeepMerge::merge_from(&mut self.started, other.started);
76        crate::DeepMerge::merge_from(&mut self.state, other.state);
77        crate::DeepMerge::merge_from(&mut self.stop_signal, other.stop_signal);
78        crate::DeepMerge::merge_from(&mut self.user, other.user);
79        crate::merge_strategies::list::map(
80            &mut self.volume_mounts,
81            other.volume_mounts,
82            &[|lhs, rhs| lhs.mount_path == rhs.mount_path],
83            |current_item, other_item| {
84                crate::DeepMerge::merge_from(current_item, other_item);
85            },
86        );
87    }
88}
89
90impl<'de> crate::serde::Deserialize<'de> for ContainerStatus {
91    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
92        #[allow(non_camel_case_types)]
93        enum Field {
94            Key_allocated_resources,
95            Key_allocated_resources_status,
96            Key_container_id,
97            Key_image,
98            Key_image_id,
99            Key_last_state,
100            Key_name,
101            Key_ready,
102            Key_resources,
103            Key_restart_count,
104            Key_started,
105            Key_state,
106            Key_stop_signal,
107            Key_user,
108            Key_volume_mounts,
109            Other,
110        }
111
112        impl<'de> crate::serde::Deserialize<'de> for Field {
113            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
114                struct Visitor;
115
116                impl crate::serde::de::Visitor<'_> for Visitor {
117                    type Value = Field;
118
119                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
120                        f.write_str("field identifier")
121                    }
122
123                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
124                        Ok(match v {
125                            "allocatedResources" => Field::Key_allocated_resources,
126                            "allocatedResourcesStatus" => Field::Key_allocated_resources_status,
127                            "containerID" => Field::Key_container_id,
128                            "image" => Field::Key_image,
129                            "imageID" => Field::Key_image_id,
130                            "lastState" => Field::Key_last_state,
131                            "name" => Field::Key_name,
132                            "ready" => Field::Key_ready,
133                            "resources" => Field::Key_resources,
134                            "restartCount" => Field::Key_restart_count,
135                            "started" => Field::Key_started,
136                            "state" => Field::Key_state,
137                            "stopSignal" => Field::Key_stop_signal,
138                            "user" => Field::Key_user,
139                            "volumeMounts" => Field::Key_volume_mounts,
140                            _ => Field::Other,
141                        })
142                    }
143                }
144
145                deserializer.deserialize_identifier(Visitor)
146            }
147        }
148
149        struct Visitor;
150
151        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
152            type Value = ContainerStatus;
153
154            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
155                f.write_str("ContainerStatus")
156            }
157
158            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
159                let mut value_allocated_resources: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
160                let mut value_allocated_resources_status: Option<std::vec::Vec<crate::api::core::v1::ResourceStatus>> = None;
161                let mut value_container_id: Option<std::string::String> = None;
162                let mut value_image: Option<std::string::String> = None;
163                let mut value_image_id: Option<std::string::String> = None;
164                let mut value_last_state: Option<crate::api::core::v1::ContainerState> = None;
165                let mut value_name: Option<std::string::String> = None;
166                let mut value_ready: Option<bool> = None;
167                let mut value_resources: Option<crate::api::core::v1::ResourceRequirements> = None;
168                let mut value_restart_count: Option<i32> = None;
169                let mut value_started: Option<bool> = None;
170                let mut value_state: Option<crate::api::core::v1::ContainerState> = None;
171                let mut value_stop_signal: Option<std::string::String> = None;
172                let mut value_user: Option<crate::api::core::v1::ContainerUser> = None;
173                let mut value_volume_mounts: Option<std::vec::Vec<crate::api::core::v1::VolumeMountStatus>> = None;
174
175                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
176                    match key {
177                        Field::Key_allocated_resources => value_allocated_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
178                        Field::Key_allocated_resources_status => value_allocated_resources_status = crate::serde::de::MapAccess::next_value(&mut map)?,
179                        Field::Key_container_id => value_container_id = crate::serde::de::MapAccess::next_value(&mut map)?,
180                        Field::Key_image => value_image = crate::serde::de::MapAccess::next_value(&mut map)?,
181                        Field::Key_image_id => value_image_id = crate::serde::de::MapAccess::next_value(&mut map)?,
182                        Field::Key_last_state => value_last_state = crate::serde::de::MapAccess::next_value(&mut map)?,
183                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
184                        Field::Key_ready => value_ready = crate::serde::de::MapAccess::next_value(&mut map)?,
185                        Field::Key_resources => value_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
186                        Field::Key_restart_count => value_restart_count = crate::serde::de::MapAccess::next_value(&mut map)?,
187                        Field::Key_started => value_started = crate::serde::de::MapAccess::next_value(&mut map)?,
188                        Field::Key_state => value_state = crate::serde::de::MapAccess::next_value(&mut map)?,
189                        Field::Key_stop_signal => value_stop_signal = crate::serde::de::MapAccess::next_value(&mut map)?,
190                        Field::Key_user => value_user = crate::serde::de::MapAccess::next_value(&mut map)?,
191                        Field::Key_volume_mounts => value_volume_mounts = crate::serde::de::MapAccess::next_value(&mut map)?,
192                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
193                    }
194                }
195
196                Ok(ContainerStatus {
197                    allocated_resources: value_allocated_resources,
198                    allocated_resources_status: value_allocated_resources_status,
199                    container_id: value_container_id,
200                    image: value_image.unwrap_or_default(),
201                    image_id: value_image_id.unwrap_or_default(),
202                    last_state: value_last_state,
203                    name: value_name.unwrap_or_default(),
204                    ready: value_ready.unwrap_or_default(),
205                    resources: value_resources,
206                    restart_count: value_restart_count.unwrap_or_default(),
207                    started: value_started,
208                    state: value_state,
209                    stop_signal: value_stop_signal,
210                    user: value_user,
211                    volume_mounts: value_volume_mounts,
212                })
213            }
214        }
215
216        deserializer.deserialize_struct(
217            "ContainerStatus",
218            &[
219                "allocatedResources",
220                "allocatedResourcesStatus",
221                "containerID",
222                "image",
223                "imageID",
224                "lastState",
225                "name",
226                "ready",
227                "resources",
228                "restartCount",
229                "started",
230                "state",
231                "stopSignal",
232                "user",
233                "volumeMounts",
234            ],
235            Visitor,
236        )
237    }
238}
239
240impl crate::serde::Serialize for ContainerStatus {
241    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
242        let mut state = serializer.serialize_struct(
243            "ContainerStatus",
244            5 +
245            self.allocated_resources.as_ref().map_or(0, |_| 1) +
246            self.allocated_resources_status.as_ref().map_or(0, |_| 1) +
247            self.container_id.as_ref().map_or(0, |_| 1) +
248            self.last_state.as_ref().map_or(0, |_| 1) +
249            self.resources.as_ref().map_or(0, |_| 1) +
250            self.started.as_ref().map_or(0, |_| 1) +
251            self.state.as_ref().map_or(0, |_| 1) +
252            self.stop_signal.as_ref().map_or(0, |_| 1) +
253            self.user.as_ref().map_or(0, |_| 1) +
254            self.volume_mounts.as_ref().map_or(0, |_| 1),
255        )?;
256        if let Some(value) = &self.allocated_resources {
257            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocatedResources", value)?;
258        }
259        if let Some(value) = &self.allocated_resources_status {
260            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocatedResourcesStatus", value)?;
261        }
262        if let Some(value) = &self.container_id {
263            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "containerID", value)?;
264        }
265        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "image", &self.image)?;
266        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "imageID", &self.image_id)?;
267        if let Some(value) = &self.last_state {
268            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "lastState", value)?;
269        }
270        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
271        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "ready", &self.ready)?;
272        if let Some(value) = &self.resources {
273            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resources", value)?;
274        }
275        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "restartCount", &self.restart_count)?;
276        if let Some(value) = &self.started {
277            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "started", value)?;
278        }
279        if let Some(value) = &self.state {
280            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "state", value)?;
281        }
282        if let Some(value) = &self.stop_signal {
283            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "stopSignal", value)?;
284        }
285        if let Some(value) = &self.user {
286            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "user", value)?;
287        }
288        if let Some(value) = &self.volume_mounts {
289            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "volumeMounts", value)?;
290        }
291        crate::serde::ser::SerializeStruct::end(state)
292    }
293}
294
295#[cfg(feature = "schemars")]
296impl crate::schemars::JsonSchema for ContainerStatus {
297    fn schema_name() -> std::borrow::Cow<'static, str> {
298        "io.k8s.api.core.v1.ContainerStatus".into()
299    }
300
301    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
302        crate::schemars::json_schema!({
303            "description": "ContainerStatus contains details for the current status of this container.",
304            "type": "object",
305            "properties": {
306                "allocatedResources": {
307                    "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.",
308                    "type": "object",
309                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
310                },
311                "allocatedResourcesStatus": {
312                    "description": "AllocatedResourcesStatus represents the status of various resources allocated for this Pod.",
313                    "type": "array",
314                    "items": (__gen.subschema_for::<crate::api::core::v1::ResourceStatus>()),
315                },
316                "containerID": {
317                    "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\").",
318                    "type": "string",
319                },
320                "image": {
321                    "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.",
322                    "type": "string",
323                },
324                "imageID": {
325                    "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.",
326                    "type": "string",
327                },
328                "lastState": ({
329                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ContainerState>();
330                    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());
331                    schema_obj
332                }),
333                "name": {
334                    "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.",
335                    "type": "string",
336                },
337                "ready": {
338                    "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.",
339                    "type": "boolean",
340                },
341                "resources": ({
342                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ResourceRequirements>();
343                    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());
344                    schema_obj
345                }),
346                "restartCount": {
347                    "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.",
348                    "type": "integer",
349                    "format": "int32",
350                },
351                "started": {
352                    "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.",
353                    "type": "boolean",
354                },
355                "state": ({
356                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ContainerState>();
357                    schema_obj.ensure_object().insert("description".into(), "State holds details about the container's current condition.".into());
358                    schema_obj
359                }),
360                "stopSignal": {
361                    "description": "StopSignal reports the effective stop signal for this container",
362                    "type": "string",
363                },
364                "user": ({
365                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ContainerUser>();
366                    schema_obj.ensure_object().insert("description".into(), "User represents user identity information initially attached to the first process of the container".into());
367                    schema_obj
368                }),
369                "volumeMounts": {
370                    "description": "Status of volume mounts.",
371                    "type": "array",
372                    "items": (__gen.subschema_for::<crate::api::core::v1::VolumeMountStatus>()),
373                },
374            },
375            "required": [
376                "image",
377                "imageID",
378                "name",
379                "ready",
380                "restartCount",
381            ],
382        })
383    }
384}