Skip to content

Commit

Permalink
Merge pull request #4795 from marwanad/azure-scale-from-zero-cherry-p…
Browse files Browse the repository at this point in the history
…icks

Cherry-pick #4421, #4550 - Azure scale from zero improvements
  • Loading branch information
k8s-ci-robot authored Apr 7, 2022
2 parents dcb7c84 + d8df72e commit 0d1f854
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cluster-autoscaler/cloudprovider/azure/azure_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"strings"
)

const azureDiskTopologyKey string = "topology.disk.csi.azure.com/zone"

func buildInstanceOS(template compute.VirtualMachineScaleSet) string {
instanceOS := cloudprovider.DefaultOS
if template.VirtualMachineProfile != nil && template.VirtualMachineProfile.OsProfile != nil && template.VirtualMachineProfile.OsProfile.WindowsConfiguration != nil {
Expand All @@ -56,8 +58,10 @@ func buildGenericLabels(template compute.VirtualMachineScaleSet, nodeName string
}

result[apiv1.LabelTopologyZone] = strings.Join(failureDomains[:], cloudvolume.LabelMultiZoneDelimiter)
result[azureDiskTopologyKey] = strings.Join(failureDomains[:], cloudvolume.LabelMultiZoneDelimiter)
} else {
result[apiv1.LabelTopologyZone] = "0"
result[azureDiskTopologyKey] = ""
}

result[apiv1.LabelHostname] = nodeName
Expand Down
18 changes: 16 additions & 2 deletions cluster-autoscaler/processors/nodegroupset/azure_nodegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,24 @@ import (
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework"
)

// AzureNodepoolLabel is a label specifying which Azure node pool a particular node belongs to.
const AzureNodepoolLabel = "agentpool"
// AzureNodepoolLegacyLabel is a label specifying which Azure node pool a particular node belongs to.
const AzureNodepoolLegacyLabel = "agentpool"

// AzureNodepoolLabel is an AKS label specifying which nodepool a particular node belongs to
const AzureNodepoolLabel = "kubernetes.azure.com/agentpool"

// AzureDiskTopologyKey is the topology key of Azure Disk CSI driver
const AzureDiskTopologyKey = "topology.disk.csi.azure.com/zone"

func nodesFromSameAzureNodePool(n1, n2 *schedulerframework.NodeInfo) bool {
n1AzureNodePool := n1.Node().Labels[AzureNodepoolLabel]
n2AzureNodePool := n2.Node().Labels[AzureNodepoolLabel]
return (n1AzureNodePool != "" && n1AzureNodePool == n2AzureNodePool) || nodesFromSameAzureNodePoolLegacy(n1, n2)
}

func nodesFromSameAzureNodePoolLegacy(n1, n2 *schedulerframework.NodeInfo) bool {
n1AzureNodePool := n1.Node().Labels[AzureNodepoolLegacyLabel]
n2AzureNodePool := n2.Node().Labels[AzureNodepoolLegacyLabel]
return n1AzureNodePool != "" && n1AzureNodePool == n2AzureNodePool
}

Expand All @@ -37,7 +49,9 @@ func CreateAzureNodeInfoComparator(extraIgnoredLabels []string) NodeInfoComparat
for k, v := range BasicIgnoredLabels {
azureIgnoredLabels[k] = v
}
azureIgnoredLabels[AzureNodepoolLegacyLabel] = true
azureIgnoredLabels[AzureNodepoolLabel] = true
azureIgnoredLabels[AzureDiskTopologyKey] = true
for _, k := range extraIgnoredLabels {
azureIgnoredLabels[k] = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func TestIsAzureNodeInfoSimilar(t *testing.T) {
n1.ObjectMeta.Labels["agentpool"] = ""
n2.ObjectMeta.Labels["agentpool"] = ""
checkNodesSimilar(t, n1, n2, comparator, false)
// AKS agentpool labels
n1.ObjectMeta.Labels["kubernetes.azure.com/agentpool"] = "foo"
n2.ObjectMeta.Labels["kubernetes.azure.com/agentpool"] = "bar"
checkNodesSimilar(t, n1, n2, comparator, false)
// Only one non empty
n1.ObjectMeta.Labels["agentpool"] = ""
n2.ObjectMeta.Labels["agentpool"] = "foo"
Expand Down Expand Up @@ -109,6 +113,8 @@ func TestFindSimilarNodeGroupsAzureByLabel(t *testing.T) {
// Unless we give them nodepool label.
n1.ObjectMeta.Labels["agentpool"] = "foobar"
n2.ObjectMeta.Labels["agentpool"] = "foobar"
n1.ObjectMeta.Labels["kubernetes.azure.com/agentpool"] = "foobar"
n2.ObjectMeta.Labels["kubernetes.azure.com/agentpool"] = "foobar"
similar, err = processor.FindSimilarNodeGroups(context, ng1, nodeInfosForGroups)
assert.NoError(t, err)
assert.Equal(t, similar, []cloudprovider.NodeGroup{ng2})
Expand All @@ -125,6 +131,9 @@ func TestFindSimilarNodeGroupsAzureByLabel(t *testing.T) {
n1.ObjectMeta.Labels["agentpool"] = "foobar1"
n2.ObjectMeta.Labels["agentpool"] = "foobar2"
n3.ObjectMeta.Labels["agentpool"] = "foobar3"
n1.ObjectMeta.Labels["kubernetes.azure.com/agentpool"] = "foobar1"
n2.ObjectMeta.Labels["kubernetes.azure.com/agentpool"] = "foobar2"
n3.ObjectMeta.Labels["kubernetes.azure.com/agentpool"] = "foobar3"

similar, err = processor.FindSimilarNodeGroups(context, ng1, nodeInfosForGroups)
assert.NoError(t, err)
Expand Down

0 comments on commit 0d1f854

Please sign in to comment.