-
Notifications
You must be signed in to change notification settings - Fork 950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add diskquota support regular expression #1057
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1057 +/- ##
==========================================
+ Coverage 15.62% 15.69% +0.07%
==========================================
Files 172 172
Lines 9672 9673 +1
==========================================
+ Hits 1511 1518 +7
+ Misses 8052 8045 -7
- Partials 109 110 +1
|
daemon/mgr/container.go
Outdated
@@ -1424,6 +1432,66 @@ func (mgr *ContainerManager) parseBinds(ctx context.Context, meta *ContainerMeta | |||
return nil | |||
} | |||
|
|||
func (mgr *ContainerManager) setMountPointDiskQuota(ctx context.Context, c *ContainerMeta) error { | |||
type diskQuotaRegExp struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think defining a struct in function setMountPointDiskQuota
is a good idea.
Maybe we could move this into diskquota package. WDYT? @rudyfly
pkg/quota/grpquota.go
Outdated
@@ -144,7 +144,7 @@ func (quota *GrpQuota) SetDiskQuota(dir string, size string, quotaID int) error | |||
return fmt.Errorf("mountpoint not found: %s", dir) | |||
} | |||
|
|||
id, err := quota.SetSubtree(dir, uint32(quotaID)) | |||
id, err := quota.SetSubtree(dir, quotaID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to judge whether err is not nil first?
pkg/quota/prjquota.go
Outdated
@@ -114,7 +114,7 @@ func (quota *PrjQuota) SetDiskQuota(dir string, size string, quotaID int) error | |||
return fmt.Errorf("mountpoint not found: %s", dir) | |||
} | |||
|
|||
id, err := quota.SetSubtree(dir, uint32(quotaID)) | |||
id, err := quota.SetSubtree(dir, quotaID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to judge whether err is not nil first?
pkg/quota/set_diskquota.go
Outdated
@@ -37,13 +38,15 @@ func processSetQuotaReexec() { | |||
} | |||
}() | |||
|
|||
if len(os.Args) != 3 { | |||
if len(os.Args) != 4 { | |||
err = fmt.Errorf("invalid arguments: %v, it should be: %s: <path> <size>", os.Args, os.Args[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the next statement is return
, I am wondering what is the usage of err = fmt.Errorf("invalid arguments: %v, it should be: %s: <path> <size>", os.Args, os.Args[0])
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh,I forgot to modify this error.
Actually I could not quite follow you via the title. |
85b3773
to
2d0c056
Compare
PTAL @allencloud @yyb196 |
if len(os.Args) != 3 { | ||
err = fmt.Errorf("invalid arguments: %v, it should be: %s: <path> <size>", os.Args, os.Args[0]) | ||
if len(os.Args) != 4 { | ||
err = fmt.Errorf("invalid arguments: %v, it should be: %s: <path> <size> <quota id>", os.Args, os.Args[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This err assignment is useless. I think we need to add a log to record this.
logrus.Errorf("invalid arguments: %v, it should be: %s: <path> <size> <quota id>", os.Args, os.Args[0])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will return the error to runc and then print it. All the hooks do it like this.
if err != nil { | ||
logrus.Errorf("failed to set subtree: %v", err) | ||
return | ||
} | ||
|
||
err = SetDiskQuota(dir, size, int(qid)) | ||
err = SetDiskQuota(dir, size, qid) | ||
if err != nil { | ||
logrus.Errorf("failed to set disk quota: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to return at the err point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your reminder.
@@ -326,7 +326,7 @@ func (suite *PouchNetworkSuite) TestNetworkPortMapping(c *check.C) { | |||
"-p", "9999:80", | |||
image).Assert(c, icmd.Success) | |||
|
|||
time.Sleep(1 * time.Second) | |||
time.Sleep(10 * time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why to change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The network test is always fail, so I increase the delay time.
) | ||
|
||
if c.Config.QuotaID != "" { | ||
id, err := strconv.Atoi(c.Config.QuotaID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, we will move this kind of validation out of package mgr. And it should be in the scope of bridge layer.
apis/swagger.yml
Outdated
@@ -1784,6 +1784,9 @@ definitions: | |||
type: "object" | |||
additionalProperties: | |||
type: "string" | |||
QuotaID: | |||
type: "string" | |||
description: "set disk quota by specified quota id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add more description that how many kinds of quota is there and what do they mean?
pkg/quota/quota.go
Outdated
@@ -120,3 +120,22 @@ func SetFileAttrNoOutput(dir string, id uint32) { | |||
func GetNextQuatoID() (uint32, error) { | |||
return Gquota.GetNextQuatoID() | |||
} | |||
|
|||
//GetDefaultQuota returns the default quota. | |||
func GetDefaultQuota(quotas map[string]string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change this into GetDefaultQuotaSize
?
daemon/mgr/container.go
Outdated
quotas := c.Config.DiskQuota | ||
defaultQuota := quota.GetDefaultQuota(quotas) | ||
if setQuotaID && defaultQuota == "" { | ||
return fmt.Errorf("set quota id but have no set quota size") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid we need to emphasize the default
, since default will take /
and *.
into consideration.
set quota id but have no set default
quota size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set quota id but have no set default quota size?
It will be failed when create container.
for _, re := range res { | ||
findStr := re.Pattern.FindString(mp.Destination) | ||
if findStr == mp.Destination { | ||
quotas[mp.Destination] = re.Size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If quotas is nil, maybe here we will run into a panic.
pkg/quota/set_diskquota.go
Outdated
return | ||
} | ||
|
||
basefs := os.Args[1] | ||
size := os.Args[2] | ||
id, _ := strconv.Atoi(os.Args[3]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if we should not ignore the error. Maybe we can just record it.
Add diskquota support regular expression. We can use pouch run --disk-quota="key=value" to set quota for container. This pr can make it support to use regular expression key, such as: --disk-quota=".=1g", it means all the quota of mount points are'1g', the priority of key'.'is the lowest. If it has no'key', just have'value', such as: --disk-quota=1g, it means the quota of rootfs is 1g. If the mountpoint is a volume, the quota of volume is base on volume's size, the disk-quota is not take effect on a volume. Signed-off-by: Rudy Zhang <rudyflyzhang@gmail.com>
Specified quota id for a container, if id < 0, it means pouchd alloc a unique quota id. If specified quota id, it will ignore the quota's regular expression, but the volume will keep its size as before. Signed-off-by: Rudy Zhang <rudyflyzhang@gmail.com>
|
||
// if QuotaID is < 0, it means pouchd alloc a unique quota id. | ||
if id < 0 { | ||
qid, err = quota.GetNextQuatoID() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/GetNextQuatoID/GetNextQuotaID
@@ -120,3 +120,22 @@ func SetFileAttrNoOutput(dir string, id uint32) { | |||
func GetNextQuatoID() (uint32, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/GetNextQuatoID/GetNextQuotaID
LGTM |
Ⅰ. Describe what this PR did
Add diskquota support regular expression.
Ⅱ. Does this pull request fix one issue?
NONE
Ⅲ. Describe how you did it
We can use
pouch run --disk-quota="key=value"
to set quota for container. This pr can make it support to use regular expression key, such as: --disk-quota=".=1g", it means all the quota of mount points are '1g', the priority of key '.' is the lowest. If it has no 'key', just have 'value', such as:--disk-quota=1g
, it means the quota of rootfs is 1g. If the mountpoint is a volume, the quota of volume is base on volume's size, the disk-quota is not take effect on a volume.Ⅳ. Describe how to verify it
The example is test case:
TestRunWithDiskQuotaRegular
create a volume with size limit: 256m
create a container with diskquota
Ⅴ. Special notes for reviews
Signed-off-by: Rudy Zhang rudyflyzhang@gmail.com