diff --git a/cluster-autoscaler/cloudprovider/aws/aws_manager.go b/cluster-autoscaler/cloudprovider/aws/aws_manager.go index cb758874d58f..bf2625116560 100644 --- a/cluster-autoscaler/cloudprovider/aws/aws_manager.go +++ b/cluster-autoscaler/cloudprovider/aws/aws_manager.go @@ -247,6 +247,11 @@ func (m *AwsManager) buildNodeFromTemplate(asg *asg, template *asgTemplate) (*ap node.Status.Capacity[gpu.ResourceNvidiaGPU] = *resource.NewQuantity(template.InstanceType.GPU, resource.DecimalSI) node.Status.Capacity[apiv1.ResourceMemory] = *resource.NewQuantity(template.InstanceType.MemoryMb*1024*1024, resource.DecimalSI) + resourcesFromTags := extractAllocatableResourcesFromAsg(template.Tags) + if val, ok := resourcesFromTags["ephemeral-storage"]; ok { + node.Status.Capacity[apiv1.ResourceEphemeralStorage] = *val + } + // TODO: use proper allocatable!! node.Status.Allocatable = node.Status.Capacity @@ -293,6 +298,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 e1f0ca488f4a..16cddd089378 100644 --- a/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go +++ b/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go @@ -33,6 +33,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" apiv1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/autoscaler/cluster-autoscaler/cloudprovider" kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis" ) @@ -82,6 +83,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{ {