From 5641b6c6a9e6eb5cf3b1d28499513caf2164f930 Mon Sep 17 00:00:00 2001 From: vishal Date: Fri, 21 Aug 2020 12:55:58 -0400 Subject: [PATCH 01/11] Update virtual_service.go --- pkg/lib/k8s/virtual_service.go | 35 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/pkg/lib/k8s/virtual_service.go b/pkg/lib/k8s/virtual_service.go index 8bc6a4e43d..ba548468aa 100644 --- a/pkg/lib/k8s/virtual_service.go +++ b/pkg/lib/k8s/virtual_service.go @@ -63,7 +63,7 @@ func VirtualService(spec *VirtualServiceSpec) *istioclientnetworking.VirtualServ }) } - httpRoutes := []*istionetworking.HTTPRoute{} + var httpRoutes []*istionetworking.HTTPRoute if spec.ExactPath != nil { httpRoutes = append(httpRoutes, &istionetworking.HTTPRoute{ @@ -77,12 +77,15 @@ func VirtualService(spec *VirtualServiceSpec) *istioclientnetworking.VirtualServ }, }, Route: destinations, - Rewrite: &istionetworking.HTTPRewrite{ - Uri: urls.CanonicalizeEndpoint(*spec.Rewrite), - }, }) + + if spec.Rewrite != nil { + httpRoutes[0].Rewrite = &istionetworking.HTTPRewrite{ + Uri: urls.CanonicalizeEndpoint(*spec.Rewrite), + } + } } else { - httpRoutes = append(httpRoutes, &istionetworking.HTTPRoute{ + exactMatch := &istionetworking.HTTPRoute{ Match: []*istionetworking.HTTPMatchRequest{ { Uri: &istionetworking.StringMatch{ @@ -93,10 +96,9 @@ func VirtualService(spec *VirtualServiceSpec) *istioclientnetworking.VirtualServ }, }, Route: destinations, - Rewrite: &istionetworking.HTTPRewrite{ - Uri: urls.CanonicalizeEndpoint(*spec.Rewrite), - }, - }, &istionetworking.HTTPRoute{ + } + + prefixMatch := &istionetworking.HTTPRoute{ Match: []*istionetworking.HTTPMatchRequest{ { Uri: &istionetworking.StringMatch{ @@ -107,10 +109,19 @@ func VirtualService(spec *VirtualServiceSpec) *istioclientnetworking.VirtualServ }, }, Route: destinations, - Rewrite: &istionetworking.HTTPRewrite{ + } + + if spec.Rewrite != nil { + exactMatch.Rewrite = &istionetworking.HTTPRewrite{ + Uri: urls.CanonicalizeEndpoint(*spec.Rewrite), + } + + prefixMatch.Rewrite = &istionetworking.HTTPRewrite{ Uri: urls.CanonicalizeEndpoint(*spec.Rewrite) + "/", - }, - }) + } + } + + httpRoutes = append(httpRoutes, exactMatch, prefixMatch) } virtualService := &istioclientnetworking.VirtualService{ From d8036a785d3a70e436bda0502ab087ee6821e3ed Mon Sep 17 00:00:00 2001 From: vishal Date: Fri, 21 Aug 2020 12:57:16 -0400 Subject: [PATCH 02/11] Rename traffic-splitter to iris-classifier --- examples/traffic-splitter/README.md | 36 +++++++++++++-------------- examples/traffic-splitter/cortex.yaml | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/traffic-splitter/README.md b/examples/traffic-splitter/README.md index 22f05dbc43..13d10ca618 100644 --- a/examples/traffic-splitter/README.md +++ b/examples/traffic-splitter/README.md @@ -17,7 +17,7 @@ $ cortex deploy --env aws creating iris-classifier-onnx (RealtimeAPI) creating iris-classifier-tf (RealtimeAPI) -created traffic-splitter (TrafficSplitter) +created iris-classifier (TrafficSplitter) ``` ## `cortex get` @@ -30,52 +30,52 @@ aws iris-classifier-onnx updating 0 1 27s - aws iris-classifier-tf updating 0 1 27s - - env traffic splitter apis last update -aws traffic-splitter iris-classifier-onnx:30 iris-classifier-tf:70 27s +aws iris-classifier iris-classifier-onnx:30 iris-classifier-tf:70 27s ``` -## `cortex get traffic-splitter` +## `cortex get iris-classifier` ```bash -$ cortex get traffic-splitter --env aws +$ cortex get iris-classifier --env aws apis weights status requested last update avg request 2XX 5XX iris-classifier-onnx 30 live 1 1m - - - iris-classifier-tf 70 live 1 1m - - - last updated: 1m -endpoint: https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -curl: curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json +endpoint: https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier +curl: curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json ... ``` ## Make multiple requests ```bash -$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json +$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json setosa -$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json +$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json setosa -$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json +$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json setosa -$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json +$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json setosa -$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json +$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json setosa -$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json +$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json setosa ``` -## `cortex get traffic-splitter` +## `cortex get iris-classifier` Notice the requests being routed to the different Realtime APIs based on their weights (the output below may not match yours): ```bash -$ cortex get traffic-splitter --env aws +$ cortex get iris-classifier --env aws using aws environment @@ -85,8 +85,8 @@ iris-classifier-onnx 30 live 1 4m 6.00791 ms iris-classifier-tf 70 live 1 4m 5.81867 ms 5 - last updated: 4m -endpoint: https://comtf6hs64.execute-api.us-west-2.amazonaws.com/traffic-splitter -curl: curl https://comtf6hs64.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json +endpoint: https://comtf6hs64.execute-api.us-west-2.amazonaws.com/iris-classifier +curl: curl https://comtf6hs64.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json ... ``` @@ -95,9 +95,9 @@ curl: curl https://comtf6hs64.execute-api.us-west-2.amazonaws.com/traffic-splitt Use `cortex delete ` to delete the Traffic Splitter and the two Realtime APIs (note that the Traffic Splitter and each Realtime API must be deleted by separate `cortex delete` commands): ```bash -$ cortex delete traffic-splitter --env aws +$ cortex delete iris-classifier --env aws -deleting traffic-splitter +deleting iris-classifier $ cortex delete iris-classifier-onnx --env aws diff --git a/examples/traffic-splitter/cortex.yaml b/examples/traffic-splitter/cortex.yaml index b489627f5b..1fc69e0216 100644 --- a/examples/traffic-splitter/cortex.yaml +++ b/examples/traffic-splitter/cortex.yaml @@ -18,7 +18,7 @@ monitoring: model_type: classification -- name: traffic-splitter +- name: iris-classifier kind: TrafficSplitter apis: - name: iris-classifier-onnx From 111a10be007ea31eb35e6c9fdfc9d4e9d9246ddb Mon Sep 17 00:00:00 2001 From: vishal Date: Fri, 21 Aug 2020 12:58:57 -0400 Subject: [PATCH 03/11] Update cluster.go --- cli/cmd/cluster.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cli/cmd/cluster.go b/cli/cmd/cluster.go index 4d7f737d78..46f9e8797d 100644 --- a/cli/cmd/cluster.go +++ b/cli/cmd/cluster.go @@ -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)"}, + {Title: "memory (requested / total)"}, + {Title: "GPU (requested / total)", Hidden: !doesClusterHaveGPUs}, } var rows [][]interface{} @@ -614,9 +614,14 @@ 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) + requestedCPU := nodeInfo.ComputeCapacity.CPU.DeepCopy() + requestedCPU.Sub(nodeInfo.ComputeAvailable.CPU.Quantity) + cpuStr := requestedCPU.String() + " / " + nodeInfo.ComputeCapacity.CPU.String() + + requestedMem := nodeInfo.ComputeCapacity.Mem.DeepCopy() + requestedMem.Sub(nodeInfo.ComputeAvailable.Mem.Quantity) + memStr := requestedMem.String() + " / " + nodeInfo.ComputeCapacity.Mem.String() + gpuStr := s.Int64(nodeInfo.ComputeCapacity.GPU-nodeInfo.ComputeAvailable.GPU) + " / " + s.Int64(nodeInfo.ComputeCapacity.GPU) rows = append(rows, []interface{}{nodeInfo.InstanceType, lifecycle, nodeInfo.NumReplicas, cpuStr, memStr, gpuStr}) } From 2df41d55e2d714b6013059347f65121259871fd8 Mon Sep 17 00:00:00 2001 From: vishal Date: Fri, 21 Aug 2020 13:55:06 -0400 Subject: [PATCH 04/11] Update development.md --- docs/contributing/development.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/contributing/development.md b/docs/contributing/development.md index 4279bee328..0d576822d0 100644 --- a/docs/contributing/development.md +++ b/docs/contributing/development.md @@ -207,7 +207,7 @@ make cluster-down ### Deploy an example ```bash -cortex deploy examples/pytorch/iris-classifier --env aws +cortex deploy examples/pytorch/iris-classifier/cortex.yaml --env aws ``` ## Off-cluster operator From 8fc2b5064b6e8ff2a3587211d711209489383d89 Mon Sep 17 00:00:00 2001 From: vishal Date: Fri, 21 Aug 2020 20:39:23 +0000 Subject: [PATCH 05/11] Revert "Rename traffic-splitter to iris-classifier" This reverts commit d8036a785d3a70e436bda0502ab087ee6821e3ed. --- examples/traffic-splitter/README.md | 36 +++++++++++++-------------- examples/traffic-splitter/cortex.yaml | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/traffic-splitter/README.md b/examples/traffic-splitter/README.md index 13d10ca618..22f05dbc43 100644 --- a/examples/traffic-splitter/README.md +++ b/examples/traffic-splitter/README.md @@ -17,7 +17,7 @@ $ cortex deploy --env aws creating iris-classifier-onnx (RealtimeAPI) creating iris-classifier-tf (RealtimeAPI) -created iris-classifier (TrafficSplitter) +created traffic-splitter (TrafficSplitter) ``` ## `cortex get` @@ -30,52 +30,52 @@ aws iris-classifier-onnx updating 0 1 27s - aws iris-classifier-tf updating 0 1 27s - - env traffic splitter apis last update -aws iris-classifier iris-classifier-onnx:30 iris-classifier-tf:70 27s +aws traffic-splitter iris-classifier-onnx:30 iris-classifier-tf:70 27s ``` -## `cortex get iris-classifier` +## `cortex get traffic-splitter` ```bash -$ cortex get iris-classifier --env aws +$ cortex get traffic-splitter --env aws apis weights status requested last update avg request 2XX 5XX iris-classifier-onnx 30 live 1 1m - - - iris-classifier-tf 70 live 1 1m - - - last updated: 1m -endpoint: https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -curl: curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json +endpoint: https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter +curl: curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json ... ``` ## Make multiple requests ```bash -$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json +$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json setosa -$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json +$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json setosa -$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json +$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json setosa -$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json +$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json setosa -$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json +$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json setosa -$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json +$ curl https://abcedefg.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json setosa ``` -## `cortex get iris-classifier` +## `cortex get traffic-splitter` Notice the requests being routed to the different Realtime APIs based on their weights (the output below may not match yours): ```bash -$ cortex get iris-classifier --env aws +$ cortex get traffic-splitter --env aws using aws environment @@ -85,8 +85,8 @@ iris-classifier-onnx 30 live 1 4m 6.00791 ms iris-classifier-tf 70 live 1 4m 5.81867 ms 5 - last updated: 4m -endpoint: https://comtf6hs64.execute-api.us-west-2.amazonaws.com/iris-classifier -curl: curl https://comtf6hs64.execute-api.us-west-2.amazonaws.com/iris-classifier -X POST -H "Content-Type: application/json" -d @sample.json +endpoint: https://comtf6hs64.execute-api.us-west-2.amazonaws.com/traffic-splitter +curl: curl https://comtf6hs64.execute-api.us-west-2.amazonaws.com/traffic-splitter -X POST -H "Content-Type: application/json" -d @sample.json ... ``` @@ -95,9 +95,9 @@ curl: curl https://comtf6hs64.execute-api.us-west-2.amazonaws.com/iris-classifie Use `cortex delete ` to delete the Traffic Splitter and the two Realtime APIs (note that the Traffic Splitter and each Realtime API must be deleted by separate `cortex delete` commands): ```bash -$ cortex delete iris-classifier --env aws +$ cortex delete traffic-splitter --env aws -deleting iris-classifier +deleting traffic-splitter $ cortex delete iris-classifier-onnx --env aws diff --git a/examples/traffic-splitter/cortex.yaml b/examples/traffic-splitter/cortex.yaml index 1fc69e0216..b489627f5b 100644 --- a/examples/traffic-splitter/cortex.yaml +++ b/examples/traffic-splitter/cortex.yaml @@ -18,7 +18,7 @@ monitoring: model_type: classification -- name: iris-classifier +- name: traffic-splitter kind: TrafficSplitter apis: - name: iris-classifier-onnx From 00922695b2e54931bf5791f85b3a921a8d0ad026 Mon Sep 17 00:00:00 2001 From: vishal Date: Fri, 21 Aug 2020 20:40:24 +0000 Subject: [PATCH 06/11] Revert "Update development.md" This reverts commit 2df41d55e2d714b6013059347f65121259871fd8. --- docs/contributing/development.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/contributing/development.md b/docs/contributing/development.md index 0d576822d0..4279bee328 100644 --- a/docs/contributing/development.md +++ b/docs/contributing/development.md @@ -207,7 +207,7 @@ make cluster-down ### Deploy an example ```bash -cortex deploy examples/pytorch/iris-classifier/cortex.yaml --env aws +cortex deploy examples/pytorch/iris-classifier --env aws ``` ## Off-cluster operator From 5d3549e64dca335aff4b7d4e7ec7f333734edc26 Mon Sep 17 00:00:00 2001 From: vishal Date: Fri, 21 Aug 2020 16:42:03 -0400 Subject: [PATCH 07/11] Calculate requested resources in cluster --- cli/cmd/cluster.go | 18 +++++++----------- pkg/lib/k8s/quantity.go | 8 ++++++++ pkg/operator/endpoints/info.go | 29 +++++++++++++++++++---------- pkg/operator/schema/schema.go | 15 ++++++++------- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/cli/cmd/cluster.go b/cli/cmd/cluster.go index 46f9e8797d..aa1da727c9 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 (requested / total)"}, - {Title: "memory (requested / total)"}, - {Title: "GPU (requested / total)", Hidden: !doesClusterHaveGPUs}, + {Title: "CPU (requested / total allocatable)"}, + {Title: "memory (requested / total allocatable)"}, + {Title: "GPU (requested / total allocatable)", Hidden: !doesClusterHaveGPUs}, } var rows [][]interface{} @@ -614,14 +614,10 @@ func printInfoNodes(infoResponse *schema.InfoResponse) { if nodeInfo.IsSpot { lifecycle = "spot" } - requestedCPU := nodeInfo.ComputeCapacity.CPU.DeepCopy() - requestedCPU.Sub(nodeInfo.ComputeAvailable.CPU.Quantity) - cpuStr := requestedCPU.String() + " / " + nodeInfo.ComputeCapacity.CPU.String() - requestedMem := nodeInfo.ComputeCapacity.Mem.DeepCopy() - requestedMem.Sub(nodeInfo.ComputeAvailable.Mem.Quantity) - memStr := requestedMem.String() + " / " + nodeInfo.ComputeCapacity.Mem.String() - gpuStr := s.Int64(nodeInfo.ComputeCapacity.GPU-nodeInfo.ComputeAvailable.GPU) + " / " + s.Int64(nodeInfo.ComputeCapacity.GPU) + cpuStr := nodeInfo.ComputeUserRequested.CPU.MilliString() + " / " + nodeInfo.ComputeUserCapacity.CPU.MilliString() + memStr := nodeInfo.ComputeUserRequested.Mem.Base2String() + " / " + nodeInfo.ComputeUserCapacity.Mem.Base2String() + gpuStr := s.Int64(nodeInfo.ComputeUserRequested.GPU-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..9c785bb31c 100644 --- a/pkg/lib/k8s/quantity.go +++ b/pkg/lib/k8s/quantity.go @@ -95,6 +95,14 @@ func NewMilliQuantity(milliValue int64) *Quantity { } } +func (quantity *Quantity) MilliString() string { + return s.Int64(quantity.Quantity.MilliValue()) + "m" +} + +func (quantity *Quantity) Base2String() string { + return s.Int64ToBase2Byte(quantity.Quantity.Value()) +} + 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..a64099d246 100644 --- a/pkg/operator/endpoints/info.go +++ b/pkg/operator/endpoints/info.go @@ -81,13 +81,18 @@ 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.Compute{ // will be added to below + CPU: &k8s.Quantity{}, + Mem: &k8s.Quantity{}, + GPU: 0, + }, } } @@ -117,9 +122,13 @@ func getNodeInfos() ([]schema.NodeInfo, int, error) { node.ComputeAvailable.GPU -= gpu if !isAPIPod { - node.ComputeCapacity.CPU.SubQty(cpu) - node.ComputeCapacity.Mem.SubQty(mem) - node.ComputeCapacity.GPU -= gpu + node.ComputeUserCapacity.CPU.SubQty(cpu) + node.ComputeUserCapacity.Mem.SubQty(mem) + node.ComputeUserCapacity.GPU -= gpu + } else { + node.ComputeUserRequested.CPU.AddQty(cpu) + node.ComputeUserRequested.Mem.AddQty(mem) + node.ComputeUserRequested.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 { From 2d761b07755747b6808a20f3ca8a6fd03602b8e2 Mon Sep 17 00:00:00 2001 From: vishal Date: Fri, 21 Aug 2020 16:45:33 -0400 Subject: [PATCH 08/11] Update cluster.go --- cli/cmd/cluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/cmd/cluster.go b/cli/cmd/cluster.go index aa1da727c9..97f0cbf6ad 100644 --- a/cli/cmd/cluster.go +++ b/cli/cmd/cluster.go @@ -617,7 +617,7 @@ func printInfoNodes(infoResponse *schema.InfoResponse) { cpuStr := nodeInfo.ComputeUserRequested.CPU.MilliString() + " / " + nodeInfo.ComputeUserCapacity.CPU.MilliString() memStr := nodeInfo.ComputeUserRequested.Mem.Base2String() + " / " + nodeInfo.ComputeUserCapacity.Mem.Base2String() - gpuStr := s.Int64(nodeInfo.ComputeUserRequested.GPU-nodeInfo.ComputeUserRequested.GPU) + " / " + s.Int64(nodeInfo.ComputeUserCapacity.GPU) + gpuStr := s.Int64(nodeInfo.ComputeUserRequested.GPU) + " / " + s.Int64(nodeInfo.ComputeUserCapacity.GPU) rows = append(rows, []interface{}{nodeInfo.InstanceType, lifecycle, nodeInfo.NumReplicas, cpuStr, memStr, gpuStr}) } From c41b6cab9e6686e89893cddae72e74bd4d999f04 Mon Sep 17 00:00:00 2001 From: David Eliahu Date: Fri, 21 Aug 2020 13:52:22 -0700 Subject: [PATCH 09/11] Add ZeroCompute() --- pkg/operator/endpoints/info.go | 20 ++++++++------------ pkg/types/userconfig/api.go | 8 ++++++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pkg/operator/endpoints/info.go b/pkg/operator/endpoints/info.go index a64099d246..9dd8c4b3f9 100644 --- a/pkg/operator/endpoints/info.go +++ b/pkg/operator/endpoints/info.go @@ -81,18 +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 - ComputeUserCapacity: nodeComputeAllocatable(&node), // will be subtracted from below - ComputeAvailable: nodeComputeAllocatable(&node), // will be subtracted from below - ComputeUserRequested: userconfig.Compute{ // will be added to below - CPU: &k8s.Quantity{}, - Mem: &k8s.Quantity{}, - GPU: 0, - }, + 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 } } 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, + } +} From 322871d413909930b098af779291ae8589a49432 Mon Sep 17 00:00:00 2001 From: David Eliahu Date: Fri, 21 Aug 2020 14:13:38 -0700 Subject: [PATCH 10/11] Update info.go --- pkg/operator/endpoints/info.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/operator/endpoints/info.go b/pkg/operator/endpoints/info.go index 9dd8c4b3f9..f84a49c132 100644 --- a/pkg/operator/endpoints/info.go +++ b/pkg/operator/endpoints/info.go @@ -117,14 +117,14 @@ func getNodeInfos() ([]schema.NodeInfo, int, error) { node.ComputeAvailable.Mem.SubQty(mem) node.ComputeAvailable.GPU -= gpu - if !isAPIPod { - node.ComputeUserCapacity.CPU.SubQty(cpu) - node.ComputeUserCapacity.Mem.SubQty(mem) - node.ComputeUserCapacity.GPU -= gpu - } else { + 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 } } From efb705c84ea0a54d24ca2da688de9b4c09df5c62 Mon Sep 17 00:00:00 2001 From: vishal Date: Fri, 21 Aug 2020 17:14:25 -0400 Subject: [PATCH 11/11] Use k8s string instead of base2 string --- cli/cmd/cluster.go | 2 +- pkg/lib/k8s/quantity.go | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/cli/cmd/cluster.go b/cli/cmd/cluster.go index 97f0cbf6ad..8763f5d4fb 100644 --- a/cli/cmd/cluster.go +++ b/cli/cmd/cluster.go @@ -616,7 +616,7 @@ func printInfoNodes(infoResponse *schema.InfoResponse) { } cpuStr := nodeInfo.ComputeUserRequested.CPU.MilliString() + " / " + nodeInfo.ComputeUserCapacity.CPU.MilliString() - memStr := nodeInfo.ComputeUserRequested.Mem.Base2String() + " / " + nodeInfo.ComputeUserCapacity.Mem.Base2String() + 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 9c785bb31c..14b15cc22f 100644 --- a/pkg/lib/k8s/quantity.go +++ b/pkg/lib/k8s/quantity.go @@ -99,10 +99,6 @@ func (quantity *Quantity) MilliString() string { return s.Int64(quantity.Quantity.MilliValue()) + "m" } -func (quantity *Quantity) Base2String() string { - return s.Int64ToBase2Byte(quantity.Quantity.Value()) -} - func (quantity *Quantity) ToFloat32() float32 { return float32(quantity.Quantity.MilliValue()) / float32(1000) }