Skip to content

Commit

Permalink
fix autoscaling due to VMSS tag prefix issue
Browse files Browse the repository at this point in the history
corrected the azure_kubernetes_ercice_pool_test unit test cases involving the changed tag prefix

added const aksManagedPoolName attribute to the top of the code and fixed file name sercice -> service

added logic for old clusters that still have poolName

added legacy tag for poolName

Fixed Autoscaling due to VMSS tag prefix issue, added tags for legacy poolName and aksManagedPoolName, and corrected file name sercice->service
  • Loading branch information
m-craghead committed Feb 17, 2022
1 parent 6dc6dbf commit d2216e0
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 d2216e0

Please sign in to comment.