Skip to content

Commit 7e87185

Browse files
committed
Complete restructure of the old LoadBalancer keeping the old json tags
1 parent 652e97a commit 7e87185

25 files changed

+556
-680
lines changed

api/v1beta1/awscluster_conversion.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,22 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
4141
}
4242
restoreControlPlaneLoadBalancer(restored.Spec.ControlPlaneLoadBalancer, dst.Spec.ControlPlaneLoadBalancer)
4343
}
44-
45-
restoreControlPlaneLoadBalancerStatus(&restored.Status.Network, &dst.Status.Network)
44+
restoreControlPlaneLoadBalancerStatus(&restored.Status.Network.APIServerELB, &dst.Status.Network.APIServerELB)
4645

4746
dst.Spec.S3Bucket = restored.Spec.S3Bucket
4847

4948
return nil
5049
}
5150

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.V2Attributes = restored.V2Attributes
57+
dst.V2Listeners = restored.V2Listeners
58+
}
59+
5260
// restoreControlPlaneLoadBalancer manually restores the control plane loadbalancer data.
5361
// Assumes restored and dst are non-nil.
5462
func restoreControlPlaneLoadBalancer(restored, dst *infrav1.AWSLoadBalancerSpec) {
@@ -58,12 +66,6 @@ func restoreControlPlaneLoadBalancer(restored, dst *infrav1.AWSLoadBalancerSpec)
5866
dst.DisableHostsRewrite = restored.DisableHostsRewrite
5967
}
6068

61-
// restoreControlPlaneLoadBalancerStatus manually restores the control plane loadbalancer status data.
62-
// Assumes restored and dst are non-nil.
63-
func restoreControlPlaneLoadBalancerStatus(restored, dst *infrav1.NetworkStatus) {
64-
dst.APIServerLB = restored.APIServerLB
65-
}
66-
6769
// ConvertFrom converts the v1beta1 AWSCluster receiver to a v1beta1 AWSCluster.
6870
func (r *AWSCluster) ConvertFrom(srcRaw conversion.Hub) error {
6971
src := srcRaw.(*infrav1.AWSCluster)

api/v1beta1/conversion.go

Lines changed: 30 additions & 4 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
)
@@ -37,10 +39,34 @@ func Convert_v1beta2_AWSLoadBalancerSpec_To_v1beta1_AWSLoadBalancerSpec(in *v1be
3739
return autoConvert_v1beta2_AWSLoadBalancerSpec_To_v1beta1_AWSLoadBalancerSpec(in, out, s)
3840
}
3941

