Skip to content

Commit 1317a26

Browse files
authored
Merge pull request #3832 from Ankitasw/cleanup-internet-facing-logic
Clean up internet-facing loadbalancer scheme logic
2 parents 5eb7ee3 + ce55e2f commit 1317a26

File tree

5 files changed

+18
-57
lines changed

5 files changed

+18
-57
lines changed

api/v1beta2/awscluster_webhook.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ func (r *AWSCluster) ValidateUpdate(old runtime.Object) error {
8181
}
8282

8383
newLoadBalancer := &AWSLoadBalancerSpec{}
84+
existingLoadBalancer := &AWSLoadBalancerSpec{}
8485

8586
if r.Spec.ControlPlaneLoadBalancer != nil {
8687
newLoadBalancer = r.Spec.ControlPlaneLoadBalancer.DeepCopy()
8788
}
8889

90+
if oldC.Spec.ControlPlaneLoadBalancer != nil {
91+
existingLoadBalancer = oldC.Spec.ControlPlaneLoadBalancer.DeepCopy()
92+
}
8993
if oldC.Spec.ControlPlaneLoadBalancer == nil {
9094
// If old scheme was nil, the only value accepted here is the default value: internet-facing
9195
if newLoadBalancer.Scheme != nil && newLoadBalancer.Scheme.String() != ClassicELBSchemeInternetFacing.String() {
@@ -96,16 +100,11 @@ func (r *AWSCluster) ValidateUpdate(old runtime.Object) error {
96100
}
97101
} else {
98102
// If old scheme was not nil, the new scheme should be the same.
99-
existingLoadBalancer := oldC.Spec.ControlPlaneLoadBalancer.DeepCopy()
100103
if !cmp.Equal(existingLoadBalancer.Scheme, newLoadBalancer.Scheme) {
101-
// Only allow changes from Internet-facing scheme to internet-facing.
102-
if !(existingLoadBalancer.Scheme.String() == ClassicELBSchemeIncorrectInternetFacing.String() &&
103-
newLoadBalancer.Scheme.String() == ClassicELBSchemeInternetFacing.String()) {
104-
allErrs = append(allErrs,
105-
field.Invalid(field.NewPath("spec", "controlPlaneLoadBalancer", "scheme"),
106-
r.Spec.ControlPlaneLoadBalancer.Scheme, "field is immutable"),
107-
)
108-
}
104+
allErrs = append(allErrs,
105+
field.Invalid(field.NewPath("spec", "controlPlaneLoadBalancer", "scheme"),
106+
r.Spec.ControlPlaneLoadBalancer.Scheme, "field is immutable"),
107+
)
109108
}
110109
// The name must be defined when the AWSCluster is created. If it is not defined,
111110
// then the controller generates a default name at runtime, but does not store it,
@@ -116,16 +115,16 @@ func (r *AWSCluster) ValidateUpdate(old runtime.Object) error {
116115
r.Spec.ControlPlaneLoadBalancer.Name, "field is immutable"),
117116
)
118117
}
118+
}
119119

120-
// Block the update for HealthCheckProtocol :
121-
// - if it was not set in old spec but added in new spec
122-
// - if it was set in old spec but changed in new spec
123-
if !cmp.Equal(newLoadBalancer.HealthCheckProtocol, existingLoadBalancer.HealthCheckProtocol) {
124-
allErrs = append(allErrs,
125-
field.Invalid(field.NewPath("spec", "controlPlaneLoadBalancer", "healthCheckProtocol"),
126-
newLoadBalancer.HealthCheckProtocol, "field is immutable once set"),
127-
)
128-
}
120+
// Block the update for HealthCheckProtocol :
121+
// - if it was not set in old spec but added in new spec
122+
// - if it was set in old spec but changed in new spec
123+
if !cmp.Equal(newLoadBalancer.HealthCheckProtocol, existingLoadBalancer.HealthCheckProtocol) {
124+
allErrs = append(allErrs,
125+
field.Invalid(field.NewPath("spec", "controlPlaneLoadBalancer", "healthCheckProtocol"),
126+
newLoadBalancer.HealthCheckProtocol, "field is immutable once set"),
127+
)
129128
}
130129

131130
if !cmp.Equal(oldC.Spec.ControlPlaneEndpoint, clusterv1.APIEndpoint{}) &&

