k8s_openapi_ext/get/
pod.rs1use super::*;
2
3pub use condition::PodConditionGetExt;
4
5mod condition;
6
7pub trait PodGetExt {
8 #[deprecated(note = "Use corev1::PodCondition::POD_SCHEDULED instead")]
9 const POD_SCHEDULED: &str = "PodScheduled";
10
11 fn spec(&self) -> Option<&corev1::PodSpec>;
12
13 fn status(&self) -> Option<&corev1::PodStatus>;
14
15 fn containers(&self) -> Option<&[corev1::Container]> {
17 self.spec().map(|spec| spec.containers.as_ref())
18 }
19
20 fn ephemeral_containers(&self) -> Option<&[corev1::EphemeralContainer]> {
21 self.spec()?.ephemeral_containers.as_deref()
22 }
23
24 fn init_containers(&self) -> Option<&[corev1::Container]> {
25 self.spec()?.init_containers.as_deref()
26 }
27
28 fn node_selector(&self) -> Option<&BTreeMap<String, String>> {
29 self.spec()?.node_selector.as_ref()
30 }
31
32 fn resource_claims(&self) -> Option<&[corev1::PodResourceClaim]> {
33 self.spec()?.resource_claims.as_deref()
34 }
35
36 fn tolerations(&self) -> Option<&[corev1::Toleration]> {
37 self.spec()?.tolerations.as_deref()
38 }
39
40 fn readiness_gates(&self) -> Option<&[corev1::PodReadinessGate]> {
41 self.spec()?.readiness_gates.as_deref()
42 }
43
44 fn message(&self) -> Option<&str> {
46 self.status()?.message.as_deref()
47 }
48
49 fn phase(&self) -> Option<&str> {
50 self.status()?.phase.as_deref()
51 }
52
53 fn qos_class(&self) -> Option<&str> {
54 self.status()?.qos_class.as_deref()
55 }
56
57 fn reason(&self) -> Option<&str> {
58 self.status()?.reason.as_deref()
59 }
60
61 fn resize(&self) -> Option<&str> {
62 self.status()?.resize.as_deref()
63 }
64
65 fn conditions(&self) -> Option<&[corev1::PodCondition]> {
66 self.status()?.conditions.as_deref()
67 }
68
69 fn container_statuses(&self) -> Option<&[corev1::ContainerStatus]> {
70 self.status()?.container_statuses.as_deref()
71 }
72
73 fn ephemeral_container_statuses(&self) -> Option<&[corev1::ContainerStatus]> {
74 self.status()?.ephemeral_container_statuses.as_deref()
75 }
76
77 fn init_container_statuses(&self) -> Option<&[corev1::ContainerStatus]> {
78 self.status()?.init_container_statuses.as_deref()
79 }
80
81 fn nominated_node_name(&self) -> Option<&str> {
82 self.status()?.nominated_node_name.as_deref()
83 }
84
85 fn resource_claim_statuses(&self) -> Option<&[corev1::PodResourceClaimStatus]> {
86 self.status()?.resource_claim_statuses.as_deref()
87 }
88
89 fn host_ip(&self) -> Option<&str> {
90 self.status()?.host_ip.as_deref()
91 }
92
93 fn host_ips(&self) -> Option<&[corev1::HostIP]> {
94 self.status()?.host_ips.as_deref()
95 }
96
97 fn pod_ip(&self) -> Option<&str> {
98 self.status()?.pod_ip.as_deref()
99 }
100
101 fn pod_ips(&self) -> Option<&[corev1::PodIP]> {
102 self.status()?.pod_ips.as_deref()
103 }
104
105 fn start_time(&self) -> Option<&metav1::Time> {
106 self.status()?.start_time.as_ref()
107 }
108
109 fn condition(&self, type_: &str) -> Option<&corev1::PodCondition> {
110 self.conditions()?
111 .iter()
112 .find(|condition| condition.type_ == type_)
113 }
114
115 fn is_ready(&self) -> bool {
116 let gates = self
117 .readiness_gates()
118 .unwrap_or_default()
119 .iter()
120 .all(|gate| {
121 self.condition(&gate.condition_type)
122 .is_some_and(|condition| condition.is_true())
123 });
124
125 let ready = self
126 .condition(corev1::PodCondition::POD_READY)
127 .is_some_and(|condition| condition.is_true());
128
129 gates && ready
130 }
131
132 fn pod_scheduled_reason(&self) -> Option<&str> {
133 self.condition(corev1::PodCondition::POD_SCHEDULED)?
134 .reason()
135 }
136}
137
138impl PodGetExt for corev1::Pod {
139 fn spec(&self) -> Option<&corev1::PodSpec> {
140 self.spec.as_ref()
141 }
142
143 fn status(&self) -> Option<&corev1::PodStatus> {
144 self.status.as_ref()
145 }
146}
147
148impl PodGetExt for corev1::PodStatus {
149 fn spec(&self) -> Option<&corev1::PodSpec> {
150 None
151 }
152
153 fn status(&self) -> Option<&corev1::PodStatus> {
154 Some(self)
155 }
156}
157
158impl PodGetExt for corev1::PodTemplate {
159 fn spec(&self) -> Option<&corev1::PodSpec> {
160 self.template.as_ref()?.spec.as_ref()
161 }
162
163 fn status(&self) -> Option<&corev1::PodStatus> {
164 None
165 }
166}
167
168impl PodGetExt for corev1::PodTemplateSpec {
169 fn spec(&self) -> Option<&corev1::PodSpec> {
170 self.spec.as_ref()
171 }
172
173 fn status(&self) -> Option<&corev1::PodStatus> {
174 None
175 }
176}