Skip to content

Commit

Permalink
Merge pull request #1656 from flix-tech/asg-tags-resource-override
Browse files Browse the repository at this point in the history
Adding ability to override allocatable resources via ASG tags.
  • Loading branch information
k8s-ci-robot authored Feb 11, 2019
2 parents 4b1466a + f79a432 commit d2debce
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
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

0 comments on commit d2debce

Please sign in to comment.