This commit is contained in:
+56
-48
@@ -75,7 +75,7 @@ func envCreate(c *cli.Context) error {
|
|||||||
envVersion = 1
|
envVersion = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceReq := getResourceReq(c)
|
resourceReq := getResourceReq(c, v1.ResourceRequirements{})
|
||||||
|
|
||||||
env := &crd.Environment{
|
env := &crd.Environment{
|
||||||
Metadata: metav1.ObjectMeta{
|
Metadata: metav1.ObjectMeta{
|
||||||
@@ -230,54 +230,62 @@ func envList(c *cli.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getResourceReq(c *cli.Context) v1.ResourceRequirements {
|
func getResourceReq(c *cli.Context, resources v1.ResourceRequirements) v1.ResourceRequirements {
|
||||||
if c.IsSet("mincpu") || c.IsSet("maxcpu") || c.IsSet("minmemory") || c.IsSet("maxmemory") {
|
|
||||||
mincpu := c.Int("mincpu")
|
|
||||||
maxcpu := c.Int("maxcpu")
|
|
||||||
minmem := c.Int("minmemory")
|
|
||||||
maxmem := c.Int("maxmemory")
|
|
||||||
|
|
||||||
requestResources := make(map[v1.ResourceName]resource.Quantity)
|
var requestResources map[v1.ResourceName]resource.Quantity
|
||||||
|
|
||||||
if mincpu != 0 {
|
if len(resources.Requests) == 0 {
|
||||||
cpuRequest, err := resource.ParseQuantity(strconv.Itoa(mincpu) + "m")
|
requestResources = make(map[v1.ResourceName]resource.Quantity)
|
||||||
if err != nil {
|
} else {
|
||||||
fatal("Failed to parse mincpu")
|
requestResources = resources.Requests
|
||||||
}
|
|
||||||
requestResources[v1.ResourceCPU] = cpuRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
if minmem != 0 {
|
|
||||||
memRequest, err := resource.ParseQuantity(strconv.Itoa(minmem) + "Mi")
|
|
||||||
if err != nil {
|
|
||||||
fatal("Failed to parse minmemory")
|
|
||||||
}
|
|
||||||
requestResources[v1.ResourceMemory] = memRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
limitResources := make(map[v1.ResourceName]resource.Quantity)
|
|
||||||
|
|
||||||
if maxcpu != 0 {
|
|
||||||
cpuLimit, err := resource.ParseQuantity(strconv.Itoa(maxcpu) + "m")
|
|
||||||
if err != nil {
|
|
||||||
fatal("Failed to parse maxcpu")
|
|
||||||
}
|
|
||||||
limitResources[v1.ResourceCPU] = cpuLimit
|
|
||||||
}
|
|
||||||
|
|
||||||
if maxmem != 0 {
|
|
||||||
memLimit, err := resource.ParseQuantity(strconv.Itoa(maxmem) + "Mi")
|
|
||||||
if err != nil {
|
|
||||||
fatal("Failed to parse maxmemory")
|
|
||||||
}
|
|
||||||
limitResources[v1.ResourceMemory] = memLimit
|
|
||||||
}
|
|
||||||
|
|
||||||
resources := v1.ResourceRequirements{
|
|
||||||
Requests: requestResources,
|
|
||||||
Limits: limitResources,
|
|
||||||
}
|
|
||||||
return resources
|
|
||||||
}
|
}
|
||||||
return v1.ResourceRequirements{}
|
|
||||||
|
if c.IsSet("mincpu") {
|
||||||
|
mincpu := c.Int("mincpu")
|
||||||
|
cpuRequest, err := resource.ParseQuantity(strconv.Itoa(mincpu) + "m")
|
||||||
|
if err != nil {
|
||||||
|
fatal("Failed to parse mincpu")
|
||||||
|
}
|
||||||
|
requestResources[v1.ResourceCPU] = cpuRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.IsSet("minmemory") {
|
||||||
|
minmem := c.Int("minmemory")
|
||||||
|
memRequest, err := resource.ParseQuantity(strconv.Itoa(minmem) + "Mi")
|
||||||
|
if err != nil {
|
||||||
|
fatal("Failed to parse minmemory")
|
||||||
|
}
|
||||||
|
requestResources[v1.ResourceMemory] = memRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
var limitResources map[v1.ResourceName]resource.Quantity
|
||||||
|
if len(resources.Limits) == 0 {
|
||||||
|
limitResources = make(map[v1.ResourceName]resource.Quantity)
|
||||||
|
} else {
|
||||||
|
limitResources = resources.Limits
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.IsSet("maxcpu") {
|
||||||
|
maxcpu := c.Int("maxcpu")
|
||||||
|
cpuLimit, err := resource.ParseQuantity(strconv.Itoa(maxcpu) + "m")
|
||||||
|
if err != nil {
|
||||||
|
fatal("Failed to parse maxcpu")
|
||||||
|
}
|
||||||
|
limitResources[v1.ResourceCPU] = cpuLimit
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.IsSet("maxmemory") {
|
||||||
|
maxmem := c.Int("maxmemory")
|
||||||
|
memLimit, err := resource.ParseQuantity(strconv.Itoa(maxmem) + "Mi")
|
||||||
|
if err != nil {
|
||||||
|
fatal("Failed to parse maxmemory")
|
||||||
|
}
|
||||||
|
limitResources[v1.ResourceMemory] = memLimit
|
||||||
|
}
|
||||||
|
|
||||||
|
resources = v1.ResourceRequirements{
|
||||||
|
Requests: requestResources,
|
||||||
|
Limits: limitResources,
|
||||||
|
}
|
||||||
|
return resources
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-6
@@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/satori/go.uuid"
|
"github.com/satori/go.uuid"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
apiv1 "k8s.io/client-go/pkg/api/v1"
|
||||||
|
|
||||||
"github.com/fission/fission"
|
"github.com/fission/fission"
|
||||||
"github.com/fission/fission/crd"
|
"github.com/fission/fission/crd"
|
||||||
@@ -196,7 +197,7 @@ func fnCreate(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
invokeStrategy := getInvokeStrategy(c.Int("minscale"), c.Int("maxscale"), c.String("executortype"), getTargetCPU(c))
|
invokeStrategy := getInvokeStrategy(c.Int("minscale"), c.Int("maxscale"), c.String("executortype"), getTargetCPU(c))
|
||||||
resourceReq := getResourceReq(c)
|
resourceReq := getResourceReq(c, apiv1.ResourceRequirements{})
|
||||||
if (c.IsSet("mincpu") || c.IsSet("maxcpu") || c.IsSet("minmemory") || c.IsSet("maxmemory")) &&
|
if (c.IsSet("mincpu") || c.IsSet("maxcpu") || c.IsSet("minmemory") || c.IsSet("maxmemory")) &&
|
||||||
invokeStrategy.ExecutionStrategy.ExecutorType == fission.ExecutorTypePoolmgr {
|
invokeStrategy.ExecutionStrategy.ExecutorType == fission.ExecutorTypePoolmgr {
|
||||||
warn("CPU/Memory specified for function with pool manager executor will be ignored in favor of resources specified at environment")
|
warn("CPU/Memory specified for function with pool manager executor will be ignored in favor of resources specified at environment")
|
||||||
@@ -469,9 +470,11 @@ func fnUpdate(c *cli.Context) error {
|
|||||||
ResourceVersion: pkgMetadata.ResourceVersion,
|
ResourceVersion: pkgMetadata.ResourceVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
function.Spec.Resources = getResourceReq(c)
|
function.Spec.Resources = getResourceReq(c, function.Spec.Resources)
|
||||||
|
|
||||||
function.Spec.InvokeStrategy.ExecutionStrategy.TargetCPUPercent = getTargetCPU(c)
|
if c.IsSet("targetcpu") {
|
||||||
|
function.Spec.InvokeStrategy.ExecutionStrategy.TargetCPUPercent = getTargetCPU(c)
|
||||||
|
}
|
||||||
|
|
||||||
if c.IsSet("minscale") {
|
if c.IsSet("minscale") {
|
||||||
minscale := c.Int("minscale")
|
minscale := c.Int("minscale")
|
||||||
@@ -496,7 +499,7 @@ func fnUpdate(c *cli.Context) error {
|
|||||||
function.Spec.InvokeStrategy.ExecutionStrategy.MaxScale = maxscale
|
function.Spec.InvokeStrategy.ExecutionStrategy.MaxScale = maxscale
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.String("executortype") != "" {
|
if c.IsSet("executortype") {
|
||||||
var fnExecutor fission.ExecutorType
|
var fnExecutor fission.ExecutorType
|
||||||
switch c.String("executortype") {
|
switch c.String("executortype") {
|
||||||
case "":
|
case "":
|
||||||
@@ -550,13 +553,19 @@ func fnList(c *cli.Context) error {
|
|||||||
|
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||||
|
|
||||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\n", "NAME", "UID", "ENV", "EXECUTORTYPE", "MINSCALE", "MAXSCALE", "TARGETCPU")
|
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n", "NAME", "UID", "ENV", "EXECUTORTYPE", "MINSCALE", "MAXSCALE", "MINCPU", "MAXCPU", "MINMEMORY", "MAXMEMORY", "TARGETCPU")
|
||||||
for _, f := range fns {
|
for _, f := range fns {
|
||||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\n",
|
mincpu := f.Spec.Resources.Requests.Cpu
|
||||||
|
mincpu().Value()
|
||||||
|
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n",
|
||||||
f.Metadata.Name, f.Metadata.UID, f.Spec.Environment.Name,
|
f.Metadata.Name, f.Metadata.UID, f.Spec.Environment.Name,
|
||||||
f.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType,
|
f.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType,
|
||||||
f.Spec.InvokeStrategy.ExecutionStrategy.MinScale,
|
f.Spec.InvokeStrategy.ExecutionStrategy.MinScale,
|
||||||
f.Spec.InvokeStrategy.ExecutionStrategy.MaxScale,
|
f.Spec.InvokeStrategy.ExecutionStrategy.MaxScale,
|
||||||
|
f.Spec.Resources.Requests.Cpu().String(),
|
||||||
|
f.Spec.Resources.Limits.Cpu().String(),
|
||||||
|
f.Spec.Resources.Requests.Memory().String(),
|
||||||
|
f.Spec.Resources.Limits.Memory().String(),
|
||||||
f.Spec.InvokeStrategy.ExecutionStrategy.TargetCPUPercent)
|
f.Spec.InvokeStrategy.ExecutionStrategy.TargetCPUPercent)
|
||||||
}
|
}
|
||||||
w.Flush()
|
w.Flush()
|
||||||
|
|||||||
Reference in New Issue
Block a user