Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions cli/cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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{}
Expand All @@ -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})
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/lib/k8s/quantity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
27 changes: 16 additions & 11 deletions pkg/operator/endpoints/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
}

Expand Down
15 changes: 8 additions & 7 deletions pkg/operator/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions pkg/types/userconfig/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}