/
awscluster_types.go
237 lines (194 loc) · 10.3 KB
/
awscluster_types.go
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
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
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"
)
// AWSClusterSpec defines the desired state of an EC2-based Kubernetes cluster.
type AWSClusterSpec struct {
// NetworkSpec encapsulates all things related to AWS network.
NetworkSpec NetworkSpec `json:"network,omitempty"`
// The AWS Region the cluster lives in.
Region string `json:"region,omitempty"`
// 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
SSHKeyName *string `json:"sshKeyName,omitempty"`
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
// 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
AdditionalTags Tags `json:"additionalTags,omitempty"`
// ControlPlaneLoadBalancer is optional configuration for customizing control plane behavior.
// +optional
ControlPlaneLoadBalancer *AWSLoadBalancerSpec `json:"controlPlaneLoadBalancer,omitempty"`
// 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
ImageLookupFormat string `json:"imageLookupFormat,omitempty"`
// 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
ImageLookupOrg string `json:"imageLookupOrg,omitempty"`
// 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.
ImageLookupBaseOS string `json:"imageLookupBaseOS,omitempty"`
// Bastion contains options to configure the bastion host.
// +optional
Bastion Bastion `json:"bastion"`
// IdentityRef is a reference to a identity to be used when reconciling this cluster
// +optional
IdentityRef *AWSIdentityReference `json:"identityRef,omitempty"`
}
// AWSIdentityKind defines allowed AWS identity types.
type AWSIdentityKind string
var (
// ControllerIdentityKind defines identity reference kind as AWSClusterControllerIdentity.
ControllerIdentityKind = AWSIdentityKind("AWSClusterControllerIdentity")
// ClusterRoleIdentityKind defines identity reference kind as AWSClusterRoleIdentity.
ClusterRoleIdentityKind = AWSIdentityKind("AWSClusterRoleIdentity")
// ClusterStaticIdentityKind defines identity reference kind as AWSClusterStaticIdentity.
ClusterStaticIdentityKind = AWSIdentityKind("AWSClusterStaticIdentity")
)
// AWSIdentityReference specifies a identity.
type AWSIdentityReference struct {
// Name of the identity.
// +kubebuilder:validation:MinLength=1
Name string `json:"name"`
// Kind of the identity.
// +kubebuilder:validation:Enum=AWSClusterControllerIdentity;AWSClusterRoleIdentity;AWSClusterStaticIdentity
Kind AWSIdentityKind `json:"kind"`
}
// Bastion defines a bastion host.
type Bastion struct {
// Enabled allows this provider to create a bastion host instance
// with a public ip to access the VPC private network.
// +optional
Enabled bool `json:"enabled"`
// DisableIngressRules will ensure there are no Ingress rules in the bastion host's security group.
// Requires AllowedCIDRBlocks to be empty.
// +optional
DisableIngressRules bool `json:"disableIngressRules,omitempty"`
// 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
AllowedCIDRBlocks []string `json:"allowedCIDRBlocks,omitempty"`
// 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.
InstanceType string `json:"instanceType,omitempty"`
// 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
AMI string `json:"ami,omitempty"`
}
// AWSLoadBalancerSpec defines the desired state of an AWS load balancer.
type AWSLoadBalancerSpec struct {
// 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
Name *string `json:"name,omitempty"`
// Scheme sets the scheme of the load balancer (defaults to internet-facing)
// +kubebuilder:default=internet-facing
// +kubebuilder:validation:Enum=internet-facing;internal
// +optional
Scheme *ClassicELBScheme `json:"scheme,omitempty"`
// 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
CrossZoneLoadBalancing 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
Subnets []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
AdditionalSecurityGroups []string `json:"additionalSecurityGroups,omitempty"`
}
// AWSClusterStatus defines the observed state of AWSCluster.
type AWSClusterStatus struct {
// +kubebuilder:default=false
Ready bool `json:"ready"`
Network NetworkStatus `json:"networkStatus,omitempty"`
FailureDomains clusterv1.FailureDomains `json:"failureDomains,omitempty"`
Bastion *Instance `json:"bastion,omitempty"`
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
}
// +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{})
}