k8s_openapi_ext/get/
replica_set.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use super::*;

pub use condition::ReplicaSetConditionGetExt;

mod condition;

pub trait ReplicaSetGetExt {
    fn spec(&self) -> Option<&appsv1::ReplicaSetSpec>;
    fn status(&self) -> Option<&appsv1::ReplicaSetStatus>;

    fn min_ready_seconds(&self) -> Option<i32> {
        self.spec()?.min_ready_seconds
    }

    fn spec_replicas(&self) -> Option<i32> {
        self.spec()?.replicas
    }

    fn selector(&self) -> Option<&metav1::LabelSelector> {
        self.spec().map(|spec| &spec.selector)
    }

    fn template(&self) -> Option<&corev1::PodTemplateSpec> {
        self.spec()?.template.as_ref()
    }

    fn available_replicas(&self) -> Option<i32> {
        self.status()?.available_replicas
    }

    fn ready_replicas(&self) -> Option<i32> {
        self.status()?.ready_replicas
    }

    fn fully_labeled_replicas(&self) -> Option<i32> {
        self.status()?.fully_labeled_replicas
    }
    fn status_replicas(&self) -> Option<i32> {
        self.status().map(|status| status.replicas)
    }

    fn observed_generation(&self) -> Option<i64> {
        self.status()?.observed_generation
    }

    fn conditions(&self) -> Option<&[appsv1::ReplicaSetCondition]> {
        self.status()?.conditions.as_deref()
    }
}

impl ReplicaSetGetExt for appsv1::ReplicaSet {
    fn spec(&self) -> Option<&appsv1::ReplicaSetSpec> {
        self.spec.as_ref()
    }

    fn status(&self) -> Option<&appsv1::ReplicaSetStatus> {
        self.status.as_ref()
    }
}