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