Skip to content

Commit

Permalink
Merge pull request #1254 from nilo19/fix/delete-lb
Browse files Browse the repository at this point in the history
fix: skip reconcileSharedLoadBalancer if the service is being deleted
  • Loading branch information
k8s-ci-robot authored Mar 16, 2022
2 parents f61169b + fac209a commit 6d49847
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/provider/azure_backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ func (az *Cloud) ListManagedLBs(service *v1.Service, nodes []*v1.Node, clusterNa

// return early if wantLb=false
if nodes == nil {
klog.V(4).Infof("ListManagedLBs: return all LBs in the resource group %s, including unmanaged LBs", az.getLoadBalancerResourceGroup())
return allLBs, nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/provider/azure_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,18 @@ func (az *Cloud) reconcileSharedLoadBalancer(service *v1.Service, clusterName st
return existingLBs, nil
}

// Skip if nodes is nil, which means the service is being deleted.
// When nodes is nil, all LBs included unmanaged LBs will be returned,
// if we don't skip this function, the unmanaged ones may be deleted later.
if nodes == nil {
klog.V(4).Infof("reconcileSharedLoadBalancer: returning early because the service %s is being deleted", service.Name)
return existingLBs, nil
}

lbNamesToBeDeleted := sets.NewString()
// delete unwanted LBs
for _, lb := range existingLBs {
klog.V(4).Infof("reconcileSharedLoadBalancer: checking LB %s", to.String(lb.Name))
// skip the internal or external primary load balancer
lbNamePrefix := strings.TrimSuffix(to.String(lb.Name), consts.InternalLoadBalancerNameSuffix)
if strings.EqualFold(lbNamePrefix, clusterName) {
Expand Down
10 changes: 9 additions & 1 deletion pkg/provider/azure_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4753,9 +4753,17 @@ func TestReconcileSharedLoadBalancer(t *testing.T) {
useBasicLB: true,
expectedListCount: 1,
},
{
description: "reconcileSharedLoadBalancer should do nothing if `nodes` is nil",
expectedListCount: 1,
},
{
description: "reconcileSharedLoadBalancer should do nothing if the vmSet is not sharing the primary slb",
useMultipleSLBs: true,
nodes: []*v1.Node{
{ObjectMeta: metav1.ObjectMeta{Name: "kubernetes"}},
{ObjectMeta: metav1.ObjectMeta{Name: "vmss1"}},
},
existingLBs: []network.LoadBalancer{
{
Name: to.StringPtr("kubernetes"),
Expand Down Expand Up @@ -4791,8 +4799,8 @@ func TestReconcileSharedLoadBalancer(t *testing.T) {

cloud.NodePoolsWithoutDedicatedSLB = tc.vmSetsSharingPrimarySLB

cloud.LoadBalancerSku = consts.VMTypeStandard
if tc.useMultipleSLBs {
cloud.LoadBalancerSku = consts.VMTypeStandard
cloud.EnableMultipleStandardLoadBalancers = true
} else if tc.useBasicLB {
cloud.LoadBalancerSku = consts.LoadBalancerSkuBasic
Expand Down

0 comments on commit 6d49847

Please sign in to comment.