From d2216e020fcddb1325a921b1a421bdb30dab7bf4 Mon Sep 17 00:00:00 2001 From: mirandacraghead Date: Wed, 16 Feb 2022 18:37:06 -0500 Subject: [PATCH] fix autoscaling due to VMSS tag prefix issue 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 --- .../azure/azure_kubernetes_service_pool.go | 10 +++++++++- ...test.go => azure_kubernetes_service_pool_test.go} | 12 ++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) rename cluster-autoscaler/cloudprovider/azure/{azure_kubernetes_sercice_pool_test.go => azure_kubernetes_service_pool_test.go} (96%) diff --git a/cluster-autoscaler/cloudprovider/azure/azure_kubernetes_service_pool.go b/cluster-autoscaler/cloudprovider/azure/azure_kubernetes_service_pool.go index acd98cf55bc9..ea65f8f23a7e 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_kubernetes_service_pool.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_kubernetes_service_pool.go @@ -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 @@ -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) { diff --git a/cluster-autoscaler/cloudprovider/azure/azure_kubernetes_sercice_pool_test.go b/cluster-autoscaler/cloudprovider/azure/azure_kubernetes_service_pool_test.go similarity index 96% rename from cluster-autoscaler/cloudprovider/azure/azure_kubernetes_sercice_pool_test.go rename to cluster-autoscaler/cloudprovider/azure/azure_kubernetes_service_pool_test.go index cb8f8796b09e..85487b07cf4f 100644 --- a/cluster-autoscaler/cloudprovider/azure/azure_kubernetes_sercice_pool_test.go +++ b/cluster-autoscaler/cloudprovider/azure/azure_kubernetes_service_pool_test.go @@ -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) { @@ -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)}, }, } @@ -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)