api/v1beta2/awscluster_webhook_test.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,7 @@ func TestAWSCluster_ValidateCreate(t *testing.T) {
5252
}{
5353
// The SSHKeyName tests were moved to sshkeyname_test.go
5454
{
55-
name: "Default nil scheme to `internet-facing`",
56-
cluster: &AWSCluster{
57-
Spec: AWSClusterSpec{},
58-
},
59-
expect: func(g *WithT, res *AWSLoadBalancerSpec) {
60-
g.Expect(res.Scheme.String(), ClassicELBSchemeInternetFacing.String())
61-
},
62-
wantErr: false,
63-
},
64-
{
65-
name: "Internet-facing ELB scheme is defaulted to internet-facing during creation",
66-
cluster: &AWSCluster{
67-
Spec: AWSClusterSpec{
68-
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{Scheme: &ClassicELBSchemeIncorrectInternetFacing},
69-
},
70-
},
71-
expect: func(g *WithT, res *AWSLoadBalancerSpec) {
72-
g.Expect(res.Scheme.String(), ClassicELBSchemeInternetFacing.String())
73-
},
74-
wantErr: false,
75-
},
76-
{
77-
name: "Supported schemes are 'internet-facing, Internet-facing, internal, or nil', rest will be rejected",
55+
name: "Supported schemes are 'internet-facing, internal, or nil', rest will be rejected",
7856
cluster: &AWSCluster{
7957
Spec: AWSClusterSpec{
8058
ControlPlaneLoadBalancer: &AWSLoadBalancerSpec{Scheme: &unsupportedIncorrectScheme},

api/v1beta2/defaults.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,8 @@ func SetDefaults_AWSClusterSpec(s *AWSClusterSpec) { //nolint:golint,stylecheck
6060
Name: AWSClusterControllerIdentityName,
6161
}
6262
}
63-
64-
// If ELB scheme is set to Internet-facing due to an API bug in versions > v0.6.6 and v0.7.0, default it to internet-facing.
6563
if s.ControlPlaneLoadBalancer == nil {
6664
s.ControlPlaneLoadBalancer = &AWSLoadBalancerSpec{Scheme: &ClassicELBSchemeInternetFacing}
67-
} else if s.ControlPlaneLoadBalancer.Scheme != nil && s.ControlPlaneLoadBalancer.Scheme.String() == ClassicELBSchemeIncorrectInternetFacing.String() {
68-
s.ControlPlaneLoadBalancer.Scheme = &ClassicELBSchemeInternetFacing
6965
}
7066
}
7167

api/v1beta2/network_types.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ var (
4242
// ClassicELBSchemeInternal defines an internal-only facing
4343
// load balancer internal to an ELB.
4444
ClassicELBSchemeInternal = ClassicELBScheme("internal")
45-
46-
// ClassicELBSchemeIncorrectInternetFacing was inaccurately used to define an internet-facing LB in v0.6 releases > v0.6.6 and v0.7.0 release.
47-
ClassicELBSchemeIncorrectInternetFacing = ClassicELBScheme("Internet-facing")
4845
)
4946

5047
func (e ClassicELBScheme) String() string {

pkg/cloud/services/elb/loadbalancer.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ const maxELBsDescribeTagsRequest = 20
5454
func (s *Service) ReconcileLoadbalancers() error {
5555
s.scope.Debug("Reconciling load balancers")
5656

57-
// If ELB scheme is set to Internet-facing due to an API bug in versions > v0.6.6 and v0.7.0, change it to internet-facing and patch.
58-
if s.scope.ControlPlaneLoadBalancerScheme().String() == infrav1.ClassicELBSchemeIncorrectInternetFacing.String() {
59-
s.scope.ControlPlaneLoadBalancer().Scheme = &infrav1.ClassicELBSchemeInternetFacing
60-
if err := s.scope.PatchObject(); err != nil {
61-
return err
62-
}
63-
s.scope.Trace("Patched control plane load balancer scheme")
64-
}
65-
6657
// Generate a default control plane load balancer name. The load balancer name cannot be
6758
// generated by the defaulting webhook, because it is derived from the cluster name, and that
6859
// name is undefined at defaulting time when generateName is used.

0 commit comments

Comments
 (0)