Skip to content

Commit

Permalink
Merge pull request #4056 from marwanad/support-separator-allocatables
Browse files Browse the repository at this point in the history
support "/"separators in custom allocatable overrides via vmss tags
  • Loading branch information
k8s-ci-robot authored May 5, 2021
2 parents 200415e + 3e53369 commit c6d4535
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cluster-autoscaler/cloudprovider/azure/azure_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,12 @@ func extractAllocatableResourcesFromScaleSet(tags map[string]*string) map[string
continue
}

normalizedResourceName := strings.Replace(resourceName[1], "_", "/", -1)
quantity, err := resource.ParseQuantity(*tagValue)
if err != nil {
continue
}
resources[resourceName[1]] = &quantity
resources[normalizedResourceName] = &quantity
}

return resources
Expand Down
9 changes: 6 additions & 3 deletions cluster-autoscaler/cloudprovider/azure/azure_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ func TestExtractTaintsFromScaleSet(t *testing.T) {

func TestExtractAllocatableResourcesFromScaleSet(t *testing.T) {
tags := map[string]*string{
fmt.Sprintf("%s%s", nodeResourcesTagName, "cpu"): to.StringPtr("100m"),
fmt.Sprintf("%s%s", nodeResourcesTagName, "memory"): to.StringPtr("100M"),
fmt.Sprintf("%s%s", nodeResourcesTagName, "ephemeral-storage"): to.StringPtr("20G"),
fmt.Sprintf("%s%s", nodeResourcesTagName, "cpu"): to.StringPtr("100m"),
fmt.Sprintf("%s%s", nodeResourcesTagName, "memory"): to.StringPtr("100M"),
fmt.Sprintf("%s%s", nodeResourcesTagName, "ephemeral-storage"): to.StringPtr("20G"),
fmt.Sprintf("%s%s", nodeResourcesTagName, "nvidia.com_Tesla-P100-PCIE"): to.StringPtr("4"),
}

labels := extractAllocatableResourcesFromScaleSet(tags)
Expand All @@ -102,6 +103,8 @@ func TestExtractAllocatableResourcesFromScaleSet(t *testing.T) {
assert.Equal(t, (&expectedMemory).String(), labels["memory"].String())
expectedEphemeralStorage := resource.MustParse("20G")
assert.Equal(t, (&expectedEphemeralStorage).String(), labels["ephemeral-storage"].String())
exepectedCustomAllocatable := resource.MustParse("4")
assert.Equal(t, (&exepectedCustomAllocatable).String(), labels["nvidia.com/Tesla-P100-PCIE"].String())
}

func makeTaintSet(taints []apiv1.Taint) map[apiv1.Taint]bool {
Expand Down

0 comments on commit c6d4535

Please sign in to comment.