k8s_openapi_ext/get/
statefulset.rs

1use super::*;
2
3pub trait StatefulSetGetExt {
4    fn spec(&self) -> Option<&appsv1::StatefulSetSpec>;
5
6    fn status(&self) -> Option<&appsv1::StatefulSetStatus>;
7
8    // From spec
9    fn ordinals(&self) -> Option<i32> {
10        self.spec()?.ordinals.as_ref()?.start
11    }
12
13    fn pod_management_policy(&self) -> Option<&str> {
14        self.spec()?.pod_management_policy.as_deref()
15    }
16
17    fn revision_history_limit(&self) -> Option<i32> {
18        self.spec()?.revision_history_limit
19    }
20
21    fn service_name(&self) -> Option<&str> {
22        self.spec()?.service_name.as_deref()
23    }
24
25    fn spec_replicas(&self) -> Option<i32> {
26        self.spec()?.replicas
27    }
28
29    fn min_ready_seconds(&self) -> Option<i32> {
30        self.spec()?.min_ready_seconds
31    }
32
33    /// Total number of available pods (ready for at least minReadySeconds) targeted by this statefulset.
34    fn available_replicas(&self) -> Option<i32> {
35        self.status()?.available_replicas
36    }
37
38    /// The count of hash collisions for the StatefulSet.
39    /// The StatefulSet controller uses this field as a collision avoidance mechanism
40    /// when it needs to create the name for the newest ControllerRevision.
41    fn collision_count(&self) -> Option<i32> {
42        self.status()?.collision_count
43    }
44
45    /// Represents the latest available observations of a statefulset’s current state.
46    fn conditions(&self) -> Option<&[appsv1::StatefulSetCondition]> {
47        self.status()?.conditions.as_deref()
48    }
49
50    /// The number of Pods created by the StatefulSet controller from the StatefulSet version indicated by `current_revision`.
51    fn current_replicas(&self) -> Option<i32> {
52        self.status()?.current_replicas
53    }
54
55    /// If not empty, indicates the version of the StatefulSet used to generate Pods in the sequence [0,currentReplicas).
56    fn current_revision(&self) -> Option<&str> {
57        self.status()?.current_revision.as_deref()
58    }
59
60    /// The most recent generation observed for this StatefulSet.
61    /// It corresponds to the StatefulSet’s generation, which is updated on mutation by the API Server.
62    fn observed_generation(&self) -> Option<i64> {
63        self.status()?.observed_generation
64    }
65
66    /// The number of pods created for this StatefulSet with a Ready Condition.
67    fn ready_replicas(&self) -> Option<i32> {
68        self.status()?.ready_replicas
69    }
70
71    /// The number of Pods created by the StatefulSet controller.
72    fn status_replicas(&self) -> i32 {
73        self.status()
74            .map(|status| status.replicas)
75            .unwrap_or_default()
76    }
77
78    /// If not empty, indicates the version of the StatefulSet used to generate Pods in the sequence [replicas-updatedReplicas,replicas)
79    fn update_revision(&self) -> Option<&str> {
80        self.status()?.update_revision.as_deref()
81    }
82
83    /// The number of Pods created by the StatefulSet controller from the StatefulSet version indicated by `update_revision`.
84    fn updated_replicas(&self) -> Option<i32> {
85        self.status()?.updated_replicas
86    }
87}
88
89impl StatefulSetGetExt for appsv1::StatefulSet {
90    fn spec(&self) -> Option<&appsv1::StatefulSetSpec> {
91        self.spec.as_ref()
92    }
93
94    fn status(&self) -> Option<&appsv1::StatefulSetStatus> {
95        self.status.as_ref()
96    }
97}