Skip to content

Commit

Permalink
Adding ability to override allocatable resources via ASG tags. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Niels-Ole Kühl committed Feb 8, 2019
1 parent 52e2cf4 commit e628858
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 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,17 @@ 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 := extractResourceAllocatableFromAsg(template.Tags)
if val, ok := resourcesFromTags["cpu"]; ok {
node.Status.Capacity[apiv1.ResourceCPU] = val
}
if val, ok := resourcesFromTags["memory"]; ok {
node.Status.Capacity[apiv1.ResourceMemory] = val
}
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 +304,28 @@ func extractLabelsFromAsg(tags []*autoscaling.TagDescription) map[string]string
return result
}

func extractResourceAllocatableFromAsg(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

0 comments on commit e628858

Please sign in to comment.