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        self,
77        match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
78    ) -> Self {
79        let mut spec = self.spec.unwrap_or_default();
80        spec.selector = spec.selector.match_labels(match_labels);
81        Self {
82            spec: Some(spec),
83            ..self
84        }
85    }
86
87    fn strategy(mut self, strategy: appsv1::DeploymentStrategy) -> Self {
88        self.spec_mut().strategy.replace(strategy);
89        self
90    }
91
92    fn template(mut self, template: corev1::PodTemplateSpec) -> Self {
93        self.spec_mut().template = template;
94        self
95    }
96
97    fn pod(mut self, pod_spec: corev1::PodSpec) -> Self {
98        self.spec_mut().template.spec.replace(pod_spec);
99        self
100    }
101}
102
103impl HasSpec for appsv1::Deployment {
104    type Spec = appsv1::DeploymentSpec;
105
106    fn spec_mut(&mut self) -> &mut Self::Spec {
107        self.spec.get_or_insert_with(default)
108    }
109}