k8s_cluster_api/v1beta1/infrastructure/aws/
impls.rs1use super::*;
2
3impl AWSClusterSpec {
4 pub fn region(&self) -> Option<&str> {
5 self.region.as_deref()
6 }
7
8 pub fn network(&self) -> Option<&NetworkSpec> {
9 self.network.as_ref()
10 }
11
12 pub fn vpc(&self) -> Option<&VPCSpec> {
13 self.network().and_then(|network| network.vpc.as_ref())
14 }
15
16 pub fn vpc_id(&self) -> Option<&str> {
17 self.vpc().and_then(|vpc| vpc.id.as_deref())
18 }
19}
20
21impl AWSClusterStatus {
22 pub fn ready(&self) -> bool {
23 self.ready
24 }
25 pub fn network(&self) -> Option<&NetworkStatus> {
26 self.network_status.as_ref()
27 }
28}
29
30impl AWSCluster {
31 pub fn with_name(name: &str) -> Self {
32 let spec = AWSClusterSpec::default();
33 Self::new(name, spec)
34 }
35
36 #[must_use]
37 pub fn region(mut self, region: impl ToString) -> Self {
38 self.spec.region = Some(region.to_string());
39 self
40 }
41
42 #[must_use]
43 pub fn sshkey(mut self, sshkey: impl ToString) -> Self {
44 self.spec.ssh_key_name = Some(sshkey.to_string());
45 self
46 }
47
48 #[must_use]
49 pub fn vpc_cidr_block(mut self, cidr_block: impl ToString) -> Self {
50 let cidr_block = cidr_block.to_string();
51 let mut network = self.spec.network.unwrap_or_default();
52 let mut vpc = network.vpc.unwrap_or_default();
53 vpc.cidr_block = Some(cidr_block);
54 network.vpc = Some(vpc);
55 self.spec.network = Some(network);
56
57 self
77 }
78
79 pub fn add_subnet(&mut self, availability_zone: &str, cidr_block: &str, is_public: bool) {
80 let network = self.spec.network.take().unwrap_or_default();
81 let network::Subnets(mut subnets) = network.subnets.unwrap_or_default();
82 subnets.push(network::SubnetSpec {
83 availability_zone: Some(availability_zone.to_string()),
84 cidr_block: Some(cidr_block.to_string()),
85 is_public: Some(is_public),
86 ..Default::default()
87 });
88 let network = NetworkSpec {
89 subnets: Some(network::Subnets(subnets)),
90 ..network
91 };
92 self.spec.network = Some(network);
93 }
94
95 #[must_use]
96 pub fn namespace(self, namespace: &str) -> Self {
97 Self {
98 metadata: kube::core::ObjectMeta {
99 namespace: Some(namespace.to_string()),
100 ..self.metadata
101 },
102 ..self
103 }
104 }
105
106 pub fn bastion(self, enabled: bool) -> Self {
107 Self {
108 spec: AWSClusterSpec {
109 bastion: Some(Bastion {
110 enabled: Some(enabled),
111 allowed_cidr_blocks: vec!["0.0.0.0/0".to_string()],
112 ..Bastion::default()
113 }),
114 ..self.spec
115 },
116 ..self
117 }
118 }
119}