kube_utils/data.rs
1//!Minimal data model to allow extraction of only useful information (for the purposes of this crate)
2
3#[derive(serde_derive::Deserialize)]
4///Common metadata for kubernetes objects
5pub struct Metadata {
6 ///Name of the pod within namespace
7 pub name: String,
8 #[serde(default)]
9 ///Namespace of the object. Can be empty for default namespace
10 pub namespace: String,
11 #[serde(default)]
12 ///Unique identifier of the object, unchanged once object is created.
13 ///
14 ///Normally it is UUID
15 pub uid: String,
16}
17
18#[derive(serde_derive::Deserialize)]
19///Container object definition
20pub struct Container {
21 ///Name of the container
22 pub name: String,
23 ///Image used by the container
24 pub image: String,
25}
26
27#[derive(Default, serde_derive::Deserialize)]
28///Pod spec
29pub struct PodSpec {
30 #[serde(default)]
31 ///List of containers within the pod. Always at least 1 in normal kubernetes deployment
32 pub containers: Vec<Container>,
33}
34
35#[derive(serde_derive::Deserialize)]
36///Container object definition
37pub struct ContainerStatus {
38 ///Unique identifier of the container
39 ///
40 ///It normally starts with `containerd://` in kubernetes cluster
41 pub container_id: String,
42 ///Name of the container
43 pub name: String,
44 ///Image used by the container
45 pub image: String,
46 ///Indicates container status to be ready or not
47 pub ready: bool,
48 ///Indicates restart count
49 pub restart_count: i32,
50}
51
52impl ContainerStatus {
53 #[inline]
54 ///Access unique id of container without type prefix
55 pub fn container_id_suffix(&self) -> &str {
56 let mut parts = self.container_id.split("://");
57 let type_or_not = parts.next().unwrap();
58 parts.next().unwrap_or(type_or_not)
59 }
60}
61
62#[derive(Default, serde_derive::Deserialize)]
63///Pod status
64pub struct PodStatus {
65 #[serde(default)]
66 ///Statuses of the containers within pod
67 pub container_statuses: Vec<ContainerStatus>,
68}
69
70#[derive(serde_derive::Deserialize)]
71///Pod object definition
72pub struct Pod {
73 ///Pod metadata
74 pub metadata: Metadata,
75 #[serde(default)]
76 ///Pod desired specification
77 pub spec: PodSpec,
78 #[serde(default)]
79 ///Pod current status
80 pub status: PodStatus,
81}