diff --git a/cluster-autoscaler/cloudprovider/aws/aws_manager.go b/cluster-autoscaler/cloudprovider/aws/aws_manager.go index b651ca05f165..13f51bb6e6a6 100644 --- a/cluster-autoscaler/cloudprovider/aws/aws_manager.go +++ b/cluster-autoscaler/cloudprovider/aws/aws_manager.go @@ -412,6 +412,28 @@ func extractLabelsFromAsg(tags []*autoscaling.TagDescription) map[string]string return result } +func extractAllocatableResourcesFromAsg(tags []*autoscaling.TagDescription) map[string]*resource.Quantity { + result := make(map[string]*resource.Quantity) + + for _, tag := range tags { + k := *tag.Key + v := *tag.Value + splits := strings.Split(k, "k8s.io/cluster-autoscaler/node-template/resources/") + if len(splits) > 1 { + label := splits[1] + if label != "" { + quantity, err := resource.ParseQuantity(v) + if err != nil { + continue + } + result[label] = &quantity + } + } + } + + return result +} + func extractTaintsFromAsg(tags []*autoscaling.TagDescription) []apiv1.Taint { taints := make([]apiv1.Taint, 0) diff --git a/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go b/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go index 8512e875f82a..cf90ff19efb9 100644 --- a/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go +++ b/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go @@ -48,6 +48,31 @@ func TestBuildGenericLabels(t *testing.T) { assert.Equal(t, cloudprovider.DefaultOS, labels[kubeletapis.LabelOS]) } +func TestExtractAllocatableResourcesFromAsg(t *testing.T) { + tags := []*autoscaling.TagDescription{ + { + Key: aws.String("k8s.io/cluster-autoscaler/node-template/resources/cpu"), + Value: aws.String("100m"), + }, + { + Key: aws.String("k8s.io/cluster-autoscaler/node-template/resources/memory"), + Value: aws.String("100M"), + }, + { + Key: aws.String("k8s.io/cluster-autoscaler/node-template/resources/ephemeral-storage"), + Value: aws.String("20G"), + }, + } + + labels := extractAllocatableResourcesFromAsg(tags) + + assert.Equal(t, resource.NewMilliQuantity(100, resource.DecimalSI).String(), labels["cpu"].String()) + expectedMemory := resource.MustParse("100M") + assert.Equal(t, (&expectedMemory).String(), labels["memory"].String()) + expectedEphemeralStorage := resource.MustParse("20G") + assert.Equal(t, (&expectedEphemeralStorage).String(), labels["ephemeral-storage"].String()) +} + func TestExtractLabelsFromAsg(t *testing.T) { tags := []*autoscaling.TagDescription{ {