sigs.k8s.io/cluster-api-provider-aws@v1.5.5/api/v1beta1/awscluster_types.go (about)

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1beta1
    18  
    19  import (
    20  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    21  
    22  	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
    23  )
    24  
    25  const (
    26  	// ClusterFinalizer allows ReconcileAWSCluster to clean up AWS resources associated with AWSCluster before
    27  	// removing it from the apiserver.
    28  	ClusterFinalizer = "awscluster.infrastructure.cluster.x-k8s.io"
    29  
    30  	// AWSClusterControllerIdentityName is the name of the AWSClusterControllerIdentity singleton.
    31  	AWSClusterControllerIdentityName = "default"
    32  )
    33  
    34  // AWSClusterSpec defines the desired state of an EC2-based Kubernetes cluster.
    35  type AWSClusterSpec struct {
    36  	// NetworkSpec encapsulates all things related to AWS network.
    37  	NetworkSpec NetworkSpec `json:"network,omitempty"`
    38  
    39  	// The AWS Region the cluster lives in.
    40  	Region string `json:"region,omitempty"`
    41  
    42  	// 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)
    43  	// +optional
    44  	SSHKeyName *string `json:"sshKeyName,omitempty"`
    45  
    46  	// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
    47  	// +optional
    48  	ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
    49  
    50  	// AdditionalTags is an optional set of tags to add to AWS resources managed by the AWS provider, in addition to the
    51  	// ones added by default.
    52  	// +optional
    53  	AdditionalTags Tags `json:"additionalTags,omitempty"`
    54  
    55  	// ControlPlaneLoadBalancer is optional configuration for customizing control plane behavior.
    56  	// +optional
    57  	ControlPlaneLoadBalancer *AWSLoadBalancerSpec `json:"controlPlaneLoadBalancer,omitempty"`
    58  
    59  	// ImageLookupFormat is the AMI naming format to look up machine images when
    60  	// a machine does not specify an AMI. When set, this will be used for all
    61  	// cluster machines unless a machine specifies a different ImageLookupOrg.
    62  	// Supports substitutions for {{.BaseOS}} and {{.K8sVersion}} with the base
    63  	// OS and kubernetes version, respectively. The BaseOS will be the value in
    64  	// ImageLookupBaseOS or ubuntu (the default), and the kubernetes version as
    65  	// defined by the packages produced by kubernetes/release without v as a
    66  	// prefix: 1.13.0, 1.12.5-mybuild.1, or 1.17.3. For example, the default
    67  	// image format of capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-* will end up
    68  	// searching for AMIs that match the pattern capa-ami-ubuntu-?1.18.0-* for a
    69  	// Machine that is targeting kubernetes v1.18.0 and the ubuntu base OS. See
    70  	// also: https://golang.org/pkg/text/template/
    71  	// +optional
    72  	ImageLookupFormat string `json:"imageLookupFormat,omitempty"`
    73  
    74  	// ImageLookupOrg is the AWS Organization ID to look up machine images when a
    75  	// machine does not specify an AMI. When set, this will be used for all
    76  	// cluster machines unless a machine specifies a different ImageLookupOrg.
    77  	// +optional
    78  	ImageLookupOrg string `json:"imageLookupOrg,omitempty"`
    79  
    80  	// ImageLookupBaseOS is the name of the base operating system used to look
    81  	// up machine images when a machine does not specify an AMI. When set, this
    82  	// will be used for all cluster machines unless a machine specifies a
    83  	// different ImageLookupBaseOS.
    84  	ImageLookupBaseOS string `json:"imageLookupBaseOS,omitempty"`
    85  
    86  	// Bastion contains options to configure the bastion host.
    87  	// +optional
    88  	Bastion Bastion `json:"bastion"`
    89  
    90  	// IdentityRef is a reference to a identity to be used when reconciling this cluster
    91  	// +optional
    92  	IdentityRef *AWSIdentityReference `json:"identityRef,omitempty"`
    93  
    94  	// S3Bucket contains options to configure a supporting S3 bucket for this
    95  	// cluster - currently used for nodes requiring Ignition
    96  	// (https://coreos.github.io/ignition/) for bootstrapping (requires
    97  	// BootstrapFormatIgnition feature flag to be enabled).
    98  	// +optional
    99  	S3Bucket *S3Bucket `json:"s3Bucket,omitempty"`
   100  }
   101  
   102  // AWSIdentityKind defines allowed AWS identity types.
   103  type AWSIdentityKind string
   104  
   105  var (
   106  	// ControllerIdentityKind defines identity reference kind as AWSClusterControllerIdentity.
   107  	ControllerIdentityKind = AWSIdentityKind("AWSClusterControllerIdentity")
   108  
   109  	// ClusterRoleIdentityKind defines identity reference kind as AWSClusterRoleIdentity.
   110  	ClusterRoleIdentityKind = AWSIdentityKind("AWSClusterRoleIdentity")
   111  
   112  	// ClusterStaticIdentityKind defines identity reference kind as AWSClusterStaticIdentity.
   113  	ClusterStaticIdentityKind = AWSIdentityKind("AWSClusterStaticIdentity")
   114  )
   115  
   116  // AWSIdentityReference specifies a identity.
   117  type AWSIdentityReference struct {
   118  	// Name of the identity.
   119  	// +kubebuilder:validation:MinLength=1
   120  	Name string `json:"name"`
   121  
   122  	// Kind of the identity.
   123  	// +kubebuilder:validation:Enum=AWSClusterControllerIdentity;AWSClusterRoleIdentity;AWSClusterStaticIdentity
   124  	Kind AWSIdentityKind `json:"kind"`
   125  }
   126  
   127  // Bastion defines a bastion host.
   128  type Bastion struct {
   129  	// Enabled allows this provider to create a bastion host instance
   130  	// with a public ip to access the VPC private network.
   131  	// +optional
   132  	Enabled bool `json:"enabled"`
   133  
   134  	// DisableIngressRules will ensure there are no Ingress rules in the bastion host's security group.
   135  	// Requires AllowedCIDRBlocks to be empty.
   136  	// +optional
   137  	DisableIngressRules bool `json:"disableIngressRules,omitempty"`
   138  
   139  	// AllowedCIDRBlocks is a list of CIDR blocks allowed to access the bastion host.
   140  	// They are set as ingress rules for the Bastion host's Security Group (defaults to 0.0.0.0/0).
   141  	// +optional
   142  	AllowedCIDRBlocks []string `json:"allowedCIDRBlocks,omitempty"`
   143  
   144  	// InstanceType will use the specified instance type for the bastion. If not specified,
   145  	// Cluster API Provider AWS will use t3.micro for all regions except us-east-1, where t2.micro
   146  	// will be the default.
   147  	InstanceType string `json:"instanceType,omitempty"`
   148  
   149  	// AMI will use the specified AMI to boot the bastion. If not specified,
   150  	// the AMI will default to one picked out in public space.
   151  	// +optional
   152  	AMI string `json:"ami,omitempty"`
   153  }
   154  
   155  // AWSLoadBalancerSpec defines the desired state of an AWS load balancer.
   156  type AWSLoadBalancerSpec struct {
   157  	// Name sets the name of the classic ELB load balancer. As per AWS, the name must be unique
   158  	// within your set of load balancers for the region, must have a maximum of 32 characters, must
   159  	// contain only alphanumeric characters or hyphens, and cannot begin or end with a hyphen. Once
   160  	// set, the value cannot be changed.
   161  	// +kubebuilder:validation:MaxLength:=32
   162  	// +kubebuilder:validation:Pattern=`^[A-Za-z0-9]([A-Za-z0-9]{0,31}|[-A-Za-z0-9]{0,30}[A-Za-z0-9])$`
   163  	// +optional
   164  	Name *string `json:"name,omitempty"`
   165  
   166  	// Scheme sets the scheme of the load balancer (defaults to internet-facing)
   167  	// +kubebuilder:default=internet-facing
   168  	// +kubebuilder:validation:Enum=internet-facing;internal
   169  	// +optional
   170  	Scheme *ClassicELBScheme `json:"scheme,omitempty"`
   171  
   172  	// CrossZoneLoadBalancing enables the classic ELB cross availability zone balancing.
   173  	//
   174  	// With cross-zone load balancing, each load balancer node for your Classic Load Balancer
   175  	// distributes requests evenly across the registered instances in all enabled Availability Zones.
   176  	// If cross-zone load balancing is disabled, each load balancer node distributes requests evenly across
   177  	// the registered instances in its Availability Zone only.
   178  	//
   179  	// Defaults to false.
   180  	// +optional
   181  	CrossZoneLoadBalancing bool `json:"crossZoneLoadBalancing"`
   182  
   183  	// 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)
   184  	// +optional
   185  	Subnets []string `json:"subnets,omitempty"`
   186  
   187  	// HealthCheckProtocol sets the protocol type for classic ELB health check target
   188  	// default value is ClassicELBProtocolSSL
   189  	// +optional
   190  	HealthCheckProtocol *ClassicELBProtocol `json:"healthCheckProtocol,omitempty"`
   191  
   192  	// AdditionalSecurityGroups sets the security groups used by the load balancer. Expected to be security group IDs
   193  	// This is optional - if not provided new security groups will be created for the load balancer
   194  	// +optional
   195  	AdditionalSecurityGroups []string `json:"additionalSecurityGroups,omitempty"`
   196  }
   197  
   198  // AWSClusterStatus defines the observed state of AWSCluster.
   199  type AWSClusterStatus struct {
   200  	// +kubebuilder:default=false
   201  	Ready          bool                     `json:"ready"`
   202  	Network        NetworkStatus            `json:"networkStatus,omitempty"`
   203  	FailureDomains clusterv1.FailureDomains `json:"failureDomains,omitempty"`
   204  	Bastion        *Instance                `json:"bastion,omitempty"`
   205  	Conditions     clusterv1.Conditions     `json:"conditions,omitempty"`
   206  }
   207  
   208  type S3Bucket struct {
   209  	// ControlPlaneIAMInstanceProfile is a name of the IAMInstanceProfile, which will be allowed
   210  	// to read control-plane node bootstrap data from S3 Bucket.
   211  	ControlPlaneIAMInstanceProfile string `json:"controlPlaneIAMInstanceProfile"`
   212  
   213  	// NodesIAMInstanceProfiles is a list of IAM instance profiles, which will be allowed to read
   214  	// worker nodes bootstrap data from S3 Bucket.
   215  	NodesIAMInstanceProfiles []string `json:"nodesIAMInstanceProfiles"`
   216  
   217  	// Name defines name of S3 Bucket to be created.
   218  	// +kubebuilder:validation:MinLength:=3
   219  	// +kubebuilder:validation:MaxLength:=63
   220  	// +kubebuilder:validation:Pattern=`^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$`
   221  	Name string `json:"name"`
   222  }
   223  
   224  // +kubebuilder:object:root=true
   225  // +kubebuilder:resource:path=awsclusters,scope=Namespaced,categories=cluster-api,shortName=awsc
   226  // +kubebuilder:storageversion
   227  // +kubebuilder:subresource:status
   228  // +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this AWSCluster belongs"
   229  // +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Cluster infrastructure is ready for EC2 instances"
   230  // +kubebuilder:printcolumn:name="VPC",type="string",JSONPath=".spec.network.vpc.id",description="AWS VPC the cluster is using"
   231  // +kubebuilder:printcolumn:name="Endpoint",type="string",JSONPath=".spec.controlPlaneEndpoint",description="API Endpoint",priority=1
   232  // +kubebuilder:printcolumn:name="Bastion IP",type="string",JSONPath=".status.bastion.publicIp",description="Bastion IP address for breakglass access"
   233  // +k8s:defaulter-gen=true
   234  
   235  // AWSCluster is the schema for Amazon EC2 based Kubernetes Cluster API.
   236  type AWSCluster struct {
   237  	metav1.TypeMeta   `json:",inline"`
   238  	metav1.ObjectMeta `json:"metadata,omitempty"`
   239  
   240  	Spec   AWSClusterSpec   `json:"spec,omitempty"`
   241  	Status AWSClusterStatus `json:"status,omitempty"`
   242  }
   243  
   244  // +kubebuilder:object:root=true
   245  
   246  // AWSClusterList contains a list of AWSCluster.
   247  // +k8s:defaulter-gen=true
   248  type AWSClusterList struct {
   249  	metav1.TypeMeta `json:",inline"`
   250  	metav1.ListMeta `json:"metadata,omitempty"`
   251  	Items           []AWSCluster `json:"items"`
   252  }
   253  
   254  // GetConditions returns the observations of the operational state of the AWSCluster resource.
   255  func (r *AWSCluster) GetConditions() clusterv1.Conditions {
   256  	return r.Status.Conditions
   257  }
   258  
   259  // SetConditions sets the underlying service state of the AWSCluster to the predescribed clusterv1.Conditions.
   260  func (r *AWSCluster) SetConditions(conditions clusterv1.Conditions) {
   261  	r.Status.Conditions = conditions
   262  }
   263  
   264  func init() {
   265  	SchemeBuilder.Register(&AWSCluster{}, &AWSClusterList{})
   266  }