Skip to content

Commit c095a06

Browse files
authored
Display requested instead of free in cortex cluster info (#1285)
1 parent 3669d7a commit c095a06

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

cli/cmd/cluster.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ func printInfoNodes(infoResponse *schema.InfoResponse) {
583583
var doesClusterHaveGPUs bool
584584
for _, nodeInfo := range infoResponse.NodeInfos {
585585
totalReplicas += nodeInfo.NumReplicas
586-
if nodeInfo.ComputeCapacity.GPU > 0 {
586+
if nodeInfo.ComputeUserCapacity.GPU > 0 {
587587
doesClusterHaveGPUs = true
588588
}
589589
}
@@ -603,9 +603,9 @@ func printInfoNodes(infoResponse *schema.InfoResponse) {
603603
{Title: "instance type"},
604604
{Title: "lifecycle"},
605605
{Title: "replicas"},
606-
{Title: "CPU (free / total)"},
607-
{Title: "memory (free / total)"},
608-
{Title: "GPU (free / total)", Hidden: !doesClusterHaveGPUs},
606+
{Title: "CPU (requested / total allocatable)"},
607+
{Title: "memory (requested / total allocatable)"},
608+
{Title: "GPU (requested / total allocatable)", Hidden: !doesClusterHaveGPUs},
609609
}
610610

611611
var rows [][]interface{}
@@ -614,9 +614,10 @@ func printInfoNodes(infoResponse *schema.InfoResponse) {
614614
if nodeInfo.IsSpot {
615615
lifecycle = "spot"
616616
}
617-
cpuStr := nodeInfo.ComputeAvailable.CPU.String() + " / " + nodeInfo.ComputeCapacity.CPU.String()
618-
memStr := nodeInfo.ComputeAvailable.Mem.String() + " / " + nodeInfo.ComputeCapacity.Mem.String()
619-
gpuStr := s.Int64(nodeInfo.ComputeAvailable.GPU) + " / " + s.Int64(nodeInfo.ComputeCapacity.GPU)
617+
618+
cpuStr := nodeInfo.ComputeUserRequested.CPU.MilliString() + " / " + nodeInfo.ComputeUserCapacity.CPU.MilliString()
619+
memStr := nodeInfo.ComputeUserRequested.Mem.String() + " / " + nodeInfo.ComputeUserCapacity.Mem.String()
620+
gpuStr := s.Int64(nodeInfo.ComputeUserRequested.GPU) + " / " + s.Int64(nodeInfo.ComputeUserCapacity.GPU)
620621
rows = append(rows, []interface{}{nodeInfo.InstanceType, lifecycle, nodeInfo.NumReplicas, cpuStr, memStr, gpuStr})
621622
}
622623

pkg/lib/k8s/quantity.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ func NewMilliQuantity(milliValue int64) *Quantity {
9595
}
9696
}
9797

98+
func (quantity *Quantity) MilliString() string {
99+
return s.Int64(quantity.Quantity.MilliValue()) + "m"
100+
}
101+
98102
func (quantity *Quantity) ToFloat32() float32 {
99103
return float32(quantity.Quantity.MilliValue()) / float32(1000)
100104
}

pkg/operator/endpoints/info.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ func getNodeInfos() ([]schema.NodeInfo, int, error) {
8181
}
8282

8383
nodeInfoMap[node.Name] = &schema.NodeInfo{
84-
Name: node.Name,
85-
InstanceType: instanceType,
86-
IsSpot: isSpot,
87-
Price: price,
88-
NumReplicas: 0, // will be added to below
89-
ComputeCapacity: nodeComputeAllocatable(&node), // will be subtracted from below
90-
ComputeAvailable: nodeComputeAllocatable(&node), // will be subtracted from below
84+
Name: node.Name,
85+
InstanceType: instanceType,
86+
IsSpot: isSpot,
87+
Price: price,
88+
NumReplicas: 0, // will be added to below
89+
ComputeUserCapacity: nodeComputeAllocatable(&node), // will be subtracted from below
90+
ComputeAvailable: nodeComputeAllocatable(&node), // will be subtracted from below
91+
ComputeUserRequested: userconfig.ZeroCompute(), // will be added to below
9192
}
9293
}
9394

@@ -116,10 +117,14 @@ func getNodeInfos() ([]schema.NodeInfo, int, error) {
116117
node.ComputeAvailable.Mem.SubQty(mem)
117118
node.ComputeAvailable.GPU -= gpu
118119

119-
if !isAPIPod {
120-
node.ComputeCapacity.CPU.SubQty(cpu)
121-
node.ComputeCapacity.Mem.SubQty(mem)
122-
node.ComputeCapacity.GPU -= gpu
120+
if isAPIPod {
121+
node.ComputeUserRequested.CPU.AddQty(cpu)
122+
node.ComputeUserRequested.Mem.AddQty(mem)
123+
node.ComputeUserRequested.GPU += gpu
124+
} else {
125+
node.ComputeUserCapacity.CPU.SubQty(cpu)
126+
node.ComputeUserCapacity.Mem.SubQty(mem)
127+
node.ComputeUserCapacity.GPU -= gpu
123128
}
124129
}
125130

pkg/operator/schema/schema.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ type InfoResponse struct {
3232
}
3333

3434
type NodeInfo struct {
35-
Name string `json:"name"`
36-
InstanceType string `json:"instance_type"`
37-
IsSpot bool `json:"is_spot"`
38-
Price float64 `json:"price"`
39-
NumReplicas int `json:"num_replicas"`
40-
ComputeCapacity userconfig.Compute `json:"compute_capacity"` // the total resources available to the user on a node
41-
ComputeAvailable userconfig.Compute `json:"compute_available"` // unused resources on a node
35+
Name string `json:"name"`
36+
InstanceType string `json:"instance_type"`
37+
IsSpot bool `json:"is_spot"`
38+
Price float64 `json:"price"`
39+
NumReplicas int `json:"num_replicas"`
40+
ComputeUserCapacity userconfig.Compute `json:"compute_user_capacity"` // the total resources available to the user on a node
41+
ComputeAvailable userconfig.Compute `json:"compute_available"` // unused resources on a node
42+
ComputeUserRequested userconfig.Compute `json:"compute_user_requested"` // total resources requested by user on a node
4243
}
4344

4445
type DeployResponse struct {

pkg/types/userconfig/api.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,3 +506,11 @@ func (updateStrategy *UpdateStrategy) UserStr() string {
506506
sb.WriteString(fmt.Sprintf("%s: %s\n", MaxUnavailableKey, updateStrategy.MaxUnavailable))
507507
return sb.String()
508508
}
509+
510+
func ZeroCompute() Compute {
511+
return Compute{
512+
CPU: &k8s.Quantity{},
513+
Mem: &k8s.Quantity{},
514+
GPU: 0,
515+
}
516+
}

0 commit comments

Comments
 (0)