diff --git a/api/v1beta2/awscluster_webhook.go b/api/v1beta2/awscluster_webhook.go index e95bdb044e..88d5965d3e 100644 --- a/api/v1beta2/awscluster_webhook.go +++ b/api/v1beta2/awscluster_webhook.go @@ -180,16 +180,16 @@ func (r *AWSCluster) validateControlPlaneLoadBalancerUpdate(oldlb, newlb *AWSLoa newlb.Name, "field is immutable"), ) } - } - // Block the update for Protocol : - // - if it was not set in old spec but added in new spec - // - if it was set in old spec but changed in new spec - if !cmp.Equal(newlb.HealthCheckProtocol, oldlb.HealthCheckProtocol) { - allErrs = append(allErrs, - field.Invalid(field.NewPath("spec", "controlPlaneLoadBalancer", "healthCheckProtocol"), - newlb.HealthCheckProtocol, "field is immutable once set"), - ) + // Block the update for Protocol : + // - if it was not set in old spec but added in new spec + // - if it was set in old spec but changed in new spec + if !cmp.Equal(newlb.HealthCheckProtocol, oldlb.HealthCheckProtocol) { + allErrs = append(allErrs, + field.Invalid(field.NewPath("spec", "controlPlaneLoadBalancer", "healthCheckProtocol"), + newlb.HealthCheckProtocol, "field is immutable once set"), + ) + } } return allErrs diff --git a/api/v1beta2/awscluster_webhook_test.go b/api/v1beta2/awscluster_webhook_test.go index 41bc5d3b1c..13260b0341 100644 --- a/api/v1beta2/awscluster_webhook_test.go +++ b/api/v1beta2/awscluster_webhook_test.go @@ -984,6 +984,20 @@ func TestAWSClusterValidateUpdate(t *testing.T) { }, wantErr: true, }, + { + name: "Should pass if old secondary lb is absent", + oldCluster: &AWSCluster{ + Spec: AWSClusterSpec{}, + }, + newCluster: &AWSCluster{ + Spec: AWSClusterSpec{ + SecondaryControlPlaneLoadBalancer: &AWSLoadBalancerSpec{ + Name: ptr.To("test-lb"), + }, + }, + }, + wantErr: false, + }, { name: "Should pass if controlPlaneLoadBalancer healthcheckprotocol is same after update", oldCluster: &AWSCluster{