in azure/azure_loadbalancer.go [954:1049]
func (az *Cloud) isFrontendIPConfigUnsafeToDelete(
lb *network.LoadBalancer,
service *v1.Service,
fipConfigID *string,
) (bool, error) {
if lb == nil || fipConfigID == nil || *fipConfigID == "" {
return false, fmt.Errorf("isFrontendIPConfigUnsafeToDelete: incorrect parameters")
}
var (
lbRules []network.LoadBalancingRule
outboundRules []network.OutboundRule
inboundNatRules []network.InboundNatRule
inboundNatPools []network.InboundNatPool
unsafe bool
)
if lb.LoadBalancerPropertiesFormat != nil {
if lb.LoadBalancingRules != nil {
lbRules = *lb.LoadBalancingRules
}
if lb.OutboundRules != nil {
outboundRules = *lb.OutboundRules
}
if lb.InboundNatRules != nil {
inboundNatRules = *lb.InboundNatRules
}
if lb.InboundNatPools != nil {
inboundNatPools = *lb.InboundNatPools
}
}
// check if there are load balancing rules from other services
// referencing this frontend IP configuration
for _, lbRule := range lbRules {
if lbRule.LoadBalancingRulePropertiesFormat != nil &&
lbRule.FrontendIPConfiguration != nil &&
lbRule.FrontendIPConfiguration.ID != nil &&
strings.EqualFold(*lbRule.FrontendIPConfiguration.ID, *fipConfigID) {
if !az.serviceOwnsRule(service, *lbRule.Name) {
warningMsg := fmt.Sprintf("isFrontendIPConfigUnsafeToDelete: frontend IP configuration with ID %s on LB %s cannot be deleted because it is being referenced by load balancing rules of other services", *fipConfigID, *lb.Name)
klog.Warning(warningMsg)
az.Event(service, v1.EventTypeWarning, "DeletingFrontendIPConfiguration", warningMsg)
unsafe = true
break
}
}
}
// check if there are outbound rules
// referencing this frontend IP configuration
for _, outboundRule := range outboundRules {
if outboundRule.OutboundRulePropertiesFormat != nil && outboundRule.FrontendIPConfigurations != nil {
outboundRuleFIPConfigs := *outboundRule.FrontendIPConfigurations
if found := findMatchedOutboundRuleFIPConfig(fipConfigID, outboundRuleFIPConfigs); found {
warningMsg := fmt.Sprintf("isFrontendIPConfigUnsafeToDelete: frontend IP configuration with ID %s on LB %s cannot be deleted because it is being referenced by the outbound rule %s", *fipConfigID, *lb.Name, *outboundRule.Name)
klog.Warning(warningMsg)
az.Event(service, v1.EventTypeWarning, "DeletingFrontendIPConfiguration", warningMsg)
unsafe = true
break
}
}
}
// check if there are inbound NAT rules
// referencing this frontend IP configuration
for _, inboundNatRule := range inboundNatRules {
if inboundNatRule.InboundNatRulePropertiesFormat != nil &&
inboundNatRule.FrontendIPConfiguration != nil &&
inboundNatRule.FrontendIPConfiguration.ID != nil &&
strings.EqualFold(*inboundNatRule.FrontendIPConfiguration.ID, *fipConfigID) {
warningMsg := fmt.Sprintf("isFrontendIPConfigUnsafeToDelete: frontend IP configuration with ID %s on LB %s cannot be deleted because it is being referenced by the inbound NAT rule %s", *fipConfigID, *lb.Name, *inboundNatRule.Name)
klog.Warning(warningMsg)
az.Event(service, v1.EventTypeWarning, "DeletingFrontendIPConfiguration", warningMsg)
unsafe = true
break
}
}
// check if there are inbound NAT pools
// referencing this frontend IP configuration
for _, inboundNatPool := range inboundNatPools {
if inboundNatPool.InboundNatPoolPropertiesFormat != nil &&
inboundNatPool.FrontendIPConfiguration != nil &&
inboundNatPool.FrontendIPConfiguration.ID != nil &&
strings.EqualFold(*inboundNatPool.FrontendIPConfiguration.ID, *fipConfigID) {
warningMsg := fmt.Sprintf("isFrontendIPConfigUnsafeToDelete: frontend IP configuration with ID %s on LB %s cannot be deleted because it is being referenced by the inbound NAT pool %s", *fipConfigID, *lb.Name, *inboundNatPool.Name)
klog.Warning(warningMsg)
az.Event(service, v1.EventTypeWarning, "DeletingFrontendIPConfiguration", warningMsg)
unsafe = true
break
}
}
return unsafe, nil
}