Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add Etag field to request body to let Etag work #8106

Merged
merged 2 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/provider/azure_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6229,7 +6229,7 @@ func TestCleanOrphanedLoadBalancerLBInUseByVMSS(t *testing.T) {

expectedVMSS := buildTestVMSSWithLB(testVMSSName, "vmss-vm-", []string{testLBBackendpoolID0}, false)
mockVMSSClient := cloud.ComputeClientFactory.GetVirtualMachineScaleSetClient().(*mock_virtualmachinescalesetclient.MockInterface)
mockVMSSClient.EXPECT().List(gomock.Any(), "rg").Return([]*armcompute.VirtualMachineScaleSet{expectedVMSS}, nil)
mockVMSSClient.EXPECT().List(gomock.Any(), "rg").Return([]*armcompute.VirtualMachineScaleSet{expectedVMSS}, nil).MaxTimes(2)
feiskyer marked this conversation as resolved.
Show resolved Hide resolved
mockVMSSClient.EXPECT().Get(gomock.Any(), "rg", testVMSSName, gomock.Any()).Return(expectedVMSS, nil)
mockVMSSClient.EXPECT().CreateOrUpdate(gomock.Any(), "rg", testVMSSName, gomock.Any()).Return(nil, nil)

Expand Down
15 changes: 15 additions & 0 deletions pkg/provider/azure_vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,7 @@ func (ss *ScaleSet) EnsureHostInPool(ctx context.Context, _ *v1.Service, nodeNam
NetworkInterfaceConfigurations: networkInterfaceConfigurations,
},
},
Etag: vm.Etag,
}

// Get the node resource group.
Expand Down Expand Up @@ -1322,8 +1323,17 @@ func (ss *ScaleSet) ensureVMSSInPool(ctx context.Context, _ *v1.Service, nodes [
},
},
},
Etag: vmss.Etag,
}

// NOTE(mainred): invalidate vmss cache for the vmss is updated.
// we invalidate the vmss cache anyway, because
// - when the vmss is updated, the vmss cache invalid
// - when the vmss update failed, we want to get fresh-new vmss in the next round of update, especially for EtagMismatch error
defer func() {
feiskyer marked this conversation as resolved.
Show resolved Hide resolved
_ = ss.vmssCache.Delete(consts.VMSSKey)
}()

klog.V(2).Infof("ensureVMSSInPool begins to update vmss(%s) with new backendPoolID %s", vmssName, backendPoolID)
rerr := ss.CreateOrUpdateVMSS(ss.ResourceGroup, vmssName, newVMSS)
if rerr != nil {
Expand Down Expand Up @@ -2221,8 +2231,13 @@ func (ss *ScaleSet) EnsureBackendPoolDeletedFromVMSets(ctx context.Context, vmss
},
},
},
Etag: vmss.Etag,
}

defer func() {
_ = ss.vmssCache.Delete(consts.VMSSKey)
}()

klog.V(2).Infof("EnsureBackendPoolDeletedFromVMSets begins to update vmss(%s) with backendPoolIDs %q", vmssName, backendPoolIDs)
rerr := ss.CreateOrUpdateVMSS(ss.ResourceGroup, vmssName, newVMSS)
if rerr != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/provider/azure_vmss_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func (az *Cloud) CreateOrUpdateVMSS(resourceGroupName string, VMScaleSetName str
}

_, err = az.ComputeClientFactory.GetVirtualMachineScaleSetClient().CreateOrUpdate(ctx, resourceGroupName, VMScaleSetName, parameters)
klog.V(10).Infof("UpdateVmssVMWithRetry: ComputeClientFactory.GetVirtualMachineScaleSetClient().CreateOrUpdate(%s): end", VMScaleSetName)
if err != nil {
klog.Errorf("CreateOrUpdateVMSS: error CreateOrUpdate vmss(%s): %v", VMScaleSetName, err)
return err
Expand Down
2 changes: 2 additions & 0 deletions pkg/provider/virtualmachine/virtualmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type VirtualMachine struct {
Type string
Plan *armcompute.Plan
Resources []*armcompute.VirtualMachineExtension
Etag *string

// fields of VirtualMachine
Identity *armcompute.VirtualMachineIdentity
Expand Down Expand Up @@ -114,6 +115,7 @@ func FromVirtualMachineScaleSetVM(vm *armcompute.VirtualMachineScaleSetVM, opt M
Zones: vm.Zones,
Plan: vm.Plan,
Resources: vm.Resources,
Etag: vm.Etag,

SKU: vm.SKU,
InstanceID: ptr.Deref(vm.InstanceID, ""),
Expand Down
Loading