k8s_cluster_api/v1beta1/machine/deployment/
impls.rs

1use super::*;
2
3impl MachineDeployment {
4    pub fn with_cluster_name(name: &str, cluster_name: &str) -> Self {
5        let spec = MachineDeploymentSpec::new(cluster_name).replicas(3);
6        Self::new(name, spec)
7    }
8
9    #[must_use]
10    pub fn machine_template<T>(mut self, machine_template: &T) -> Self
11    where
12        T: MachineTemplate,
13    {
14        let infrastructure_ref = machine_template.object_ref();
15        let mut spec = self.spec.template.spec.take().unwrap_or_default();
16        spec.infrastructure_ref = infrastructure_ref;
17        self.spec.template.spec = Some(spec);
18        self
19    }
20
21    #[must_use]
22    pub fn version(mut self, version: &str) -> Self {
23        let mut spec = self.spec.template.spec.take().unwrap_or_default();
24        spec.version = Some(version.to_string());
25        self.spec.template.spec = Some(spec);
26        self
27    }
28
29    #[must_use]
30    pub fn bootstrap<T>(mut self, template: &T) -> Self
31    where
32        T: ControlPlaneConfigTemplate,
33    {
34        self.spec
35            .template
36            .spec
37            .get_or_insert_with(Default::default)
38            .bootstrap
39            .config_ref = Some(template.object_ref());
40        self
41    }
42}
43
44impl MachineDeploymentSpec {
45    pub fn new(cluster_name: &str) -> Self {
46        let spec = MachineSpec::new(cluster_name);
47        let template = MachineTemplateSpec {
48            spec: Some(spec),
49            ..MachineTemplateSpec::default()
50        };
51        let cluster_name = cluster_name.to_string();
52        Self {
53            cluster_name,
54            template,
55            // replicas: todo!(),
56            // selector: todo!(),
57            // strategy: todo!(),
58            // min_ready_seconds: todo!(),
59            // revision_history_limit: todo!(),
60            // paused: todo!(),
61            // progress_deadline_seconds: todo!(),
62            ..Self::default()
63        }
64    }
65
66    #[must_use]
67    pub fn replicas(mut self, replicas: i32) -> Self {
68        self.replicas = Some(replicas);
69        self
70    }
71
72    #[must_use]
73    pub fn template(mut self, template: MachineTemplateSpec) -> Self {
74        self.template = template;
75        self
76    }
77}