diff --git a/cluster-autoscaler/cloudprovider/aws/aws_manager.go b/cluster-autoscaler/cloudprovider/aws/aws_manager.go index cb758874d58f..07e7be1361b9 100644 --- a/cluster-autoscaler/cloudprovider/aws/aws_manager.go +++ b/cluster-autoscaler/cloudprovider/aws/aws_manager.go @@ -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 @@ -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)