1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use super::*;

impl MachineDeployment {
    pub fn with_cluster_name(name: &str, cluster_name: &str) -> Self {
        let spec = MachineDeploymentSpec::new(cluster_name).replicas(3);
        Self::new(name, spec)
    }

    #[must_use]
    pub fn machine_template(mut self, machine_template: &MachineTemplate) -> Self {
        let infrastructure_ref = machine_template.object_ref();
        let mut spec = self.spec.template.spec.take().unwrap_or_default();
        spec.infrastructure_ref = infrastructure_ref;
        self.spec.template.spec = Some(spec);
        self
    }

    #[must_use]
    pub fn version(mut self, version: &str) -> Self {
        let mut spec = self.spec.template.spec.take().unwrap_or_default();
        spec.version = Some(version.to_string());
        self.spec.template.spec = Some(spec);
        self
    }

    #[must_use]
    pub fn bootstrap_config_ref(mut self, template: &ControlPlaneConfigTemplate) -> Self {
        let config_ref = template.object_ref();
        let mut spec = self.spec.template.spec.take().unwrap_or_default();
        spec.bootstrap.config_ref = Some(config_ref);
        self.spec.template.spec = Some(spec);
        self
    }
}

impl MachineDeploymentSpec {
    pub fn new(cluster_name: &str) -> Self {
        let spec = MachineSpec::new(cluster_name);
        let template = MachineTemplateSpec {
            spec: Some(spec),
            ..MachineTemplateSpec::default()
        };
        let cluster_name = cluster_name.to_string();
        Self {
            cluster_name,
            template,
            // replicas: todo!(),
            // selector: todo!(),
            // strategy: todo!(),
            // min_ready_seconds: todo!(),
            // revision_history_limit: todo!(),
            // paused: todo!(),
            // progress_deadline_seconds: todo!(),
            ..Self::default()
        }
    }

    #[must_use]
    pub fn replicas(mut self, replicas: i32) -> Self {
        self.replicas = Some(replicas);
        self
    }

    #[must_use]
    pub fn template(mut self, template: MachineTemplateSpec) -> Self {
        self.template = template;
        self
    }
}