Skip to content

Commit 8c6bd5f

Browse files
committed
Fix Azure Private Cluster
1 parent 31a7780 commit 8c6bd5f

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

api/v1beta1/azurecluster_default.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ func (c *AzureCluster) setAPIServerLBDefaults() {
278278
}
279279
}
280280
} else if lb.Type == Internal {
281+
var privateIP string
282+
if lb.PrivateIP == "" {
283+
privateIP = DefaultInternalLBIPAddress
284+
} else {
285+
privateIP = lb.PrivateIP
286+
}
281287
if lb.Name == "" {
282288
lb.Name = generateInternalLBName(c.ObjectMeta.Name)
283289
}
@@ -286,7 +292,7 @@ func (c *AzureCluster) setAPIServerLBDefaults() {
286292
{
287293
Name: generateFrontendIPConfigName(lb.Name),
288294
FrontendIPClass: FrontendIPClass{
289-
PrivateIPAddress: DefaultInternalLBIPAddress,
295+
PrivateIPAddress: privateIP,
290296
},
291297
},
292298
}

api/v1beta1/azurecluster_validation.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,12 @@ func validateAPIServerLB(lb *LoadBalancerSpec, old *LoadBalancerSpec, cidrs []st
439439
fldPath.Child("frontendIPConfigs").Index(0).Child("privateIP")); err != nil {
440440
allErrs = append(allErrs, err)
441441
}
442-
if lb.IPAllocationMethod == "Static" && len(old.FrontendIPs) != 0 && old.FrontendIPs[0].PrivateIPAddress == "" && old.FrontendIPs[0].PrivateIPAddress != lb.FrontendIPs[0].PrivateIPAddress {
443-
allErrs = append(allErrs, field.Forbidden(fldPath.Child("name"), "API Server load balancer private IP should not be modified after AzureCluster creation."))
442+
if lb.IPAllocationMethod == "Static" {
443+
if old != nil {
444+
if len(old.FrontendIPs) != 0 && old.FrontendIPs[0].PrivateIPAddress == "" && old.FrontendIPs[0].PrivateIPAddress != lb.FrontendIPs[0].PrivateIPAddress {
445+
allErrs = append(allErrs, field.Forbidden(fldPath.Child("name"), "API Server load balancer private IP should not be modified after AzureCluster creation."))
446+
}
447+
}
444448
}
445449
}
446450
}

api/v1beta1/types_class.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ type LoadBalancerClassSpec struct {
510510
Type LBType `json:"type,omitempty"`
511511
// +optional
512512
IPAllocationMethod string `json:"ipAllocationMethod,omitempty"`
513+
// +optional
514+
PrivateIP string `json:"privateIP,omitempty"`
513515
// IdleTimeoutInMinutes specifies the timeout for the TCP idle connection.
514516
// +optional
515517
IdleTimeoutInMinutes *int32 `json:"idleTimeoutInMinutes,omitempty"`

azure/scope/cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ func (s *ClusterScope) LBSpecs() []azure.ResourceSpecGetter {
266266
Role: infrav1.APIServerRole,
267267
BackendPoolName: s.APIServerLB().BackendPool.Name,
268268
IPAllocationMethod: s.APIServerLB().IPAllocationMethod,
269+
PrivateIP: s.APIServerLB().PrivateIP,
269270
IdleTimeoutInMinutes: s.APIServerLB().IdleTimeoutInMinutes,
270271
AdditionalTags: s.AdditionalTags(),
271272
}

azure/services/loadbalancers/spec.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type LBSpec struct {
4040
Type infrav1.LBType
4141
SKU infrav1.SKU
4242
IPAllocationMethod string
43+
PrivateIP string
4344
VNetName string
4445
VNetResourceGroup string
4546
SubnetName string
@@ -169,13 +170,17 @@ func getFrontendIPConfigs(lbSpec LBSpec) ([]*armnetwork.FrontendIPConfiguration,
169170
frontendIDs := make([]*armnetwork.SubResource, 0)
170171
for _, ipConfig := range lbSpec.FrontendIPConfigs {
171172
var properties armnetwork.FrontendIPConfigurationPropertiesFormat
173+
var privateIPAddress string
174+
if lbSpec.IPAllocationMethod == "Static" {
175+
privateIPAddress = ipConfig.PrivateIPAddress
176+
}
172177
if lbSpec.Type == infrav1.Internal {
173178
properties = armnetwork.FrontendIPConfigurationPropertiesFormat{
174179
PrivateIPAllocationMethod: ptr.To(armnetwork.IPAllocationMethodStatic),
175180
Subnet: &armnetwork.Subnet{
176181
ID: ptr.To(azure.SubnetID(lbSpec.SubscriptionID, lbSpec.VNetResourceGroup, lbSpec.VNetName, lbSpec.SubnetName)),
177182
},
178-
PrivateIPAddress: ptr.To(ipConfig.PrivateIPAddress),
183+
PrivateIPAddress: ptr.To(privateIPAddress),
179184
}
180185
} else {
181186
properties = armnetwork.FrontendIPConfigurationPropertiesFormat{

0 commit comments

Comments
 (0)