diff --git a/cli/cmd/cluster.go b/cli/cmd/cluster.go index 4d7f737d78..8763f5d4fb 100644 --- a/cli/cmd/cluster.go +++ b/cli/cmd/cluster.go @@ -583,7 +583,7 @@ func printInfoNodes(infoResponse *schema.InfoResponse) { var doesClusterHaveGPUs bool for _, nodeInfo := range infoResponse.NodeInfos { totalReplicas += nodeInfo.NumReplicas - if nodeInfo.ComputeCapacity.GPU > 0 { + if nodeInfo.ComputeUserCapacity.GPU > 0 { doesClusterHaveGPUs = true } } @@ -603,9 +603,9 @@ func printInfoNodes(infoResponse *schema.InfoResponse) { {Title: "instance type"}, {Title: "lifecycle"}, {Title: "replicas"}, - {Title: "CPU (free / total)"}, - {Title: "memory (free / total)"}, - {Title: "GPU (free / total)", Hidden: !doesClusterHaveGPUs}, + {Title: "CPU (requested / total allocatable)"}, + {Title: "memory (requested / total allocatable)"}, + {Title: "GPU (requested / total allocatable)", Hidden: !doesClusterHaveGPUs}, } var rows [][]interface{} @@ -614,9 +614,10 @@ func printInfoNodes(infoResponse *schema.InfoResponse) { if nodeInfo.IsSpot { lifecycle = "spot" } - cpuStr := nodeInfo.ComputeAvailable.CPU.String() + " / " + nodeInfo.ComputeCapacity.CPU.String() - memStr := nodeInfo.ComputeAvailable.Mem.String() + " / " + nodeInfo.ComputeCapacity.Mem.String() - gpuStr := s.Int64(nodeInfo.ComputeAvailable.GPU) + " / " + s.Int64(nodeInfo.ComputeCapacity.GPU) + + cpuStr := nodeInfo.ComputeUserRequested.CPU.MilliString() + " / " + nodeInfo.ComputeUserCapacity.CPU.MilliString() + memStr := nodeInfo.ComputeUserRequested.Mem.String() + " / " + nodeInfo.ComputeUserCapacity.Mem.String() + gpuStr := s.Int64(nodeInfo.ComputeUserRequested.GPU) + " / " + s.Int64(nodeInfo.ComputeUserCapacity.GPU) rows = append(rows, []interface{}{nodeInfo.InstanceType, lifecycle, nodeInfo.NumReplicas, cpuStr, memStr, gpuStr}) } diff --git a/pkg/lib/k8s/quantity.go b/pkg/lib/k8s/quantity.go index 5849235281..14b15cc22f 100644 --- a/pkg/lib/k8s/quantity.go +++ b/pkg/lib/k8s/quantity.go @@ -95,6 +95,10 @@ func NewMilliQuantity(milliValue int64) *Quantity { } } +func (quantity *Quantity) MilliString() string { + return s.Int64(quantity.Quantity.MilliValue()) + "m" +} + func (quantity *Quantity) ToFloat32() float32 { return float32(quantity.Quantity.MilliValue()) / float32(1000) } diff --git a/pkg/operator/endpoints/info.go b/pkg/operator/endpoints/info.go index f918c8c144..f84a49c132 100644 --- a/pkg/operator/endpoints/info.go +++ b/pkg/operator/endpoints/info.go @@ -81,13 +81,14 @@ func getNodeInfos() ([]schema.NodeInfo, int, error) { } nodeInfoMap[node.Name] = &schema.NodeInfo{ - Name: node.Name, - InstanceType: instanceType, - IsSpot: isSpot, - Price: price, - NumReplicas: 0, // will be added to below - ComputeCapacity: nodeComputeAllocatable(&node), // will be subtracted from below - ComputeAvailable: nodeComputeAllocatable(&node), // will be subtracted from below + Name: node.Name, + InstanceType: instanceType, + IsSpot: isSpot, + Price: price, + NumReplicas: 0, // will be added to below + ComputeUserCapacity: nodeComputeAllocatable(&node), // will be subtracted from below + ComputeAvailable: nodeComputeAllocatable(&node), // will be subtracted from below + ComputeUserRequested: userconfig.ZeroCompute(), // will be added to below } } @@ -116,10 +117,14 @@ func getNodeInfos() ([]schema.NodeInfo, int, error) { node.ComputeAvailable.Mem.SubQty(mem) node.ComputeAvailable.GPU -= gpu - if !isAPIPod { - node.ComputeCapacity.CPU.SubQty(cpu) - node.ComputeCapacity.Mem.SubQty(mem) - node.ComputeCapacity.GPU -= gpu + if isAPIPod { + node.ComputeUserRequested.CPU.AddQty(cpu) + node.ComputeUserRequested.Mem.AddQty(mem) + node.ComputeUserRequested.GPU += gpu + } else { + node.ComputeUserCapacity.CPU.SubQty(cpu) + node.ComputeUserCapacity.Mem.SubQty(mem) + node.ComputeUserCapacity.GPU -= gpu } } diff --git a/pkg/operator/schema/schema.go b/pkg/operator/schema/schema.go index eaf70696ad..5e6b0f686a 100644 --- a/pkg/operator/schema/schema.go +++ b/pkg/operator/schema/schema.go @@ -32,13 +32,14 @@ type InfoResponse struct { } type NodeInfo struct { - Name string `json:"name"` - InstanceType string `json:"instance_type"` - IsSpot bool `json:"is_spot"` - Price float64 `json:"price"` - NumReplicas int `json:"num_replicas"` - ComputeCapacity userconfig.Compute `json:"compute_capacity"` // the total resources available to the user on a node - ComputeAvailable userconfig.Compute `json:"compute_available"` // unused resources on a node + Name string `json:"name"` + InstanceType string `json:"instance_type"` + IsSpot bool `json:"is_spot"` + Price float64 `json:"price"` + NumReplicas int `json:"num_replicas"` + ComputeUserCapacity userconfig.Compute `json:"compute_user_capacity"` // the total resources available to the user on a node + ComputeAvailable userconfig.Compute `json:"compute_available"` // unused resources on a node + ComputeUserRequested userconfig.Compute `json:"compute_user_requested"` // total resources requested by user on a node } type DeployResponse struct { diff --git a/pkg/types/userconfig/api.go b/pkg/types/userconfig/api.go index 743182f030..7dc5db3fda 100644 --- a/pkg/types/userconfig/api.go +++ b/pkg/types/userconfig/api.go @@ -506,3 +506,11 @@ func (updateStrategy *UpdateStrategy) UserStr() string { sb.WriteString(fmt.Sprintf("%s: %s\n", MaxUnavailableKey, updateStrategy.MaxUnavailable)) return sb.String() } + +func ZeroCompute() Compute { + return Compute{ + CPU: &k8s.Quantity{}, + Mem: &k8s.Quantity{}, + GPU: 0, + } +}