k8s_openapi_ext/ext/
deployment.rs

1use super::*;
2
3pub trait DeploymentExt: 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 paused(self, yes: bool) -> Self;
11
12    fn progress_deadline_seconds(self, seconds: i32) -> Self;
13
14    fn replicas(self, replicas: i32) -> Self;
15
16    fn revision_history_limit(self, limit: i32) -> Self;
17
18    fn selector(self, selector: metav1::LabelSelector) -> Self;
19
20    fn match_labels(
21        self,
22        match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
23    ) -> Self;
24
25    fn strategy(self, strategy: appsv1::DeploymentStrategy) -> Self;
26
27    fn template(self, template: corev1::PodTemplateSpec) -> Self;
28
29    fn pod(self, pod: corev1::PodSpec) -> Self;
30}
31
32impl DeploymentExt for appsv1::Deployment {
33    fn new(name: impl ToString) -> Self {
34        let metadata = metadata(name);
35        Self {
36            metadata,
37            // spec: todo!(),
38            // status: todo!(),
39            ..default()
40        }
41    }
42
43    fn with_labels(
44        name: impl ToString,
45        labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
46    ) -> Self {
47        Self::new(name).labels(labels)
48    }
49
50    fn paused(mut self, yes: bool) -> Self {
51        self.spec_mut().paused.replace(yes);
52        self
53    }
54
55    fn progress_deadline_seconds(mut self, seconds: i32) -> Self {
56        self.spec_mut().progress_deadline_seconds.replace(seconds);
57        self
58    }
59
60    fn replicas(mut self, replicas: i32) -> Self {
61        self.spec_mut().replicas.replace(replicas);
62        self
63    }
64
65    fn revision_history_limit(mut self, limit: i32) -> Self {
66        self.spec_mut().revision_history_limit.replace(limit);
67        self
68    }
69
70    fn selector(mut self, selector: metav1::LabelSelector) -> Self {
71        self.spec_mut().selector = selector;
72        self
73    }
74
75    fn match_labels(
76        mut self,
77        match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
78    ) -> Self {
79        self.spec_mut().selector = metav1::LabelSelector::match_labels(match_labels);
80        self
81    }
82
83    fn strategy(mut self, strategy: appsv1::DeploymentStrategy) -> Self {
84        self.spec_mut().strategy.replace(strategy);
85        self
86    }
87
88    fn template(mut self, template: corev1::PodTemplateSpec) -> Self {
89        self.spec_mut().template = template;
90        self
91    }
92
93    fn pod(mut self, pod_spec: corev1::PodSpec) -> Self {
94        self.spec_mut().template.spec.replace(pod_spec);
95        self
96    }
97}
98
99impl HasSpec for appsv1::Deployment {
100    type Spec = appsv1::DeploymentSpec;
101
102    fn spec_mut(&mut self) -> &mut Self::Spec {
103        self.spec.get_or_insert_default()
104    }
105}