k8s_cluster_api/v1beta1/infrastructure/aws/machine/
impls.rs1use super::*;
2
3impl AWSMachineTemplate {
4 pub fn with_type(name: &str, instance_type: &str) -> Self {
5 let machine_spec = AWSMachineSpec::with_type(instance_type);
6 let template = AWSMachineTemplateResource::new(machine_spec);
7 let spec = AWSMachineTemplateSpec::new(template);
8 Self::new(name, spec)
9 }
10
11 pub fn t3small(name: &str) -> Self {
12 Self::with_type(name, "t3.small")
13 }
14
15 pub fn m5large(name: &str) -> Self {
16 Self::with_type(name, "m5.large")
17 }
18
19 pub fn m5xlarge(name: &str) -> Self {
20 Self::with_type(name, "m5.xlarge")
21 }
22
23 pub fn m5dxlarge(name: &str) -> Self {
24 Self::with_type(name, "m5d.xlarge")
25 }
26
27 pub fn m5d4xlarge(name: &str) -> Self {
28 Self::with_type(name, "m5d.4xlarge")
29 }
30
31 pub fn m5d16large(name: &str) -> Self {
32 Self::with_type(name, "m5d.16xlarge")
33 }
34
35 pub fn m6gdxlarge(name: &str) -> Self {
36 Self::with_type(name, "m6gd.xlarge")
37 }
38
39 pub fn m6gd4xlarge(name: &str) -> Self {
40 Self::with_type(name, "m6gd.4xlarge")
41 }
42
43 pub fn m6ilarge(name: &str) -> Self {
44 Self::with_type(name, "m6i.large")
45 }
46
47 pub fn m6ixlarge(name: &str) -> Self {
48 Self::with_type(name, "m6i.xlarge")
49 }
50
51 #[must_use]
52 pub fn ssh_key_name(mut self, name: &str) -> Self {
53 self.spec.template.spec.ssh_key_name = Some(name.to_string());
54 self
55 }
56
57 #[must_use]
58 pub fn iam_instance_profile(mut self, iam_instance_profile: &str) -> Self {
59 self.spec.template.spec.iam_instance_profile = Some(iam_instance_profile.to_string());
60 self
61 }
62
63 #[must_use]
64 pub fn public_ip(mut self, yes: bool) -> Self {
65 self.spec.template.spec.public_ip = Some(yes);
66 self
67 }
68
69 #[must_use]
70 pub fn ami(mut self, id: &str) -> Self {
71 let id = id.to_string();
72 let mut ami = self.spec.template.spec.ami.unwrap_or_default();
73 ami.id = Some(id);
74 self.spec.template.spec.ami = Some(ami);
75 self
76 }
77
78 #[must_use]
79 pub fn root_volume(mut self, root_volume: Volume) -> Self {
80 self.spec.template.spec.root_volume = Some(root_volume);
81 self
82 }
83
84 #[must_use]
85 pub fn root_volume_size(self, size: i64) -> Self {
86 let root_volume = Volume::gp3(size);
87 self.root_volume(root_volume)
88 }
89
90 #[must_use]
91 pub fn non_root_volumes(mut self, volumes: impl IntoIterator<Item = Volume>) -> Self {
92 self.spec.template.spec.non_root_volumes = volumes.into_iter().collect();
93 self
94 }
95
96 #[must_use]
97 pub fn namespace(self, namespace: &str) -> Self {
98 Self {
99 metadata: kube::core::ObjectMeta {
100 namespace: Some(namespace.to_string()),
101 ..self.metadata
102 },
103 ..self
104 }
105 }
106
107 pub fn additional_security_group(self, arn: &str) -> Self {
108 let mut additional_security_groups = self.spec.template.spec.additional_security_groups;
109 additional_security_groups.push(types::AWSResourceReference {
110 arn: Some(arn.to_string()),
111 id: None,
112 filters: vec![],
113 });
114 Self {
115 spec: AWSMachineTemplateSpec {
116 template: AWSMachineTemplateResource {
117 spec: AWSMachineSpec {
118 additional_security_groups,
119 ..self.spec.template.spec
120 },
121 ..self.spec.template
122 },
123 },
124 ..self
125 }
126 }
127}
128
129impl AWSMachineTemplateSpec {
130 fn new(template: AWSMachineTemplateResource) -> Self {
131 Self { template }
132 }
133}
134
135impl AWSMachineTemplateResource {
136 fn new(spec: AWSMachineSpec) -> Self {
137 Self {
138 spec,
139 ..Self::default()
140 }
141 }
142}
143
144impl AWSMachineSpec {
145 fn with_type(instnce_type: &str) -> Self {
146 let instance_type = instnce_type.to_string();
147 Self {
148 instance_type,
149 ..Self::default()
150 }
167 }
168
169 pub fn ssh_key_name(self, ssh_key_name: impl ToString) -> Self {
170 let ssh_key_name = ssh_key_name.to_string().into();
171 Self {
172 ssh_key_name,
173 ..self
174 }
175 }
176}