Skip to content

Commit 8b04806

Browse files
committed
webhook: Add validation for load balancer zone immutability
Add webhook validation to enforce Azure's requirement that availability zones cannot be changed after a load balancer is created. The validation checks all three load balancer types: - APIServerLB - NodeOutboundLB - ControlPlaneOutboundLB Any attempt to modify zones on an existing load balancer will be rejected at admission time with a clear error message, preventing users from attempting operations that would fail at the Azure API level.
1 parent 51f6e1a commit 8b04806

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

api/v1beta1/azurecluster_webhook.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,43 @@ func (*AzureClusterWebhook) ValidateUpdate(_ context.Context, oldRaw, newObj run
169169
allErrs = append(allErrs, err)
170170
}
171171

172+
// Validate availability zones are immutable for load balancers
173+
if c.Spec.NetworkSpec.APIServerLB != nil && old.Spec.NetworkSpec.APIServerLB != nil {
174+
if !webhookutils.EnsureStringSlicesAreEquivalent(
175+
c.Spec.NetworkSpec.APIServerLB.AvailabilityZones,
176+
old.Spec.NetworkSpec.APIServerLB.AvailabilityZones) {
177+
allErrs = append(allErrs,
178+
field.Invalid(
179+
field.NewPath("spec", "networkSpec", "apiServerLB", "availabilityZones"),
180+
c.Spec.NetworkSpec.APIServerLB.AvailabilityZones,
181+
"field is immutable"))
182+
}
183+
}
184+
185+
if c.Spec.NetworkSpec.NodeOutboundLB != nil && old.Spec.NetworkSpec.NodeOutboundLB != nil {
186+
if !webhookutils.EnsureStringSlicesAreEquivalent(
187+
c.Spec.NetworkSpec.NodeOutboundLB.AvailabilityZones,
188+
old.Spec.NetworkSpec.NodeOutboundLB.AvailabilityZones) {
189+
allErrs = append(allErrs,
190+
field.Invalid(
191+
field.NewPath("spec", "networkSpec", "nodeOutboundLB", "availabilityZones"),
192+
c.Spec.NetworkSpec.NodeOutboundLB.AvailabilityZones,
193+
"field is immutable"))
194+
}
195+
}
196+
197+
if c.Spec.NetworkSpec.ControlPlaneOutboundLB != nil && old.Spec.NetworkSpec.ControlPlaneOutboundLB != nil {
198+
if !webhookutils.EnsureStringSlicesAreEquivalent(
199+
c.Spec.NetworkSpec.ControlPlaneOutboundLB.AvailabilityZones,
200+
old.Spec.NetworkSpec.ControlPlaneOutboundLB.AvailabilityZones) {
201+
allErrs = append(allErrs,
202+
field.Invalid(
203+
field.NewPath("spec", "networkSpec", "controlPlaneOutboundLB", "availabilityZones"),
204+
c.Spec.NetworkSpec.ControlPlaneOutboundLB.AvailabilityZones,
205+
"field is immutable"))
206+
}
207+
}
208+
172209
allErrs = append(allErrs, c.validateSubnetUpdate(old)...)
173210

174211
if len(allErrs) == 0 {

0 commit comments

Comments
 (0)