k8s_openapi_ext/get/container/
status.rs1use super::*;
2
3pub trait ContainerStatusGetExt {
4 fn container_status(&self) -> &corev1::ContainerStatus;
5
6 fn name(&self) -> &str {
7 self.container_status().name.as_str()
8 }
9
10 fn allocated_resources(&self) -> Option<&BTreeMap<String, resource::Quantity>> {
11 self.container_status().allocated_resources.as_ref()
12 }
13
14 fn container_id(&self) -> Option<&str> {
15 self.container_status().container_id.as_deref()
16 }
17 fn image(&self) -> &str {
18 &self.container_status().image
19 }
20
21 fn image_id(&self) -> &str {
22 &self.container_status().image_id
23 }
24
25 fn last_state(&self) -> Option<&corev1::ContainerState> {
26 self.container_status().last_state.as_ref()
27 }
28
29 fn ready(&self) -> bool {
30 self.container_status().ready
31 }
32
33 fn resources(&self) -> Option<&corev1::ResourceRequirements> {
34 self.container_status().resources.as_ref()
35 }
36
37 fn restart_count(&self) -> i32 {
38 self.container_status().restart_count
39 }
40
41 fn started(&self) -> Option<bool> {
42 self.container_status().started
43 }
44
45 fn state(&self) -> Option<&corev1::ContainerState> {
46 self.container_status().state.as_ref()
47 }
48
49 fn running(&self) -> Option<&corev1::ContainerStateRunning> {
50 self.state()?.running.as_ref()
51 }
52
53 fn terminated(&self) -> Option<&corev1::ContainerStateTerminated> {
54 self.state()?.terminated.as_ref()
55 }
56
57 fn waiting(&self) -> Option<&corev1::ContainerStateWaiting> {
58 self.state()?.waiting.as_ref()
59 }
60
61 fn terminated_reason(&self) -> Option<String> {
62 self.terminated()
63 .map(|terminated| terminated.access_reason())
64 }
65
66 fn waiting_reason(&self) -> Option<&str> {
67 self.waiting()?.reason.as_deref()
68 }
69
70 openapi::k8s_if_ge_1_31! {
71 fn allocated_resources_status(&self) -> Option<&[corev1::ResourceStatus]> {
72 self.container_status().allocated_resources_status.as_deref()
73 }
74 fn user(&self) -> Option<&corev1::ContainerUser> {
75 self.container_status().user.as_ref()
76 }
77
78 fn volume_mounts(&self) -> Option<&[corev1::VolumeMountStatus]> {
79 self.container_status().volume_mounts.as_deref()
80 }
81 }
82}
83
84impl ContainerStatusGetExt for corev1::ContainerStatus {
85 #[inline(always)]
86 fn container_status(&self) -> &corev1::ContainerStatus {
87 self
88 }
89}