sigs.k8s.io/cluster-api-provider-aws@v1.5.5/api/v1alpha4/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 v1alpha4
    18  
    19  import (
    20  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    21  
    22  	clusterv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
    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 AWSCluster
    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 clusterv1alpha4.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  
    95  // AWSIdentityKind defines allowed AWS identity types.
    96  type AWSIdentityKind string
    97  
    98  var (
    99  	// ControllerIdentityKind defines identity reference kind as AWSClusterControllerIdentity.
   100  	ControllerIdentityKind = AWSIdentityKind("AWSClusterControllerIdentity")
   101  
   102  	// ClusterRoleIdentityKind defines identity reference kind as AWSClusterRoleIdentity.
   103  	ClusterRoleIdentityKind = AWSIdentityKind("AWSClusterRoleIdentity")
   104  
   105  	// ClusterStaticIdentityKind defines identity reference kind as AWSClusterStaticIdentity.
   106  	ClusterStaticIdentityKind = AWSIdentityKind("AWSClusterStaticIdentity")
   107  )
   108  
   109  // AWSIdentityReference specifies a identity.
   110  type AWSIdentityReference struct {
   111  	// Name of the identity.
   112  	// +kubebuilder:validation:MinLength=1
   113  	Name string `json:"name"`
   114  
   115  	// Kind of the identity.
   116  	// +kubebuilder:validation:Enum=AWSClusterControllerIdentity;AWSClusterRoleIdentity;AWSClusterStaticIdentity
   117  	Kind AWSIdentityKind `json:"kind"`
   118  }
   119  
   120  // Bastion defines a bastion host.
   121  type Bastion struct {
   122  	// Enabled allows this provider to create a bastion host instance
   123  	// with a public ip to access the VPC private network.
   124  	// +optional
   125  	Enabled bool `json:"enabled"`
   126  
   127  	// DisableIngressRules will ensure there are no Ingress rules in the bastion host's security group.
   128  	// Requires AllowedCIDRBlocks to be empty.
   129  	// +optional
   130  	DisableIngressRules bool `json:"disableIngressRules,omitempty"`
   131  
   132  	// AllowedCIDRBlocks is a list of CIDR blocks allowed to access the bastion host.
   133  	// They are set as ingress rules for the Bastion host's Security Group (defaults to 0.0.0.0/0).
   134  	// +optional
   135  	AllowedCIDRBlocks []string `json:"allowedCIDRBlocks,omitempty"`
   136  
   137  	// InstanceType will use the specified instance type for the bastion. If not specified,
   138  	// Cluster API Provider AWS will use t3.micro for all regions except us-east-1, where t2.micro
   139  	// will be the default.
   140  	InstanceType string `json:"instanceType,omitempty"`
   141  
   142  	// AMI will use the specified AMI to boot the bastion. If not specified,
   143  	// the AMI will default to one picked out in public space.
   144  	// +optional
   145  	AMI string `json:"ami,omitempty"`
   146  }
   147  
   148  // AWSLoadBalancerSpec defines the desired state of an AWS load balancer.
   149  type AWSLoadBalancerSpec struct {
   150  	// Scheme sets the scheme of the load balancer (defaults to internet-facing)
   151  	// +kubebuilder:default=internet-facing
   152  	// +kubebuilder:validation:Enum=internet-facing;Internet-facing;internal
   153  	// +optional
   154  	Scheme *ClassicELBScheme `json:"scheme,omitempty"`
   155  
   156  	// CrossZoneLoadBalancing enables the classic ELB cross availability zone balancing.
   157  	//
   158  	// With cross-zone load balancing, each load balancer node for your Classic Load Balancer
   159  	// distributes requests evenly across the registered instances in all enabled Availability Zones.
   160  	// If cross-zone load balancing is disabled, each load balancer node distributes requests evenly across
   161  	// the registered instances in its Availability Zone only.
   162  	//
   163  	// Defaults to false.
   164  	// +optional
   165  	CrossZoneLoadBalancing bool `json:"crossZoneLoadBalancing"`
   166  
   167  	// 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)
   168  	// +optional
   169  	Subnets []string `json:"subnets,omitempty"`
   170  
   171  	// AdditionalSecurityGroups sets the security groups used by the load balancer. Expected to be security group IDs
   172  	// This is optional - if not provided new security groups will be created for the load balancer
   173  	// +optional
   174  	AdditionalSecurityGroups []string `json:"additionalSecurityGroups,omitempty"`
   175  }
   176  
   177  // AWSClusterStatus defines the observed state of AWSCluster
   178  type AWSClusterStatus struct {
   179  	// +kubebuilder:default=false
   180  	Ready          bool                           `json:"ready"`
   181  	Network        NetworkStatus                  `json:"networkStatus,omitempty"`
   182  	FailureDomains clusterv1alpha4.FailureDomains `json:"failureDomains,omitempty"`
   183  	Bastion        *Instance                      `json:"bastion,omitempty"`
   184  	Conditions     clusterv1alpha4.Conditions     `json:"conditions,omitempty"`
   185  }
   186  
   187  // +kubebuilder:object:root=true
   188  // +kubebuilder:resource:path=awsclusters,scope=Namespaced,categories=cluster-api,shortName=awsc
   189  // +kubebuilder:subresource:status
   190  // +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this AWSCluster belongs"
   191  // +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Cluster infrastructure is ready for EC2 instances"
   192  // +kubebuilder:printcolumn:name="VPC",type="string",JSONPath=".spec.network.vpc.id",description="AWS VPC the cluster is using"
   193  // +kubebuilder:printcolumn:name="Endpoint",type="string",JSONPath=".spec.controlPlaneEndpoint",description="API Endpoint",priority=1
   194  // +kubebuilder:printcolumn:name="Bastion IP",type="string",JSONPath=".status.bastion.publicIp",description="Bastion IP address for breakglass access"
   195  // +k8s:defaulter-gen=true
   196  
   197  // AWSCluster is the Schema for the awsclusters API.
   198  type AWSCluster struct {
   199  	metav1.TypeMeta   `json:",inline"`
   200  	metav1.ObjectMeta `json:"metadata,omitempty"`
   201  
   202  	Spec   AWSClusterSpec   `json:"spec,omitempty"`
   203  	Status AWSClusterStatus `json:"status,omitempty"`
   204  }
   205  
   206  // +kubebuilder:object:root=true
   207  
   208  // AWSClusterList contains a list of AWSCluster.
   209  type AWSClusterList struct {
   210  	metav1.TypeMeta `json:",inline"`
   211  	metav1.ListMeta `json:"metadata,omitempty"`
   212  	Items           []AWSCluster `json:"items"`
   213  }
   214  
   215  // GetConditions returns the observations of the operational state of the AWSCluster resource.
   216  func (r *AWSCluster) GetConditions() clusterv1alpha4.Conditions {
   217  	return r.Status.Conditions
   218  }
   219  
   220  // SetConditions sets the underlying service state of the AWSCluster to the predescribed clusterv1alpha4.Conditions.
   221  func (r *AWSCluster) SetConditions(conditions clusterv1alpha4.Conditions) {
   222  	r.Status.Conditions = conditions
   223  }
   224  
   225  func init() {
   226  	SchemeBuilder.Register(&AWSCluster{}, &AWSClusterList{})
   227  }