Skip to content

Commit 7549bed

Browse files
authored
Merge pull request #3804 from Skarlso/create_nlb
Add ability to use NLBs as control plane load-balancers
2 parents 6fef355 + 681762d commit 7549bed

36 files changed

+3557
-408
lines changed

api/v1beta1/awscluster_conversion.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,30 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
4141
}
4242
restoreControlPlaneLoadBalancer(restored.Spec.ControlPlaneLoadBalancer, dst.Spec.ControlPlaneLoadBalancer)
4343
}
44+
restoreControlPlaneLoadBalancerStatus(&restored.Status.Network.APIServerELB, &dst.Status.Network.APIServerELB)
4445

4546
dst.Spec.S3Bucket = restored.Spec.S3Bucket
4647

4748
return nil
4849
}
4950

51+
// restoreControlPlaneLoadBalancerStatus manually restores the control plane loadbalancer status data.
52+
// Assumes restored and dst are non-nil.
53+
func restoreControlPlaneLoadBalancerStatus(restored, dst *infrav1.LoadBalancer) {
54+
dst.ARN = restored.ARN
55+
dst.LoadBalancerType = restored.LoadBalancerType
56+
dst.ELBAttributes = restored.ELBAttributes
57+
dst.ELBListeners = restored.ELBListeners
58+
}
59+
5060
// restoreControlPlaneLoadBalancer manually restores the control plane loadbalancer data.
5161
// Assumes restored and dst are non-nil.
5262
func restoreControlPlaneLoadBalancer(restored, dst *infrav1.AWSLoadBalancerSpec) {
5363
dst.Name = restored.Name
5464
dst.HealthCheckProtocol = restored.HealthCheckProtocol
65+
dst.LoadBalancerType = restored.LoadBalancerType
66+
dst.DisableHostsRewrite = restored.DisableHostsRewrite
67+
dst.PreserveClientIP = restored.PreserveClientIP
5568
}
5669

5770
// ConvertFrom converts the v1beta1 AWSCluster receiver to a v1beta1 AWSCluster.

