k8s_cluster_api/v1beta1/controlplane/kubeadm/
impls.rs

1use maplit::{btreemap, convert_args};
2
3use super::*;
4
5impl KubeadmControlPlane {
6    pub fn aws(name: &str) -> Self {
7        let extra_args = convert_args!(btreemap!("cloud-provider" => "aws"));
8        let spec = KubeadmControlPlaneSpec {
9            kubeadm_config_spec: cabpkv1::KubeadmConfigSpec {
10                cluster_configuration: Some(cabpkv1::ClusterConfiguration {
11                    api_server: Some(cabpkv1::APIServer {
12                        control_plane: cabpkv1::ControlPlaneComponent {
13                            extra_args: extra_args.clone(),
14                            ..Default::default()
15                        },
16                        ..Default::default()
17                    }),
18                    controller_manager: Some(cabpkv1::ControlPlaneComponent {
19                        extra_args: extra_args.clone(),
20                        ..Default::default()
21                    }),
22                    ..Default::default()
23                }),
24                init_configuration: Some(cabpkv1::InitConfiguration {
25                    node_registration: Some(cabpkv1::NodeRegistrationOptions {
26                        kubelet_extra_args: extra_args.clone(),
27                        name: Some("{{ ds.meta_data.local_hostname }}".to_string()),
28                        ..Default::default()
29                    }),
30                    ..Default::default()
31                }),
32                join_configuration: Some(cabpkv1::JoinConfiguration {
33                    node_registration: Some(cabpkv1::NodeRegistrationOptions {
34                        kubelet_extra_args: extra_args,
35                        name: Some("{{ ds.meta_data.local_hostname }}".to_string()),
36                        ..Default::default()
37                    }),
38                    ..Default::default()
39                }),
40                ..Default::default()
41            },
42            ..Default::default()
43        };
44        Self::new(name, spec)
45    }
46
47    #[must_use]
48    pub fn machine_template<T>(self, machine_template: &T) -> Self
49    where
50        T: MachineTemplate,
51    {
52        let infrastructure_ref = machine_template.object_ref();
53        let mut kubeadm_control_plane_machine_template = self.spec.machine_template;
54        kubeadm_control_plane_machine_template.infrastructure_ref = infrastructure_ref;
55        Self {
56            spec: KubeadmControlPlaneSpec {
57                machine_template: kubeadm_control_plane_machine_template,
58                ..self.spec
59            },
60            ..self
61        }
62    }
63
64    #[must_use]
65    pub fn replicas(self, replicas: i32) -> Self {
66        let mut kubeadm_control_plane_spec = self.spec;
67        kubeadm_control_plane_spec.replicas = Some(replicas);
68        Self {
69            spec: kubeadm_control_plane_spec,
70            ..self
71        }
72    }
73
74    #[must_use]
75    pub fn version(self, version: &str) -> Self {
76        Self {
77            spec: KubeadmControlPlaneSpec {
78                version: version.to_string(),
79                ..self.spec
80            },
81            ..self
82        }
83    }
84
85    #[must_use]
86    pub fn namespace(self, namespace: &str) -> Self {
87        Self {
88            metadata: kube::core::ObjectMeta {
89                namespace: Some(namespace.to_string()),
90                ..self.metadata
91            },
92            ..self
93        }
94    }
95}