k8s_openapi_ext/ext/
replica_set.rs1use super::*;
2
3pub trait ReplicaSetExt: super::ResourceBuilder {
4 fn new(name: impl ToString) -> Self;
5 fn with_labels(
6 name: impl ToString,
7 labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
8 ) -> Self;
9
10 fn spec(self, spec: appsv1::ReplicaSetSpec) -> Self;
11
12 fn min_ready_seconds(self, seconds: i32) -> Self;
13
14 fn replicas(self, replicas: i32) -> Self;
15
16 fn selector(self, selector: metav1::LabelSelector) -> Self;
17
18 fn match_labels(
19 self,
20 match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
21 ) -> Self;
22
23 fn template(self, template: corev1::PodTemplateSpec) -> Self;
24
25 fn pod_spec(self, pod: corev1::PodSpec) -> Self;
26}
27
28impl ReplicaSetExt for appsv1::ReplicaSet {
29 fn new(name: impl ToString) -> Self {
30 let metadata = metadata(name);
31 Self {
32 metadata,
33 ..default()
36 }
37 }
38
39 fn with_labels(
40 name: impl ToString,
41 labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
42 ) -> Self {
43 Self::new(name).labels(labels)
44 }
45
46 fn spec(self, spec: appsv1::ReplicaSetSpec) -> Self {
47 Self {
48 spec: Some(spec),
49 ..self
50 }
51 }
52
53 fn min_ready_seconds(mut self, seconds: i32) -> Self {
54 self.spec_mut().min_ready_seconds.replace(seconds);
55 self
56 }
57
58 fn replicas(mut self, replicas: i32) -> Self {
59 self.spec_mut().replicas.replace(replicas);
60 self
61 }
62
63 fn selector(mut self, selector: metav1::LabelSelector) -> Self {
64 self.spec_mut().selector = selector;
65 self
66 }
67
68 fn match_labels(
69 self,
70 match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
71 ) -> Self {
72 let mut spec = self.spec.unwrap_or_default();
73 spec.selector = spec.selector.match_labels(match_labels);
74 Self {
75 spec: Some(spec),
76 ..self
77 }
78 }
79
80 fn template(mut self, template: corev1::PodTemplateSpec) -> Self {
81 self.spec_mut().template.replace(template);
82 self
83 }
84
85 fn pod_spec(mut self, pod_spec: corev1::PodSpec) -> Self {
86 self.spec_mut()
87 .template
88 .get_or_insert_default()
89 .spec
90 .replace(pod_spec);
91 self
92 }
93}
94
95impl HasSpec for appsv1::ReplicaSet {
96 type Spec = appsv1::ReplicaSetSpec;
97
98 fn spec_mut(&mut self) -> &mut Self::Spec {
99 self.spec.get_or_insert_default()
100 }
101}