Skip to content

Commit

Permalink
Merge pull request #4800 from m-craghead/VMSS-Tag-Prefix-Fix-CherryPi…
Browse files Browse the repository at this point in the history
…ck-release-1.22

fix autoscaling due to VMSS tag prefix issue - Cherry Pick into release 1.22
  • Loading branch information
k8s-ci-robot authored Apr 11, 2022
2 parents 0d1f854 + 59205e8 commit 3326b12
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
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

0 comments on commit 3326b12

Please sign in to comment.