k8s_openapi_ext/get/
container.rs

1use super::*;
2
3pub use ephemeral::EphemeralContainerGetExt;
4pub use state::ContainerStateTerminatedGetExt;
5pub use state::ContainerStateWaitingGetExt;
6pub use status::ContainerStatusGetExt;
7
8mod ephemeral;
9mod state;
10mod status;
11
12pub trait ContainerGetExt {
13    fn container(&self) -> &corev1::Container;
14
15    fn name(&self) -> &str {
16        self.container().name.as_str()
17    }
18
19    fn args(&self) -> Option<&[String]> {
20        self.container().args.as_deref()
21    }
22
23    fn image(&self) -> Option<&str> {
24        self.container().image.as_deref()
25    }
26
27    fn image_pull_policy(&self) -> Option<&str> {
28        self.container().image_pull_policy.as_deref()
29    }
30
31    fn ports(&self) -> Option<&[corev1::ContainerPort]> {
32        self.container().ports.as_deref()
33    }
34
35    fn liveness_probe(&self) -> Option<&corev1::Probe> {
36        self.container().liveness_probe.as_ref()
37    }
38
39    fn readiness_probe(&self) -> Option<&corev1::Probe> {
40        self.container().readiness_probe.as_ref()
41    }
42
43    fn startup_probe(&self) -> Option<&corev1::Probe> {
44        self.container().startup_probe.as_ref()
45    }
46
47    fn resources(&self) -> Option<&corev1::ResourceRequirements> {
48        self.container().resources.as_ref()
49    }
50
51    fn restart_policy(&self) -> Option<&str> {
52        self.container().restart_policy.as_deref()
53    }
54
55    fn security_context(&self) -> Option<&corev1::SecurityContext> {
56        self.container().security_context.as_ref()
57    }
58
59    fn working_dir(&self) -> Option<&str> {
60        self.container().working_dir.as_deref()
61    }
62
63    fn port_by_name(&self, name: impl AsRef<str>) -> Option<&corev1::ContainerPort> {
64        let name = name.as_ref();
65        self.ports()?
66            .iter()
67            .find(|port| port.name.as_deref() == Some(name))
68    }
69
70    fn is_restartable(&self) -> bool {
71        self.restart_policy() == Some("Always")
72    }
73}
74
75impl ContainerGetExt for corev1::Container {
76    #[inline(always)]
77    fn container(&self) -> &corev1::Container {
78        self
79    }
80}