@@ -81,11 +81,15 @@ func (r *AWSCluster) ValidateUpdate(old runtime.Object) error {
81
81
}
82
82
83
83
newLoadBalancer := & AWSLoadBalancerSpec {}
84
+ existingLoadBalancer := & AWSLoadBalancerSpec {}
84
85
85
86
if r .Spec .ControlPlaneLoadBalancer != nil {
86
87
newLoadBalancer = r .Spec .ControlPlaneLoadBalancer .DeepCopy ()
87
88
}
88
89
90
+ if oldC .Spec .ControlPlaneLoadBalancer != nil {
91
+ existingLoadBalancer = oldC .Spec .ControlPlaneLoadBalancer .DeepCopy ()
92
+ }
89
93
if oldC .Spec .ControlPlaneLoadBalancer == nil {
90
94
// If old scheme was nil, the only value accepted here is the default value: internet-facing
91
95
if newLoadBalancer .Scheme != nil && newLoadBalancer .Scheme .String () != ClassicELBSchemeInternetFacing .String () {
@@ -96,16 +100,11 @@ func (r *AWSCluster) ValidateUpdate(old runtime.Object) error {
96
100
}
97
101
} else {
98
102
// If old scheme was not nil, the new scheme should be the same.
99
- existingLoadBalancer := oldC .Spec .ControlPlaneLoadBalancer .DeepCopy ()
100
103
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
+ )
109
108
}
110
109
// The name must be defined when the AWSCluster is created. If it is not defined,
111
110
// 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 {
116
115
r .Spec .ControlPlaneLoadBalancer .Name , "field is immutable" ),
117
116
)
118
117
}
118
+ }
119
119
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
+ )
129
128
}
130
129
131
130
if ! cmp .Equal (oldC .Spec .ControlPlaneEndpoint , clusterv1.APIEndpoint {}) &&
0 commit comments