api/v1beta1/conversion.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"unsafe"
21+
2022
"k8s.io/apimachinery/pkg/conversion"
2123
"sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2224
)
@@ -32,3 +34,39 @@ func Convert_v1beta1_AWSResourceReference_To_v1beta2_AWSResourceReference(in *AW
3234
func Convert_v1beta1_AWSMachineSpec_To_v1beta2_AWSMachineSpec(in *AWSMachineSpec, out *v1beta2.AWSMachineSpec, s conversion.Scope) error {
3335
return autoConvert_v1beta1_AWSMachineSpec_To_v1beta2_AWSMachineSpec(in, out, s)
3436
}
37+
38+
func Convert_v1beta2_AWSLoadBalancerSpec_To_v1beta1_AWSLoadBalancerSpec(in *v1beta2.AWSLoadBalancerSpec, out *AWSLoadBalancerSpec, s conversion.Scope) error {
39+
return autoConvert_v1beta2_AWSLoadBalancerSpec_To_v1beta1_AWSLoadBalancerSpec(in, out, s)
40+
}
41+
42+
func Convert_v1beta2_NetworkStatus_To_v1beta1_NetworkStatus(in *v1beta2.NetworkStatus, out *NetworkStatus, s conversion.Scope) error {
43+
return autoConvert_v1beta2_NetworkStatus_To_v1beta1_NetworkStatus(in, out, s)
44+
}
45+
46+
func Convert_v1beta1_ClassicELB_To_v1beta2_LoadBalancer(in *ClassicELB, out *v1beta2.LoadBalancer, s conversion.Scope) error {
47+
out.Name = in.Name
48+
out.DNSName = in.DNSName
49+
out.Scheme = v1beta2.ELBScheme(in.Scheme)
50+
out.HealthCheck = (*v1beta2.ClassicELBHealthCheck)(in.HealthCheck)
51+
out.AvailabilityZones = in.AvailabilityZones
52+
out.ClassicElbAttributes = (v1beta2.ClassicELBAttributes)(in.Attributes)
53+
out.ClassicELBListeners = *(*[]v1beta2.ClassicELBListener)(unsafe.Pointer(&in.Listeners))
54+
out.SecurityGroupIDs = in.SecurityGroupIDs
55+
out.Tags = in.Tags
56+
out.SubnetIDs = in.SubnetIDs
57+
return nil
58+
}
59+
60+
func Convert_v1beta2_LoadBalancer_To_v1beta1_ClassicELB(in *v1beta2.LoadBalancer, out *ClassicELB, s conversion.Scope) error {
61+
out.Name = in.Name
62+
out.DNSName = in.DNSName
63+
out.Scheme = ClassicELBScheme(in.Scheme)
64+
out.HealthCheck = (*ClassicELBHealthCheck)(in.HealthCheck)
65+
out.AvailabilityZones = in.AvailabilityZones
66+
out.Attributes = (ClassicELBAttributes)(in.ClassicElbAttributes)
67+
out.Listeners = *(*[]ClassicELBListener)(unsafe.Pointer(&in.ClassicELBListeners))
68+
out.SecurityGroupIDs = in.SecurityGroupIDs
69+
out.Tags = in.Tags
70+
out.SubnetIDs = in.SubnetIDs
71+
return nil
72+
}

api/v1beta1/zz_generated.conversion.go

Lines changed: 47 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/awscluster_types.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ type Bastion struct {
152152
AMI string `json:"ami,omitempty"`
153153
}
154154

155+
type LoadBalancerType string
156+
157+
var (
158+
LoadBalancerTypeClassic = LoadBalancerType("classic")
159+
LoadBalancerTypeELB = LoadBalancerType("elb")
160+
LoadBalancerTypeALB = LoadBalancerType("alb")
161+
LoadBalancerTypeNLB = LoadBalancerType("nlb")
162+
)
163+
155164
// AWSLoadBalancerSpec defines the desired state of an AWS load balancer.
156165
type AWSLoadBalancerSpec struct {
157166
// Name sets the name of the classic ELB load balancer. As per AWS, the name must be unique
@@ -167,7 +176,7 @@ type AWSLoadBalancerSpec struct {
167176
// +kubebuilder:default=internet-facing
168177
// +kubebuilder:validation:Enum=internet-facing;internal
169178
// +optional
170-
Scheme *ClassicELBScheme `json:"scheme,omitempty"`
179+
Scheme *ELBScheme `json:"scheme,omitempty"`
171180

172181
// CrossZoneLoadBalancing enables the classic ELB cross availability zone balancing.
173182
//
@@ -184,15 +193,27 @@ type AWSLoadBalancerSpec struct {
184193
// +optional
185194
Subnets []string `json:"subnets,omitempty"`
186195

187-
// HealthCheckProtocol sets the protocol type for classic ELB health check target
188-
// default value is ClassicELBProtocolSSL
196+
// HealthCheckProtocol sets the protocol type for ELB health check target
197+
// default value is ELBProtocolSSL
189198
// +optional
190-
HealthCheckProtocol *ClassicELBProtocol `json:"healthCheckProtocol,omitempty"`
199+
HealthCheckProtocol *ELBProtocol `json:"healthCheckProtocol,omitempty"`
191200

192201
// AdditionalSecurityGroups sets the security groups used by the load balancer. Expected to be security group IDs
193202
// This is optional - if not provided new security groups will be created for the load balancer
194203
// +optional
195204
AdditionalSecurityGroups []string `json:"additionalSecurityGroups,omitempty"`
205+
206+
// LoadBalancerType sets the type for a load balancer. The default type is classic.
207+
// +kubebuilder:validation:Enum:=classic;elb;alb;nlb
208+
LoadBalancerType LoadBalancerType `json:"loadBalancerType,omitempty"`
209+
210+
// DisableHostsRewrite disabled the hair pinning issue solution that adds the NLB's address as 127.0.0.1 to the hosts
211+
// file of each instance. This is by default, false.
212+
DisableHostsRewrite bool `json:"disableHostsRewrite,omitempty"`
213+
214+
// PreserveClientIP lets the user control if preservation of client ips must be retained or not.
215+
// If this is enabled 6443 will be opened to 0.0.0.0/0.
216+
PreserveClientIP bool `json:"preserveClientIP,omitempty"`
196217
}
197218

198219
// AWSClusterStatus defines the observed state of AWSCluster.

api/v1beta2/awscluster_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (r *AWSCluster) ValidateUpdate(old runtime.Object) error {
9292
}
9393
if oldC.Spec.ControlPlaneLoadBalancer == nil {
9494
// If old scheme was nil, the only value accepted here is the default value: internet-facing
95-
if newLoadBalancer.Scheme != nil && newLoadBalancer.Scheme.String() != ClassicELBSchemeInternetFacing.String() {
95+
if newLoadBalancer.Scheme != nil && newLoadBalancer.Scheme.String() != ELBSchemeInternetFacing.String() {
9696
allErrs = append(allErrs,
9797
field.Invalid(field.NewPath("spec", "controlPlaneLoadBalancer", "scheme"),
9898
r.Spec.ControlPlaneLoadBalancer.Scheme, "field is immutable, default value was set to internet-facing"),
@@ -117,7 +117,7 @@ func (r *AWSCluster) ValidateUpdate(old runtime.Object) error {
117117
}
118118
}
119119

120-
// Block the update for HealthCheckProtocol :
120+
// Block the update for Protocol :
121121
// - if it was not set in old spec but added in new spec
122122
// - if it was set in old spec but changed in new spec
123123
if !cmp.Equal(newLoadBalancer.HealthCheckProtocol, existingLoadBalancer.HealthCheckProtocol) {

0 commit comments

Comments
 (0)