k8s_openapi_ext/ext/
replicaset.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 mut self,
70 match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
71 ) -> Self {
72 self.spec_mut().selector = metav1::LabelSelector::match_labels(match_labels);
73 self
74 }
75
76 fn template(mut self, template: corev1::PodTemplateSpec) -> Self {
77 self.spec_mut().template.replace(template);
78 self
79 }
80
81 fn pod_spec(mut self, pod_spec: corev1::PodSpec) -> Self {
82 self.spec_mut()
83 .template
84 .get_or_insert_default()
85 .spec
86 .replace(pod_spec);
87 self
88 }
89}
90
91impl HasSpec for appsv1::ReplicaSet {
92 type Spec = appsv1::ReplicaSetSpec;
93
94 fn spec_mut(&mut self) -> &mut Self::Spec {
95 self.spec.get_or_insert_default()
96 }
97}