Skip to content

Commit 87768ed

Browse files
author
lijianguo
committed
chore(limits):drycc limits cmd remove requests
1 parent 9a5c478 commit 87768ed

7 files changed

Lines changed: 35 additions & 47 deletions

File tree

cmd/limits.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ func parseLimits(limits []string) (map[string]interface{}, error) {
145145
}
146146

147147
func parseLimit(limit string) (string, string, error) {
148-
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?}))?)$")
148+
regex := regexp.MustCompile("^([a-z0-9]+(?:-[a-z0-9]+)*)=(([0-9]+[bkmgBKMG]{1,2}|[0-9.]{1,5}|[0-9.]{1,5}m?))$")
149149

150150
if !regex.MatchString(limit) {
151-
return "", "", fmt.Errorf(`%s doesn't fit format type=#unit or type=# or type=#/#
152-
Examples: web=2G worker=500M db=1G/2G`, limit)
151+
return "", "", fmt.Errorf(`%s doesn't fit format type=#unit or type=#
152+
Examples: web=2G worker=500M db=1G`, limit)
153153
}
154154

155155
capture := regex.FindStringSubmatch(limit)

cmd/limits_test.go

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,22 @@ type parseLimitCase struct {
2222
func TestParseLimit(t *testing.T) {
2323
t.Parallel()
2424

25-
var errorHint = ` doesn't fit format type=#unit or type=# or type=#/#
26-
Examples: web=2G worker=500M db=1G/2G`
25+
var errorHint = ` doesn't fit format type=#unit or type=#
26+
Examples: web=2G worker=500M db=1G`
2727

2828
cases := []parseLimitCase{
2929
{"web=2G", "web", "2G", false, ""},
3030
{"web=2", "web", "2", false, ""},
3131
{"web=100m", "web", "100m", false, ""},
3232
{"web=0.1", "web", "0.1", false, ""},
3333
{"web=.123", "web", ".123", false, ""},
34-
{"web=2G/4G", "web", "2G/4G", false, ""},
35-
{"web=2/4", "web", "2/4", false, ""},
36-
{"web=200m/400m", "web", "200m/400m", false, ""},
37-
{"web=0.2/0.4", "web", "0.2/0.4", false, ""},
38-
{"web=.2/.4", "web", ".2/.4", false, ""},
3934
{"web1=2G", "web1", "2G", false, ""},
4035
{"web-server=2G", "web-server", "2G", false, ""},
4136
{"web-server1=2G", "web-server1", "2G", false, ""},
4237
{"=1", "", "", true, "=1" + errorHint},
4338
{"web=", "", "", true, "web=" + errorHint},
4439
{"1=", "", "", true, "1=" + errorHint},
4540
{"web=G", "", "", true, "web=G" + errorHint},
46-
{"web=/", "", "", true, "web=/" + errorHint},
47-
{"web=/1", "", "", true, "web=/1" + errorHint},
4841
{"web-=2G", "", "", true, "web-=2G" + errorHint},
4942
{"-web=2G", "", "", true, "-web=2G" + errorHint},
5043
{"Web=2G", "", "", true, "Web=2G" + errorHint},
@@ -74,8 +67,8 @@ func TestLimitTags(t *testing.T) {
7467

7568
cases := []parseLimitsCase{
7669
{[]string{"web=1G", "worker=2"}, map[string]interface{}{"web": "1G", "worker": "2"}, false, ""},
77-
{[]string{"foo=", "web=1G"}, nil, true, `foo= doesn't fit format type=#unit or type=# or type=#/#
78-
Examples: web=2G worker=500M db=1G/2G`},
70+
{[]string{"foo=", "web=1G"}, nil, true, `foo= doesn't fit format type=#unit or type=#
71+
Examples: web=2G worker=500M db=1G`},
7972
}
8073

8174
for _, check := range cases {
@@ -105,12 +98,12 @@ func TestLimitsList(t *testing.T) {
10598
"values": {},
10699
"memory": {
107100
"web": "2G",
108-
"db": "1000M/1500M"
101+
"db": "1000M"
109102
},
110103
"cpu": {
111104
"web": "2",
112105
"worker": "1",
113-
"db": "500m/2000m"
106+
"db": "500m"
114107
},
115108
"tags": {},
116109
"registry": {},
@@ -128,11 +121,11 @@ func TestLimitsList(t *testing.T) {
128121
assert.Equal(t, b.String(), `=== enterprise Limits
129122
130123
--- Memory
131-
db 1000M/1500M
124+
db 1000M
132125
web 2G
133126
134127
--- CPU
135-
db 500m/2000m
128+
db 500m
136129
web 2
137130
worker 1
138131
`, "output")
@@ -265,8 +258,8 @@ Unlimited
265258
testutil.AssertBody(t, api.Config{
266259
Memory: map[string]interface{}{
267260
"web": "2000M",
268-
"worker": "0/3G",
269-
"db": "4G/5G",
261+
"worker": "3G",
262+
"db": "5G",
270263
},
271264
}, r)
272265
}
@@ -277,8 +270,8 @@ Unlimited
277270
"values": {},
278271
"memory": {
279272
"web": "2000M",
280-
"worker": "0/3G",
281-
"db": "4G/5G"
273+
"worker": "3G",
274+
"db": "5G"
282275
},
283276
"cpu": {},
284277
"tags": {},
@@ -290,17 +283,17 @@ Unlimited
290283
})
291284
b.Reset()
292285

293-
err = cmdr.LimitsSet("jim", []string{"web=2000M", "worker=0/3G", "db=4G/5G"}, "memory")
286+
err = cmdr.LimitsSet("jim", []string{"web=2000M", "worker=3G", "db=5G"}, "memory")
294287
assert.NoErr(t, err)
295288

296289
assert.Equal(t, testutil.StripProgress(b.String()), `Applying limits... done
297290
298291
=== jim Limits
299292
300293
--- Memory
301-
db 4G/5G
294+
db 5G
302295
web 2000M
303-
worker 0/3G
296+
worker 3G
304297
305298
--- CPU
306299
Unlimited
@@ -313,8 +306,8 @@ Unlimited
313306
testutil.AssertBody(t, api.Config{
314307
CPU: map[string]interface{}{
315308
"web": "2",
316-
"worker": "0/300m",
317-
"db": "4/5.6",
309+
"worker": "300m",
310+
"db": "5.6",
318311
},
319312
}, r)
320313
}
@@ -325,8 +318,8 @@ Unlimited
325318
"values": {},
326319
"cpu": {
327320
"web": "2",
328-
"worker": "0/300m",
329-
"db": "4/5.6"
321+
"worker": "300m",
322+
"db": "5.6"
330323
},
331324
"cpu": {},
332325
"tags": {},
@@ -338,7 +331,7 @@ Unlimited
338331
})
339332
b.Reset()
340333

341-
err = cmdr.LimitsSet("phew", []string{"web=2", "worker=0/300m", "db=4/5.6"}, "cpu")
334+
err = cmdr.LimitsSet("phew", []string{"web=2", "worker=300m", "db=5.6"}, "cpu")
342335
assert.NoErr(t, err)
343336

344337
assert.Equal(t, testutil.StripProgress(b.String()), `Applying limits... done
@@ -349,9 +342,9 @@ Unlimited
349342
Unlimited
350343
351344
--- CPU
352-
db 4/5.6
345+
db 5.6
353346
web 2
354-
worker 0/300m
347+
worker 300m
355348
`, "output")
356349
}
357350

cmd/volumes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ func printVolumes(d *DryccCmd, appID string, volumes api.Volumes, wOut io.Writer
4343

4444
var max int
4545
for _, volume := range volumes {
46-
if max < (len(volume.Name) + 4){
46+
if max < (len(volume.Name) + 4) {
4747
max = len(volume.Name) + 4
4848
}
49-
for key, _ := range volume.Path {
50-
if max < len(key){
49+
for key := range volume.Path {
50+
if max < len(key) {
5151
max = len(key)
5252
}
5353
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.13
55
require (
66
github.com/arschles/assert v1.0.1-0.20191213221312-71f210f9375a
77
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
8-
github.com/drycc/controller-sdk-go v0.0.0-20200910051502-0b84631ba397
8+
github.com/drycc/controller-sdk-go v0.0.0-20200914062048-dcf027e6dd1a
99
github.com/drycc/pkg v0.0.0-20200811173146-1f2b2781a852
1010
github.com/olekukonko/tablewriter v0.0.4
1111
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ github.com/drycc/controller-sdk-go v0.0.0-20200901021526-471d3aa9862b h1:scZpGVS
3838
github.com/drycc/controller-sdk-go v0.0.0-20200901021526-471d3aa9862b/go.mod h1:mF8/kZ/E4oDHCtfUVS790Frm8oVzZkoCGCKYT2eWQro=
3939
github.com/drycc/controller-sdk-go v0.0.0-20200910051502-0b84631ba397 h1:MbpNwDOmS0+YxR0S8AsmygAj2qsOy9PjmLUzI76OhZs=
4040
github.com/drycc/controller-sdk-go v0.0.0-20200910051502-0b84631ba397/go.mod h1:mF8/kZ/E4oDHCtfUVS790Frm8oVzZkoCGCKYT2eWQro=
41+
github.com/drycc/controller-sdk-go v0.0.0-20200914062048-dcf027e6dd1a h1:sQEQ8KUgm3X1y8XVsGXqeAkeowMGdOtu+PwBgd4V2eU=
42+
github.com/drycc/controller-sdk-go v0.0.0-20200914062048-dcf027e6dd1a/go.mod h1:mF8/kZ/E4oDHCtfUVS790Frm8oVzZkoCGCKYT2eWQro=
4143
github.com/drycc/pkg v0.0.0-20190129033019-bcdffff0fcb3 h1:QRAbL97/hJecXQzaSONMCiwt1JjBKAAMKK0qJW5sgIM=
4244
github.com/drycc/pkg v0.0.0-20190129033019-bcdffff0fcb3/go.mod h1:zNgTT6kuGZOKMIdSrjskIw5fctdbbszqiTPEt3ffxHw=
4345
github.com/drycc/pkg v0.0.0-20200811173146-1f2b2781a852 h1:OsWH7jrv2i32rkvHFuj3yVpGMR+A6heRge9tm01XR/U=

parser/limits.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,11 @@ Options:
6161

6262
func limitSet(argv []string, cmdr cmd.Commander) error {
6363
usage := `
64-
Sets resource requests and limits for an application.
64+
Sets resource limits for an application.
6565
6666
A resource limit is a finite resource within a pod which we can apply
67-
restrictions through Kubernetes. A resource request is used by Kubernetes scheduler
68-
to select a node that can guarantee requested resource. If provided only one value,
69-
it'll be default by Kubernetes as both request and limit. These request and limit
70-
are applied to each individual pod, so setting a memory limit of 1G for an application
71-
means that each pod gets 1G of memory. Value needs to be within 0 <= request <= limit
67+
restrictions through Kubernetes.The limit is applied to each individual pod,
68+
so setting a memory limit of 1G for an application means that each pod gets 1G of memory.
7269
7370
Usage: drycc limits:set [options] <type>=<value>...
7471
@@ -78,7 +75,7 @@ Arguments:
7875
Note that Dockerfile apps have a default 'cmd' process type.
7976
<value>
8077
The value to apply to the process type. By default, this is set to --memory.
81-
Can be in <limit> or <request>/<limit> format eg. web=2G db=1G/2G
78+
Can be in <limit> format eg. web=2G db=1G
8279
You can only set one type of limit per call.
8380
8481
With --memory, units are represented in Bytes (B), Kilobytes (K), Megabytes

parser/limits_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ func TestLimits(t *testing.T) {
5353
args: []string{"limits:set", "web=1G worker=2G"},
5454
expected: "",
5555
},
56-
{
57-
args: []string{"limits:set", "web=1G/2G worker=2G/4G"},
58-
expected: "",
59-
},
6056
{
6157
args: []string{"limits:set", "--cpu", "web=1"},
6258
expected: "",

0 commit comments

Comments
 (0)