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: remove single vm from the cache instead of removing all vms of a… #3507

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/provider/azure_vmss_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,18 @@ func (ss *ScaleSet) DeleteCacheForNode(nodeName string) error {
return err
}

err = timedcache.Delete(cacheKey)
entry, exists, err := timedcache.Store.GetByKey(cacheKey)
if err != nil {
klog.Errorf("DeleteCacheForNode(%s) failed with error: %v", nodeName, err)
return err
}
if exists {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see master branch does not have such issue, so this is a specific fix on 1.23?

virtualMachines.Delete(nodeName)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs cherry-pick to 1.23-1.25.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.23-1.25

cached := entry.(*azcache.AzureCacheEntry).Data
if cached != nil {
virtualMachines := cached.(*sync.Map)
virtualMachines.Delete(nodeName)
entry.(*azcache.AzureCacheEntry).Data = virtualMachines
}
}

if err := ss.gcVMSSVMCache(); err != nil {
klog.Errorf("DeleteCacheForNode(%s) failed to gc stale vmss caches: %v", nodeName, err)
Expand Down
15 changes: 15 additions & 0 deletions pkg/provider/azure_vmss_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"net/http"
"strings"
"sync"
"testing"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-03-01/compute"
Expand Down Expand Up @@ -121,6 +122,20 @@ func TestVMSSVMCache(t *testing.T) {
err = ss.DeleteCacheForNode(vmName)
assert.NoError(t, err)

// ensure only one vm is removed from the cache
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks adding a test for this scenario!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you add this test into master branch @nilo19 I think master branch does not have this issue, but still needs a ut, thanks.

cacheKey, timedcache, _ := ss.getVMSSVMCache("rg", "vmss")
entry, _, _ := timedcache.Store.GetByKey(cacheKey)
cached := entry.(*azcache.AzureCacheEntry).Data
virtualMachines := cached.(*sync.Map)
length := 0
virtualMachines.Range(func(key, value interface{}) bool {
length++
assert.NotEqual(t, vmName, key)
fmt.Println(key)
return true
})
assert.Equal(t, 2, length)

// the VM should be back after another cache refresh.
ssName, instanceID, realVM, err := ss.getVmssVM(vmName, azcache.CacheReadTypeDefault)
assert.NoError(t, err)
Expand Down