Skip to content

Commit

Permalink
fix: Change the order of updating vmss vm and vmss (#7540)
Browse files Browse the repository at this point in the history
Co-authored-by: Qi Ni <[email protected]>
  • Loading branch information
k8s-infra-cherrypick-robot and nilo19 authored Nov 12, 2024
1 parent c2a23f3 commit d75fc30
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions pkg/provider/azure_vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,13 @@ func (ss *ScaleSet) ensureHostsInPool(ctx context.Context, service *v1.Service,
mc.ObserveOperationWithResult(isOperationSucceeded)
}()

// Ensure the backendPoolID is also added on VMSS itself.
// Refer to issue kubernetes/kubernetes#80365 for detailed information
err := ss.ensureVMSSInPool(ctx, service, nodes, backendPoolID, vmSetNameOfLB)
if err != nil {
return err
}

hostUpdates := make([]func() error, 0, len(nodes))
nodeUpdates := make(map[vmssMetaInfo]map[string]compute.VirtualMachineScaleSetVM)
errors := make([]error, 0)
Expand Down Expand Up @@ -1469,13 +1476,6 @@ func (ss *ScaleSet) ensureHostsInPool(ctx context.Context, service *v1.Service,
return utilerrors.Flatten(utilerrors.NewAggregate(errors))
}

// Ensure the backendPoolID is also added on VMSS itself.
// Refer to issue kubernetes/kubernetes#80365 for detailed information
err := ss.ensureVMSSInPool(ctx, service, nodes, backendPoolID, vmSetNameOfLB)
if err != nil {
return err
}

isOperationSucceeded = true
return nil
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/provider/azure_vmssflex.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,13 @@ func (fs *FlexScaleSet) EnsureHostsInPool(ctx context.Context, service *v1.Servi
defer func() {
mc.ObserveOperationWithResult(isOperationSucceeded)
}()
hostUpdates := make([]func() error, 0, len(nodes))

err := fs.ensureVMSSFlexInPool(ctx, service, nodes, backendPoolID, vmSetNameOfLB)
if err != nil {
return err
}

hostUpdates := make([]func() error, 0, len(nodes))
for _, node := range nodes {
localNodeName := node.Name
if fs.useStandardLoadBalancer() && fs.excludeMasterNodesFromStandardLB() && isControlPlaneNode(node) {
Expand Down Expand Up @@ -746,11 +751,6 @@ func (fs *FlexScaleSet) EnsureHostsInPool(ctx context.Context, service *v1.Servi
return utilerrors.Flatten(errs)
}

err := fs.ensureVMSSFlexInPool(ctx, service, nodes, backendPoolID, vmSetNameOfLB)
if err != nil {
return err
}

isOperationSucceeded = true
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/azure_vmssflex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ func TestEnsureHostsInPoolVmssFlex(t *testing.T) {
vmListErr: nil,
nic: testNic1,
nicGetErr: nil,
expectedErr: fmt.Errorf("ensure(/): backendPoolID(/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/lb-internal/backendAddressPools/backendpool-1) - failed to ensure host in pool: EnsureHostInPool: VMSS Flex does not support Basic Load Balancer"),
expectedErr: fmt.Errorf("ensureVMSSFlexInPool: VMSS Flex does not support Basic Load Balancer"),
},
{
description: "EnsureHostsInPool should return error if vmss update fails",
Expand Down

0 comments on commit d75fc30

Please sign in to comment.