Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to override allocatable resources via ASG tags. #1656

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cluster-autoscaler/cloudprovider/aws/aws_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
26 changes: 26 additions & 0 deletions cluster-autoscaler/cloudprovider/aws/aws_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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{
{
Expand Down