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 autoscaling due to VMSS tag prefix issue - Cherry Pick into release 1.22 #4800

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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ import (
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework"
)

const (
aksManagedPoolNameTag = "aks-managed-poolName"
legacyAKSPoolNameTag = "poolName"
)

//AKSAgentPool implements NodeGroup interface for agent pool deployed in AKS
type AKSAgentPool struct {
azureRef
Expand Down Expand Up @@ -315,7 +320,10 @@ func (agentPool *AKSAgentPool) DeleteNodes(nodes []*apiv1.Node) error {

//IsAKSNode checks if the tag from the vm matches the agentPool name
func (agentPool *AKSAgentPool) IsAKSNode(tags map[string]*string) bool {
poolName := tags["poolName"]
poolName := tags[aksManagedPoolNameTag]
if poolName == nil {
poolName = tags[legacyAKSPoolNameTag]
}
if poolName != nil {
klog.V(5).Infof("Matching agentPool name: %s with tag name: %s", agentPool.azureRef.Name, *poolName)
if strings.EqualFold(*poolName, agentPool.azureRef.Name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,17 @@ func TestAKSIncreaseSize(t *testing.T) {

func TestIsAKSNode(t *testing.T) {
aksPool := getTestAKSPool(newTestAzureManager(t), testAKSPoolName)
tags := map[string]*string{"poolName": to.StringPtr(testAKSPoolName)}
tags := map[string]*string{aksManagedPoolNameTag: to.StringPtr(testAKSPoolName)}
isAKSNode := aksPool.IsAKSNode(tags)
assert.True(t, isAKSNode)

tags = map[string]*string{"poolName": to.StringPtr("fake")}
tags = map[string]*string{aksManagedPoolNameTag: to.StringPtr("fake")}
isAKSNode = aksPool.IsAKSNode(tags)
assert.False(t, isAKSNode)

tags = map[string]*string{legacyAKSPoolNameTag: to.StringPtr(testAKSPoolName)}
isAKSNode = aksPool.IsAKSNode(tags)
assert.True(t, isAKSNode)
}

func TestDeleteNodesAKS(t *testing.T) {
Expand Down Expand Up @@ -346,7 +350,7 @@ func TestAKSNodes(t *testing.T) {
{
Name: to.StringPtr("name"),
ID: to.StringPtr("/subscriptions/sub/resourceGroups/rg/providers/provider/vm1"),
Tags: map[string]*string{"poolName": to.StringPtr(testAKSPoolName)},
Tags: map[string]*string{aksManagedPoolNameTag: to.StringPtr(testAKSPoolName)},
},
}

Expand Down Expand Up @@ -394,7 +398,7 @@ func TestAKSDecreaseTargetSize(t *testing.T) {
{
Name: to.StringPtr("name"),
ID: to.StringPtr("/subscriptions/sub/resourceGroups/rg/providers/provider/vm1"),
Tags: map[string]*string{"poolName": to.StringPtr(testAKSPoolName)},
Tags: map[string]*string{aksManagedPoolNameTag: to.StringPtr(testAKSPoolName)},
},
}
mockVMClient := mockvmclient.NewMockInterface(ctrl)
Expand Down