From 87768ed7446aadb21266ea84a4d723275891e0dc Mon Sep 17 00:00:00 2001
From: lijianguo <lijianguo@zhumengyuan.com>
Date: Mon, 21 Sep 2020 10:28:43 +0800
Subject: [PATCH] chore(limits):drycc limits cmd remove requests

---
 cmd/limits.go         |  6 ++---
 cmd/limits_test.go    | 51 +++++++++++++++++++------------------------
 cmd/volumes.go        |  6 ++---
 go.mod                |  2 +-
 go.sum                |  2 ++
 parser/limits.go      | 11 ++++------
 parser/limits_test.go |  4 ----
 7 files changed, 35 insertions(+), 47 deletions(-)

diff --git a/cmd/limits.go b/cmd/limits.go
index 5b12d1df3..02e6956fa 100644
--- a/cmd/limits.go
+++ b/cmd/limits.go
@@ -145,11 +145,11 @@ func parseLimits(limits []string) (map[string]interface{}, error) {
 }
 
 func parseLimit(limit string) (string, string, error) {
-	regex := regexp.MustCompile("^([a-z0-9]+(?:-[a-z0-9]+)*)=(([0-9]+[bkmgBKMG]{1,2}|[0-9.]{1,5}|[0-9.]{1,5}m?)(/([0-9]+[bkmgBKMG]{1,2}|[0-9.]{1,5}|[0-9.]{1,5}m?}))?)$")
+	regex := regexp.MustCompile("^([a-z0-9]+(?:-[a-z0-9]+)*)=(([0-9]+[bkmgBKMG]{1,2}|[0-9.]{1,5}|[0-9.]{1,5}m?))$")
 
 	if !regex.MatchString(limit) {
-		return "", "", fmt.Errorf(`%s doesn't fit format type=#unit or type=# or type=#/#
-Examples: web=2G worker=500M db=1G/2G`, limit)
+		return "", "", fmt.Errorf(`%s doesn't fit format type=#unit or type=#
+Examples: web=2G worker=500M db=1G`, limit)
 	}
 
 	capture := regex.FindStringSubmatch(limit)
diff --git a/cmd/limits_test.go b/cmd/limits_test.go
index 9ea6d2806..0916f338c 100644
--- a/cmd/limits_test.go
+++ b/cmd/limits_test.go
@@ -22,8 +22,8 @@ type parseLimitCase struct {
 func TestParseLimit(t *testing.T) {
 	t.Parallel()
 
-	var errorHint = ` doesn't fit format type=#unit or type=# or type=#/#
-Examples: web=2G worker=500M db=1G/2G`
+	var errorHint = ` doesn't fit format type=#unit or type=#
+Examples: web=2G worker=500M db=1G`
 
 	cases := []parseLimitCase{
 		{"web=2G", "web", "2G", false, ""},
@@ -31,11 +31,6 @@ Examples: web=2G worker=500M db=1G/2G`
 		{"web=100m", "web", "100m", false, ""},
 		{"web=0.1", "web", "0.1", false, ""},
 		{"web=.123", "web", ".123", false, ""},
-		{"web=2G/4G", "web", "2G/4G", false, ""},
-		{"web=2/4", "web", "2/4", false, ""},
-		{"web=200m/400m", "web", "200m/400m", false, ""},
-		{"web=0.2/0.4", "web", "0.2/0.4", false, ""},
-		{"web=.2/.4", "web", ".2/.4", false, ""},
 		{"web1=2G", "web1", "2G", false, ""},
 		{"web-server=2G", "web-server", "2G", false, ""},
 		{"web-server1=2G", "web-server1", "2G", false, ""},
@@ -43,8 +38,6 @@ Examples: web=2G worker=500M db=1G/2G`
 		{"web=", "", "", true, "web=" + errorHint},
 		{"1=", "", "", true, "1=" + errorHint},
 		{"web=G", "", "", true, "web=G" + errorHint},
-		{"web=/", "", "", true, "web=/" + errorHint},
-		{"web=/1", "", "", true, "web=/1" + errorHint},
 		{"web-=2G", "", "", true, "web-=2G" + errorHint},
 		{"-web=2G", "", "", true, "-web=2G" + errorHint},
 		{"Web=2G", "", "", true, "Web=2G" + errorHint},
@@ -74,8 +67,8 @@ func TestLimitTags(t *testing.T) {
 
 	cases := []parseLimitsCase{
 		{[]string{"web=1G", "worker=2"}, map[string]interface{}{"web": "1G", "worker": "2"}, false, ""},
-		{[]string{"foo=", "web=1G"}, nil, true, `foo= doesn't fit format type=#unit or type=# or type=#/#
-Examples: web=2G worker=500M db=1G/2G`},
+		{[]string{"foo=", "web=1G"}, nil, true, `foo= doesn't fit format type=#unit or type=#
+Examples: web=2G worker=500M db=1G`},
 	}
 
 	for _, check := range cases {
@@ -105,12 +98,12 @@ func TestLimitsList(t *testing.T) {
 			"values": {},
 			"memory": {
 				"web": "2G",
-				"db": "1000M/1500M"
+				"db": "1000M"
 			},
 			"cpu": {
 				"web": "2",
 				"worker": "1",
-				"db": "500m/2000m"
+				"db": "500m"
 			},
 			"tags": {},
 			"registry": {},
@@ -128,11 +121,11 @@ func TestLimitsList(t *testing.T) {
 	assert.Equal(t, b.String(), `=== enterprise Limits
 
 --- Memory
-db      1000M/1500M
+db      1000M
 web     2G
 
 --- CPU
-db         500m/2000m
+db         500m
 web        2
 worker     1
 `, "output")
@@ -265,8 +258,8 @@ Unlimited
 			testutil.AssertBody(t, api.Config{
 				Memory: map[string]interface{}{
 					"web":    "2000M",
-					"worker": "0/3G",
-					"db":     "4G/5G",
+					"worker": "3G",
+					"db":     "5G",
 				},
 			}, r)
 		}
@@ -277,8 +270,8 @@ Unlimited
 			"values": {},
 			"memory": {
 				"web": "2000M",
-				"worker": "0/3G",
-				"db": "4G/5G"
+				"worker": "3G",
+				"db": "5G"
 			},
 			"cpu": {},
 			"tags": {},
@@ -290,7 +283,7 @@ Unlimited
 	})
 	b.Reset()
 
-	err = cmdr.LimitsSet("jim", []string{"web=2000M", "worker=0/3G", "db=4G/5G"}, "memory")
+	err = cmdr.LimitsSet("jim", []string{"web=2000M", "worker=3G", "db=5G"}, "memory")
 	assert.NoErr(t, err)
 
 	assert.Equal(t, testutil.StripProgress(b.String()), `Applying limits... done
@@ -298,9 +291,9 @@ Unlimited
 === jim Limits
 
 --- Memory
-db         4G/5G
+db         5G
 web        2000M
-worker     0/3G
+worker     3G
 
 --- CPU
 Unlimited
@@ -313,8 +306,8 @@ Unlimited
 			testutil.AssertBody(t, api.Config{
 				CPU: map[string]interface{}{
 					"web":    "2",
-					"worker": "0/300m",
-					"db":     "4/5.6",
+					"worker": "300m",
+					"db":     "5.6",
 				},
 			}, r)
 		}
@@ -325,8 +318,8 @@ Unlimited
 			"values": {},
 			"cpu": {
 				"web": "2",
-				"worker": "0/300m",
-				"db": "4/5.6"
+				"worker": "300m",
+				"db": "5.6"
 			},
 			"cpu": {},
 			"tags": {},
@@ -338,7 +331,7 @@ Unlimited
 	})
 	b.Reset()
 
-	err = cmdr.LimitsSet("phew", []string{"web=2", "worker=0/300m", "db=4/5.6"}, "cpu")
+	err = cmdr.LimitsSet("phew", []string{"web=2", "worker=300m", "db=5.6"}, "cpu")
 	assert.NoErr(t, err)
 
 	assert.Equal(t, testutil.StripProgress(b.String()), `Applying limits... done
@@ -349,9 +342,9 @@ Unlimited
 Unlimited
 
 --- CPU
-db         4/5.6
+db         5.6
 web        2
-worker     0/300m
+worker     300m
 `, "output")
 }
 
diff --git a/cmd/volumes.go b/cmd/volumes.go
index 28d85b9b0..3f0861a39 100644
--- a/cmd/volumes.go
+++ b/cmd/volumes.go
@@ -43,11 +43,11 @@ func printVolumes(d *DryccCmd, appID string, volumes api.Volumes, wOut io.Writer
 
 	var max int
 	for _, volume := range volumes {
-		if max < (len(volume.Name) + 4){
+		if max < (len(volume.Name) + 4) {
 			max = len(volume.Name) + 4
 		}
-		for key, _ := range volume.Path {
-			if max < len(key){
+		for key := range volume.Path {
+			if max < len(key) {
 				max = len(key)
 			}
 		}
diff --git a/go.mod b/go.mod
index 5f226d611..60ae8b227 100644
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ go 1.13
 require (
 	github.com/arschles/assert v1.0.1-0.20191213221312-71f210f9375a
 	github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
-	github.com/drycc/controller-sdk-go v0.0.0-20200910051502-0b84631ba397
+	github.com/drycc/controller-sdk-go v0.0.0-20200914062048-dcf027e6dd1a
 	github.com/drycc/pkg v0.0.0-20200811173146-1f2b2781a852
 	github.com/olekukonko/tablewriter v0.0.4
 	golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de
diff --git a/go.sum b/go.sum
index ae6684bac..f51464dec 100644
--- a/go.sum
+++ b/go.sum
@@ -38,6 +38,8 @@ github.com/drycc/controller-sdk-go v0.0.0-20200901021526-471d3aa9862b h1:scZpGVS
 github.com/drycc/controller-sdk-go v0.0.0-20200901021526-471d3aa9862b/go.mod h1:mF8/kZ/E4oDHCtfUVS790Frm8oVzZkoCGCKYT2eWQro=
 github.com/drycc/controller-sdk-go v0.0.0-20200910051502-0b84631ba397 h1:MbpNwDOmS0+YxR0S8AsmygAj2qsOy9PjmLUzI76OhZs=
 github.com/drycc/controller-sdk-go v0.0.0-20200910051502-0b84631ba397/go.mod h1:mF8/kZ/E4oDHCtfUVS790Frm8oVzZkoCGCKYT2eWQro=
+github.com/drycc/controller-sdk-go v0.0.0-20200914062048-dcf027e6dd1a h1:sQEQ8KUgm3X1y8XVsGXqeAkeowMGdOtu+PwBgd4V2eU=
+github.com/drycc/controller-sdk-go v0.0.0-20200914062048-dcf027e6dd1a/go.mod h1:mF8/kZ/E4oDHCtfUVS790Frm8oVzZkoCGCKYT2eWQro=
 github.com/drycc/pkg v0.0.0-20190129033019-bcdffff0fcb3 h1:QRAbL97/hJecXQzaSONMCiwt1JjBKAAMKK0qJW5sgIM=
 github.com/drycc/pkg v0.0.0-20190129033019-bcdffff0fcb3/go.mod h1:zNgTT6kuGZOKMIdSrjskIw5fctdbbszqiTPEt3ffxHw=
 github.com/drycc/pkg v0.0.0-20200811173146-1f2b2781a852 h1:OsWH7jrv2i32rkvHFuj3yVpGMR+A6heRge9tm01XR/U=
diff --git a/parser/limits.go b/parser/limits.go
index 099bd3cc2..5bdd76e09 100644
--- a/parser/limits.go
+++ b/parser/limits.go
@@ -61,14 +61,11 @@ Options:
 
 func limitSet(argv []string, cmdr cmd.Commander) error {
 	usage := `
-Sets resource requests and limits for an application.
+Sets resource limits for an application.
 
 A resource limit is a finite resource within a pod which we can apply
-restrictions through Kubernetes. A resource request is used by Kubernetes scheduler
-to select a node that can guarantee requested resource. If provided only one value,
-it'll be default by Kubernetes as both request and limit. These request and limit
-are applied to each individual pod, so setting a memory limit of 1G for an application
-means that each pod gets 1G of memory. Value needs to be within 0 <= request <= limit
+restrictions through Kubernetes.The limit is applied to each individual pod,
+so setting a memory limit of 1G for an application means that each pod gets 1G of memory.
 
 Usage: drycc limits:set [options] <type>=<value>...
 
@@ -78,7 +75,7 @@ Arguments:
     Note that Dockerfile apps have a default 'cmd' process type.
   <value>
     The value to apply to the process type. By default, this is set to --memory.
-    Can be in <limit> or <request>/<limit> format eg. web=2G db=1G/2G
+    Can be in <limit> format eg. web=2G db=1G
     You can only set one type of limit per call.
 
     With --memory, units are represented in Bytes (B), Kilobytes (K), Megabytes
diff --git a/parser/limits_test.go b/parser/limits_test.go
index 20fafb142..064211539 100644
--- a/parser/limits_test.go
+++ b/parser/limits_test.go
@@ -53,10 +53,6 @@ func TestLimits(t *testing.T) {
 			args:     []string{"limits:set", "web=1G worker=2G"},
 			expected: "",
 		},
-		{
-			args:     []string{"limits:set", "web=1G/2G worker=2G/4G"},
-			expected: "",
-		},
 		{
 			args:     []string{"limits:set", "--cpu", "web=1"},
 			expected: "",