40-
func Convert_v1beta1_ClassicELB_To_v1beta2_ClassicELB(in *ClassicELB, out *v1beta2.ClassicELB, s conversion.Scope) error {
41-
return autoConvert_v1beta1_ClassicELB_To_v1beta2_ClassicELB(in, out, s)
42-
}
43-
4442
func Convert_v1beta2_NetworkStatus_To_v1beta1_NetworkStatus(in *v1beta2.NetworkStatus, out *NetworkStatus, s conversion.Scope) error {
4543
return autoConvert_v1beta2_NetworkStatus_To_v1beta1_NetworkStatus(in, out, s)
4644
}
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: 16 additions & 49 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ type AWSLoadBalancerSpec struct {
176176
// +kubebuilder:default=internet-facing
177177
// +kubebuilder:validation:Enum=internet-facing;internal
178178
// +optional
179-
Scheme *ClassicELBScheme `json:"scheme,omitempty"`
179+
Scheme *ElbScheme `json:"scheme,omitempty"`
180180

181181
// CrossZoneLoadBalancing enables the classic ELB cross availability zone balancing.
182182
//
@@ -194,9 +194,9 @@ type AWSLoadBalancerSpec struct {
194194
Subnets []string `json:"subnets,omitempty"`
195195

196196
// HealthCheckProtocol sets the protocol type for classic ELB health check target
197-
// default value is ClassicELBProtocolSSL
197+
// default value is ElbProtocolSSL
198198
// +optional
199-
HealthCheckProtocol *ClassicELBProtocol `json:"healthCheckProtocol,omitempty"`
199+
HealthCheckProtocol *ElbProtocol `json:"healthCheckProtocol,omitempty"`
200200

201201
// AdditionalSecurityGroups sets the security groups used by the load balancer. Expected to be security group IDs
202202
// This is optional - if not provided new security groups will be created for the load balancer

api/v1beta2/awscluster_webhook.go

Lines changed: 1 addition & 1 deletion
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"),

api/v1beta2/awscluster_webhook_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestAWSClusterDefault(t *testing.T) {
4242
}
4343

4444
func TestAWSCluster_ValidateCreate(t *testing.T) {
45-
unsupportedIncorrectScheme := ClassicELBScheme("any-other-scheme")
45+
unsupportedIncorrectScheme := ElbScheme("any-other-scheme")
4646

4747
tests := []struct {
4848
name string
@@ -52,7 +52,7 @@ func TestAWSCluster_ValidateCreate(t *testing.T) {
5252
}{
5353
// The SSHKeyName tests were moved to sshkeyname_test.go
5454
{
55-
name: "Supported schemes are 'internet-facing, internal, or nil', rest will be rejected",
55+
name: "Supported schemes are 'internet-facing, Internet-facing, internal, or nil', rest will be rejected",
5656
cluster: &AWSCluster{
5757
Spec: AWSClusterSpec{
5858
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{Scheme: &unsupportedIncorrectScheme},
@@ -351,14 +351,14 @@ func TestAWSCluster_ValidateUpdate(t *testing.T) {
351351
oldCluster: &AWSCluster{
352352
Spec: AWSClusterSpec{
353353
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
354-
Scheme: &ClassicELBSchemeInternal,
354+
Scheme: &ElbSchemeInternal,
355355
},
356356
},
357357
},
358358
newCluster: &AWSCluster{
359359
Spec: AWSClusterSpec{
360360
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
361-
Scheme: &ClassicELBSchemeInternetFacing,
361+
Scheme: &ElbSchemeInternetFacing,
362362
},
363363
},
364364
},
@@ -372,7 +372,7 @@ func TestAWSCluster_ValidateUpdate(t *testing.T) {
372372
newCluster: &AWSCluster{
373373
Spec: AWSClusterSpec{
374374
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
375-
Scheme: &ClassicELBSchemeInternal,
375+
Scheme: &ElbSchemeInternal,
376376
},
377377
},
378378
},
@@ -386,7 +386,7 @@ func TestAWSCluster_ValidateUpdate(t *testing.T) {
386386
newCluster: &AWSCluster{
387387
Spec: AWSClusterSpec{
388388
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
389-
Scheme: &ClassicELBSchemeInternetFacing,
389+
Scheme: &ElbSchemeInternetFacing,
390390
},
391391
},
392392
},
@@ -526,14 +526,14 @@ func TestAWSCluster_ValidateUpdate(t *testing.T) {
526526
oldCluster: &AWSCluster{
527527
Spec: AWSClusterSpec{
528528
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
529-
HealthCheckProtocol: &ClassicELBProtocolTCP,
529+
HealthCheckProtocol: &ElbProtocolTCP,
530530
},
531531
},
532532
},
533533
newCluster: &AWSCluster{
534534
Spec: AWSClusterSpec{
535535
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
536-
HealthCheckProtocol: &ClassicELBProtocolSSL,
536+
HealthCheckProtocol: &ElbProtocolSSL,
537537
},
538538
},
539539
},
@@ -544,14 +544,14 @@ func TestAWSCluster_ValidateUpdate(t *testing.T) {
544544
oldCluster: &AWSCluster{
545545
Spec: AWSClusterSpec{
546546
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
547-
HealthCheckProtocol: &ClassicELBProtocolTCP,
547+
HealthCheckProtocol: &ElbProtocolTCP,
548548
},
549549
},
550550
},
551551
newCluster: &AWSCluster{
552552
Spec: AWSClusterSpec{
553553
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
554-
HealthCheckProtocol: &ClassicELBProtocolTCP,
554+
HealthCheckProtocol: &ElbProtocolTCP,
555555
},
556556
},
557557
},
@@ -565,7 +565,7 @@ func TestAWSCluster_ValidateUpdate(t *testing.T) {
565565
newCluster: &AWSCluster{
566566
Spec: AWSClusterSpec{
567567
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{
568-
HealthCheckProtocol: &ClassicELBProtocolTCP,
568+
HealthCheckProtocol: &ElbProtocolTCP,
569569
},
570570
},
571571
},

api/v1beta2/defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func SetDefaults_AWSClusterSpec(s *AWSClusterSpec) { //nolint:golint,stylecheck
6363
}
6464
if s.ControlPlaneLoadBalancer == nil {
6565
s.ControlPlaneLoadBalancer = &AWSLoadBalancerSpec{
66-
Scheme: &ClassicELBSchemeInternetFacing,
66+
Scheme: &ElbSchemeInternetFacing,
6767
LoadBalancerType: LoadBalancerTypeClassic,
6868
}
6969
}

0 commit comments

Comments
 (0)