Skip to content

Commit 73a52ca

Browse files
committed
Rfrain from adding Egress IP to public LB backend pool
This PR is to stop adding Egress IP to public load balancer backend pool regardless of presence of an OutBoundRule in any Azure cluster. This change comes with a consequence of no outbound connectivity except to the infrastructure subnet even if there is no OutBoundRule. However this is required to tackle following situation: - If an infra node is being used as an egressNode then health check for egress IP also succeeds when it is added to public load balancer and LB considers it as a legitimate ingress router backend. - Limits the number of egress IP which can be created on a cluster due to some Azure specific limitation. Signed-off-by: Arnab Ghosh <[email protected]>
1 parent 8384756 commit 73a52ca

File tree

1 file changed

+7
-102
lines changed

1 file changed

+7
-102
lines changed

pkg/cloudprovider/azure.go

Lines changed: 7 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ type Azure struct {
4848
vmClient *armcompute.VirtualMachinesClient
4949
virtualNetworkClient *armnetwork.VirtualNetworksClient
5050
networkClient *armnetwork.InterfacesClient
51-
backendAddressPoolClient *armnetwork.LoadBalancerBackendAddressPoolsClient
5251
nodeMapLock sync.Mutex
5352
nodeLockMap map[string]*sync.Mutex
5453
azureWorkloadIdentityEnabled bool
@@ -162,11 +161,6 @@ func (a *Azure) initCredentials() error {
162161
return fmt.Errorf("failed to initialize new VirtualNetworksClient: %w", err)
163162
}
164163

165-
a.backendAddressPoolClient, err = armnetwork.NewLoadBalancerBackendAddressPoolsClient(cfg.subscriptionID, cred, options)
166-
if err != nil {
167-
return fmt.Errorf("failed to initialize new LoadBalancerBackendAddressPoolsClient: %w", err)
168-
}
169-
170164
return nil
171165
}
172166

