Skip to content

Commit

Permalink
use fargate profile as namespace and fix instance type composition
Browse files Browse the repository at this point in the history
  • Loading branch information
alexei-led committed May 14, 2023
1 parent 221cfc9 commit c6794ec
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/usage/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package usage

import (
"fmt"
"math"
"strings"
"time"

Expand Down Expand Up @@ -94,7 +95,11 @@ func NodeInfoFromNode(cluster string, node *v1.Node) NodeInfo {
// get nodegroup from node label, fargate nodegroup is empty
nodegroup := node.GetLabels()["eks.amazonaws.com/nodegroup"]
if nodegroup == "" {
nodegroup = "fargate"
// assume fargate and get fargate profile name from node label
nodegroup = node.GetLabels()["eks.amazonaws.com/fargate-profile"]
if nodegroup == "" {
nodegroup = "fargate"
}
}

// get region from node label
Expand All @@ -109,7 +114,10 @@ func NodeInfoFromNode(cluster string, node *v1.Node) NodeInfo {
instanceType = node.GetLabels()["node.kubernetes.io/instance-type"]
// if empty, assume fargate and build instance type based on pattern "fargate-vCPU-memoryGB" where memory is rounded to GiB
if instanceType == "" {
instanceType = fmt.Sprintf("fargate-%dvCPU-%dGB", node.Status.Capacity.Cpu().Value(), node.Status.Capacity.Memory().ScaledValue(resource.Giga))
// get memory in rounded GB
memory := float64(node.Status.Capacity.Memory().Value())
memoryGB := math.Round(memory / 1024 / 1024 / 1024)
instanceType = fmt.Sprintf("fargate-%dvCPU-%dGB", node.Status.Capacity.Cpu().Value(), memoryGB)
}
}

Expand Down

0 comments on commit c6794ec

Please sign in to comment.