k8s_openapi_ext/get/
component.rs1use super::*;
2
3pub trait ComponentStatusGetExt {
4 const COMPONENT_CONDITION_HEALTHY: &str = "Healthy";
5
6 fn conditions(&self) -> Option<&[corev1::ComponentCondition]>;
7
8 fn condition(&self, r#type: &str) -> Option<&corev1::ComponentCondition> {
9 self.conditions()?
10 .iter()
11 .find(|condition| condition.type_ == r#type)
12 }
13
14 fn healthy(&self) -> Option<&corev1::ComponentCondition> {
15 self.condition(Self::COMPONENT_CONDITION_HEALTHY)
16 }
17}
18
19impl ComponentStatusGetExt for corev1::ComponentStatus {
20 fn conditions(&self) -> Option<&[corev1::ComponentCondition]> {
21 self.conditions.as_deref()
22 }
23}
24
25pub trait ComponentConditionGetExt {
26 fn status(&self) -> &str;
27 fn r#type(&self) -> &str;
28 fn message(&self) -> Option<&str>;
29 fn error(&self) -> Option<&str>;
30 fn is_true(&self) -> bool;
31}
32
33impl ComponentConditionGetExt for corev1::ComponentCondition {
34 fn status(&self) -> &str {
35 &self.status
36 }
37
38 fn r#type(&self) -> &str {
39 &self.type_
40 }
41
42 fn message(&self) -> Option<&str> {
43 self.message.as_deref()
44 }
45
46 fn error(&self) -> Option<&str> {
47 self.error.as_deref()
48 }
49
50 fn is_true(&self) -> bool {
51 self.status == "True"
52 }
53}