@@ -198,65 +192,14 @@ func (a *Azure) AssignPrivateIP(ip net.IP, node *corev1.Node) error {
198192
name := fmt.Sprintf("%s_%s", node.Name, ipc)
199193
untrue := false
200194

201-
// In some Azure setups (Azure private, public ARO, private ARO) outbound connectivity is achieved through
202-
// outbound rules tied to the backend address pool of the primary IP of the VM NIC. An Azure constraint
203-
// forbids the creation of a secondary IP tied to such address pool and would result in
204-
// OutboundRuleCannotBeUsedWithBackendAddressPoolThatIsReferencedBySecondaryIpConfigs.
205-
// Work around it by not specifying the backend address pool when an outbound rule is set, even though
206-
// that means preventing outbound connectivity to the egress IP, which will be able to reach the
207-
// infrastructure subnet nonetheless. In public Azure clusters, outbound connectivity is achieved through
208-
// UserDefinedRouting, which doesn't impose such constraints on secondary IPs.
209-
loadBalancerBackendAddressPoolsArgument := networkInterface.Properties.IPConfigurations[0].Properties.LoadBalancerBackendAddressPools
210-
var attachedOutboundRule *armnetwork.SubResource
211-
OuterLoop:
212-
for _, ipconfig := range networkInterface.Properties.IPConfigurations {
213-
if ipconfig.Properties.LoadBalancerBackendAddressPools != nil {
214-
for _, pool := range ipconfig.Properties.LoadBalancerBackendAddressPools {
215-
if pool.ID == nil {
216-
continue
217-
}
218-
// for some reason, the struct for the pool above is not entirely filled out:
219-
// BackendAddressPoolPropertiesFormat:(*network.BackendAddressPoolPropertiesFormat)(nil)
220-
// Do a separate get for this pool in order to check whether there are any outbound rules
221-
// attached to it
222-
realPool, err := a.getBackendAddressPool(ptr.Deref(pool.ID, ""))
223-
if err != nil {
224-
return fmt.Errorf("error looking up backend address pool %s with ID %s: %v", ptr.Deref(pool.Name, ""), ptr.Deref(pool.ID, ""), err)
225-
}
226-
if len(realPool.Properties.LoadBalancerBackendAddresses) > 0 {
227-
if realPool.Properties.OutboundRule != nil {
228-
loadBalancerBackendAddressPoolsArgument = nil
229-
attachedOutboundRule = realPool.Properties.OutboundRule
230-
break OuterLoop
231-
}
232-
if len(realPool.Properties.OutboundRules) > 0 {
233-
loadBalancerBackendAddressPoolsArgument = nil
234-
attachedOutboundRule = (realPool.Properties.OutboundRules)[0]
235-
break OuterLoop
236-
}
237-
}
238-
}
239-
}
240-
}
241-
if loadBalancerBackendAddressPoolsArgument == nil {
242-
outboundRuleStr := ""
243-
if attachedOutboundRule != nil && attachedOutboundRule.ID != nil {
244-
// https://issues.redhat.com/browse/OCPBUGS-33617 showed that there can be a rule without an ID...
245-
outboundRuleStr = fmt.Sprintf(": %s", ptr.Deref(attachedOutboundRule.ID, ""))
246-
}
247-
klog.Warningf("Egress IP %s will have no outbound connectivity except for the infrastructure subnet: "+
248-
"omitting backend address pool when adding secondary IP: it has an outbound rule already%s",
249-
ipc, outboundRuleStr)
250-
}
251195
newIPConfiguration := &armnetwork.InterfaceIPConfiguration{
252196
Name: &name,
253197
Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
254-
PrivateIPAddress: &ipc,
255-
PrivateIPAllocationMethod: ptr.To(armnetwork.IPAllocationMethodStatic),
256-
Subnet: networkInterface.Properties.IPConfigurations[0].Properties.Subnet,
257-
Primary: &untrue,
258-
LoadBalancerBackendAddressPools: loadBalancerBackendAddressPoolsArgument,
259-
ApplicationSecurityGroups: applicationSecurityGroups,
198+
PrivateIPAddress: &ipc,
199+
PrivateIPAllocationMethod: ptr.To(armnetwork.IPAllocationMethodStatic),
200+
Subnet: networkInterface.Properties.IPConfigurations[0].Properties.Subnet,
201+
Primary: &untrue,
202+
ApplicationSecurityGroups: applicationSecurityGroups,
260203
},
261204
}
262205
for _, ipCfg := range ipConfigurations {
@@ -272,6 +215,8 @@ OuterLoop:
272215
ipConfigurations = append(ipConfigurations, newIPConfiguration)
273216
networkInterface.Properties.IPConfigurations = ipConfigurations
274217
// Send the request
218+
klog.Warningf("Egress IP %s will have no outbound connectivity except for the infrastructure subnet: "+
219+
"omitting backend address pool when adding secondary IP", ipc)
275220
poller, err := a.createOrUpdate(networkInterface)
276221
if err != nil {
277222
return err
@@ -491,46 +436,6 @@ func (a *Azure) getNetworkInterfaces(instance *armcompute.VirtualMachine) ([]arm
491436
return networkInterfaces, nil
492437
}
493438

494-
func splitObjectID(azureResourceID string) (resourceGroupName, loadBalancerName, backendAddressPoolName string) {
495-
// example of an azureResourceID:
496-
// "/subscriptions/53b8f551-f0fc-4bea-8cba-6d1fefd54c8a/resourceGroups/huirwang-debug1-2qh9t-rg/providers/Microsoft.Network/loadBalancers/huirwang-debug1-2qh9t/backendAddressPools/huirwang-debug1-2qh9t"
497-
498-
// Split the Azure resource ID into parts using "/"
499-
parts := strings.Split(azureResourceID, "/")
500-
501-
// Iterate through the parts to find the relevant subIDs
502-
for i, part := range parts {
503-
switch part {
504-
case "resourceGroups":
505-
if i+1 < len(parts) {
506-
resourceGroupName = parts[i+1]
507-
}
508-
case "loadBalancers":
509-
if i+1 < len(parts) {
510-
loadBalancerName = parts[i+1]
511-
}
512-
case "backendAddressPools":
513-
if i+1 < len(parts) {
514-
backendAddressPoolName = parts[i+1]
515-
}
516-
}
517-
}
518-
return
519-
}
520-
521-
func (a *Azure) getBackendAddressPool(poolID string) (*armnetwork.BackendAddressPool, error) {
522-
ctx, cancel := context.WithTimeout(a.ctx, defaultAzureOperationTimeout)
523-
defer cancel()
524-
resourceGroupName, loadBalancerName, backendAddressPoolName := splitObjectID(poolID)
525-
response, err := a.backendAddressPoolClient.Get(ctx, resourceGroupName, loadBalancerName, backendAddressPoolName, nil)
526-
if err != nil {
527-
return nil, fmt.Errorf("failed to retrieve backend address pool for backendAddressPoolClient=%s, loadBalancerName=%s, backendAddressPoolName=%s: %w",
528-
resourceGroupName, loadBalancerName, backendAddressPoolName, err)
529-
}
530-
return &response.BackendAddressPool, nil
531-
532-
}
533-
534439
func (a *Azure) getNetworkInterface(id string) (armnetwork.Interface, error) {
535440
ctx, cancel := context.WithTimeout(a.ctx, defaultAzureOperationTimeout)
536441
defer cancel()

0 commit comments

Comments
 (0)