k8s_cluster_api/v1beta1/infrastructure/aws.rs
1use std::collections::BTreeMap;
2
3use super::*;
4
5pub use machine::AWSMachineTemplate;
6pub use network::ClassicELBScheme;
7pub use network::NetworkSpec;
8pub use network::NetworkStatus;
9pub use network::VPCSpec;
10pub use tags::Tags;
11pub use types::AMIReference;
12pub use types::AZSelectionScheme;
13pub use types::EKSAMILookupType;
14pub use types::Instance;
15pub use types::InstanceState;
16pub use types::Volume;
17pub use types::VolumeType;
18
19mod impls;
20mod machine;
21mod network;
22mod tags;
23mod types;
24
25/// AWSClusterSpec defines the desired state of an EC2-based Kubernetes cluster.
26#[skip_serializing_none]
27#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, Default)]
28#[serde(rename_all = "camelCase")]
29#[kube(
30 group = "infrastructure.cluster.x-k8s.io",
31 version = "v1beta1",
32 kind = "AWSCluster",
33 plural = "awsclusters",
34 status = "AWSClusterStatus"
35)]
36#[kube(namespaced)]
37#[kube(schema = "disabled")]
38pub struct AWSClusterSpec {
39 /// NetworkSpec encapsulates all things related to AWS network.
40 pub network: Option<NetworkSpec>,
41
42 /// The AWS Region the cluster lives in.
43 pub region: Option<String>,
44
45 /// SSHKeyName is the name of the ssh key to attach to the bastion host. Valid values are empty string (do not use SSH keys), a valid SSH key name, or omitted (use the default SSH key name)
46 // +optional
47 pub ssh_key_name: Option<String>,
48
49 /// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
50 // +optional
51 pub control_plane_endpoint: Option<clusterv1::ApiEndpoint>,
52
53 /// AdditionalTags is an optional set of tags to add to AWS resources managed by the AWS provider, in addition to the
54 /// ones added by default.
55 // +optional
56 pub additional_tags: Option<Tags>,
57
58 /// ControlPlaneLoadBalancer is optional configuration for customizing control plane behavior.
59 // +optional
60 pub control_plane_load_balancer: Option<AWSLoadBalancerSpec>,
61
62 /// ImageLookupFormat is the AMI naming format to look up machine images when
63 /// a machine does not specify an AMI. When set, this will be used for all
64 /// cluster machines unless a machine specifies a different ImageLookupOrg.
65 /// Supports substitutions for {{.BaseOS}} and {{.K8sVersion}} with the base
66 /// OS and kubernetes version, respectively. The BaseOS will be the value in
67 /// ImageLookupBaseOS or ubuntu (the default), and the kubernetes version as
68 /// defined by the packages produced by kubernetes/release without v as a
69 /// prefix: 1.13.0, 1.12.5-mybuild.1, or 1.17.3. For example, the default
70 /// image format of capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-* will end up
71 /// searching for AMIs that match the pattern capa-ami-ubuntu-?1.18.0-* for a
72 /// Machine that is targeting kubernetes v1.18.0 and the ubuntu base OS. See
73 /// also: https://golang.org/pkg/text/template/
74 // +optional
75 pub image_lookup_format: Option<String>,
76
77 /// ImageLookupOrg is the AWS Organization ID to look up machine images when a
78 /// machine does not specify an AMI. When set, this will be used for all
79 /// cluster machines unless a machine specifies a different ImageLookupOrg.
80 // +optional
81 pub image_lookup_org: Option<String>,
82
83 /// ImageLookupBaseOS is the name of the base operating system used to look
84 /// up machine images when a machine does not specify an AMI. When set, this
85 /// will be used for all cluster machines unless a machine specifies a
86 /// different ImageLookupBaseOS.
87 #[serde(rename = "imageLookupBaseOS")]
88 pub image_lookup_base_os: Option<String>,
89
90 /// Bastion contains options to configure the bastion host.
91 // +optional
92 pub bastion: Option<Bastion>,
93
94 /// IdentityRef is a reference to a identity to be used when reconciling this cluster
95 // +optional
96 pub identity_ref: Option<AWSIdentityReference>,
97}
98
99/// AWSClusterStatus defines the observed state of AWSCluster.
100#[skip_serializing_none]
101#[derive(Clone, Debug, Default, Serialize, Deserialize)]
102#[serde(rename_all = "camelCase")]
103pub struct AWSClusterStatus {
104 // +kubebuilder:default=false
105 pub ready: bool,
106 pub network_status: Option<NetworkStatus>,
107 pub failure_domains: Option<clusterv1::FailureDomains>,
108 pub bastion: Option<Instance>,
109 pub conditions: Option<clusterv1::Conditions>,
110}
111
112/// AWSIdentityKind defines allowed AWS identity types.
113#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
114pub enum AWSIdentityKind {
115 AWSClusterControllerIdentity,
116 AWSClusterRoleIdentity,
117 AWSClusterStaticIdentity,
118}
119
120/// ControllerIdentityKind defines identity reference kind as AWSClusterControllerIdentity.
121#[allow(non_upper_case_globals)]
122pub const ControllerIdentityKind: AWSIdentityKind = AWSIdentityKind::AWSClusterControllerIdentity;
123
124/// ClusterRoleIdentityKind defines identity reference kind as AWSClusterRoleIdentity.
125#[allow(non_upper_case_globals)]
126pub const ClusterRoleIdentityKind: AWSIdentityKind = AWSIdentityKind::AWSClusterRoleIdentity;
127
128/// ClusterStaticIdentityKind defines identity reference kind as AWSClusterStaticIdentity.
129#[allow(non_upper_case_globals)]
130pub const ClusterStaticIdentityKind: AWSIdentityKind = AWSIdentityKind::AWSClusterStaticIdentity;
131
132/// AWSIdentityReference specifies a identity.
133#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
134pub struct AWSIdentityReference {
135 /// Name of the identity.
136 // +kubebuilder:validation:MinLength=1
137 pub name: String,
138
139 /// Kind of the identity.
140 // +kubebuilder:validation:Enum=AWSClusterControllerIdentity;AWSClusterRoleIdentity;AWSClusterStaticIdentity
141 pub kind: AWSIdentityKind,
142}
143
144// Bastion defines a bastion host.
145#[skip_serializing_none]
146#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Default)]
147#[serde(rename_all = "camelCase")]
148pub struct Bastion {
149 /// Enabled allows this provider to create a bastion host instance
150 /// with a public ip to access the VPC private network.
151 // +optional
152 pub enabled: Option<bool>,
153
154 /// DisableIngressRules will ensure there are no Ingress rules in the bastion host's security group.
155 /// Requires AllowedCIDRBlocks to be empty.
156 // +optional
157 pub disable_ingress_rules: Option<bool>,
158
159 /// AllowedCIDRBlocks is a list of CIDR blocks allowed to access the bastion host.
160 /// They are set as ingress rules for the Bastion host's Security Group (defaults to 0.0.0.0/0).
161 // +optional
162 #[serde(
163 default,
164 rename = "allowedCIDRBlocks",
165 skip_serializing_if = "Vec::is_empty"
166 )]
167 pub allowed_cidr_blocks: Vec<String>,
168
169 /// InstanceType will use the specified instance type for the bastion. If not specified,
170 /// Cluster API Provider AWS will use t3.micro for all regions except us-east-1, where t2.micro
171 /// will be the default.
172 pub instance_type: Option<String>,
173
174 /// AMI will use the specified AMI to boot the bastion. If not specified,
175 /// the AMI will default to one picked out in public space.
176 // +optional
177 pub ami: Option<String>,
178}
179
180/// AWSLoadBalancerSpec defines the desired state of an AWS load balancer.
181#[skip_serializing_none]
182#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
183#[serde(rename_all = "camelCase")]
184pub struct AWSLoadBalancerSpec {
185 /// Name sets the name of the classic ELB load balancer. As per AWS, the name must be unique
186 /// within your set of load balancers for the region, must have a maximum of 32 characters, must
187 /// contain only alphanumeric characters or hyphens, and cannot begin or end with a hyphen. Once
188 /// set, the value cannot be changed.
189 /// +kubebuilder:validation:MaxLength:=32
190 /// +kubebuilder:validation:Pattern=`^[A-Za-z0-9]([A-Za-z0-9]{0,31}|[-A-Za-z0-9]{0,30}[A-Za-z0-9])$`
191 // +optional
192 pub name: Option<String>,
193
194 /// Scheme sets the scheme of the load balancer (defaults to internet-facing)
195 /// +kubebuilder:default=internet-facing
196 /// +kubebuilder:validation:Enum=internet-facing;internal
197 // +optional
198 pub scheme: Option<ClassicELBScheme>,
199
200 /// CrossZoneLoadBalancing enables the classic ELB cross availability zone balancing.
201 ///
202 /// With cross-zone load balancing, each load balancer node for your Classic Load Balancer
203 /// distributes requests evenly across the registered instances in all enabled Availability Zones.
204 /// If cross-zone load balancing is disabled, each load balancer node distributes requests evenly across
205 /// the registered instances in its Availability Zone only.
206 ///
207 /// Defaults to false.
208 // +optional
209 pub cross_zone_load_balancing: Option<bool>, // `json:"crossZoneLoadBalancing"`
210
211 /// Subnets sets the subnets that should be applied to the control plane load balancer (defaults to discovered subnets for managed VPCs or an empty set for unmanaged VPCs)
212 // +optional
213 pub subnets: Option<Vec<String>>, // `json:"subnets,omitempty"`
214
215 /// AdditionalSecurityGroups sets the security groups used by the load balancer. Expected to be security group IDs
216 /// This is optional - if not provided new security groups will be created for the load balancer
217 // +optional
218 pub additional_security_groups: Option<Vec<String>>, // `json:"additionalSecurityGroups,omitempty"`
219}
220
221#[cfg(test)]
222mod tests;
223
224/* ==========================================================================
225
226package v1beta1
227
228import (
229 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
230 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
231)
232
233const (
234 // ClusterFinalizer allows ReconcileAWSCluster to clean up AWS resources associated with AWSCluster before
235 // removing it from the apiserver.
236 ClusterFinalizer = "awscluster.infrastructure.cluster.x-k8s.io"
237
238 // AWSClusterControllerIdentityName is the name of the AWSClusterControllerIdentity singleton.
239 AWSClusterControllerIdentityName = "default"
240)
241
242
243
244// +kubebuilder:object:root=true
245// +kubebuilder:resource:path=awsclusters,scope=Namespaced,categories=cluster-api,shortName=awsc
246// +kubebuilder:storageversion
247// +kubebuilder:subresource:status
248// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this AWSCluster belongs"
249// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Cluster infrastructure is ready for EC2 instances"
250// +kubebuilder:printcolumn:name="VPC",type="string",JSONPath=".spec.network.vpc.id",description="AWS VPC the cluster is using"
251// +kubebuilder:printcolumn:name="Endpoint",type="string",JSONPath=".spec.controlPlaneEndpoint",description="API Endpoint",priority=1
252// +kubebuilder:printcolumn:name="Bastion IP",type="string",JSONPath=".status.bastion.publicIp",description="Bastion IP address for breakglass access"
253// +k8s:defaulter-gen=true
254
255// AWSCluster is the schema for Amazon EC2 based Kubernetes Cluster API.
256type AWSCluster struct {
257 metav1.TypeMeta `json:",inline"`
258 metav1.ObjectMeta `json:"metadata,omitempty"`
259
260 Spec AWSClusterSpec `json:"spec,omitempty"`
261 Status AWSClusterStatus `json:"status,omitempty"`
262}
263
264// +kubebuilder:object:root=true
265
266// AWSClusterList contains a list of AWSCluster.
267// +k8s:defaulter-gen=true
268type AWSClusterList struct {
269 metav1.TypeMeta `json:",inline"`
270 metav1.ListMeta `json:"metadata,omitempty"`
271 Items []AWSCluster `json:"items"`
272}
273
274// GetConditions returns the observations of the operational state of the AWSCluster resource.
275func (r *AWSCluster) GetConditions() clusterv1.Conditions {
276 return r.Status.Conditions
277}
278
279// SetConditions sets the underlying service state of the AWSCluster to the predescribed clusterv1.Conditions.
280func (r *AWSCluster) SetConditions(conditions clusterv1.Conditions) {
281 r.Status.Conditions = conditions
282}
283
284func init() {
285 SchemeBuilder.Register(&AWSCluster{}, &AWSClusterList{})
286}
287
288========================================================================== */