Skip to main content

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    /// The PodTemplateSpec used to create Pods in the StatefulSet.
34    fn template(&self) -> Option<&corev1::PodTemplateSpec> {
35        self.spec().map(|spec| &spec.template)
36    }
37
38    /// Total number of available pods (ready for at least minReadySeconds) targeted by this statefulset.
39    fn available_replicas(&self) -> Option<i32> {
40        self.status()?.available_replicas
41    }
42
43    /// The count of hash collisions for the StatefulSet.
44    /// The StatefulSet controller uses this field as a collision avoidance mechanism
45    /// when it needs to create the name for the newest ControllerRevision.
46    fn collision_count(&self) -> Option<i32> {
47        self.status()?.collision_count
48    }
49
50    /// Represents the latest available observations of a statefulset’s current state.
51    fn conditions(&self) -> Option<&[appsv1::StatefulSetCondition]> {
52        self.status()?.conditions.as_deref()
53    }
54
55    /// The number of Pods created by the StatefulSet controller from the StatefulSet version indicated by `current_revision`.
56    fn current_replicas(&self) -> Option<i32> {
57        self.status()?.current_replicas
58    }
59
60    /// If not empty, indicates the version of the StatefulSet used to generate Pods in the sequence [0,currentReplicas).
61    fn current_revision(&self) -> Option<&str> {
62        self.status()?.current_revision.as_deref()
63    }
64
65    /// The most recent generation observed for this StatefulSet.
66    /// It corresponds to the StatefulSet’s generation, which is updated on mutation by the API Server.
67    fn observed_generation(&self) -> Option<i64> {
68        self.status()?.observed_generation
69    }
70
71    /// The number of pods created for this StatefulSet with a Ready Condition.
72    fn ready_replicas(&self) -> Option<i32> {
73        self.status()?.ready_replicas
74    }
75
76    /// The number of Pods created by the StatefulSet controller.
77    fn status_replicas(&self) -> i32 {
78        self.status()
79            .map(|status| status.replicas)
80            .unwrap_or_default()
81    }
82
83    /// If not empty, indicates the version of the StatefulSet used to generate Pods in the sequence [replicas-updatedReplicas,replicas)
84    fn update_revision(&self) -> Option<&str> {
85        self.status()?.update_revision.as_deref()
86    }
87
88    /// The number of Pods created by the StatefulSet controller from the StatefulSet version indicated by `update_revision`.
89    fn updated_replicas(&self) -> Option<i32> {
90        self.status()?.updated_replicas
91    }
92}
93
94impl StatefulSetGetExt for appsv1::StatefulSet {
95    fn spec(&self) -> Option<&appsv1::StatefulSetSpec> {
96        self.spec.as_ref()
97    }
98
99    fn status(&self) -> Option<&appsv1::StatefulSetStatus> {
100        self.status.as_ref()
101    }
102}