-
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
bugfix: delete upperDir and workDir when deleting container taken over by pouch #2524
bugfix: delete upperDir and workDir when deleting container taken over by pouch #2524
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2524 +/- ##
==========================================
- Coverage 69.2% 69.07% -0.14%
==========================================
Files 278 278
Lines 18494 18694 +200
==========================================
+ Hits 12798 12912 +114
- Misses 4243 4309 +66
- Partials 1453 1473 +20
|
a11a875
to
d383214
Compare
|
||
if v, ok := c.Snapshotter.Data["WorkDir"]; ok { | ||
workDir = v | ||
} |
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.
What about refactor it to
if c.Snapshotter == nil || c.Snapshotter.Data == nil {
return
}
for _, dir := range []string{"MergedDir", "UpperDir", "WorkDir"} {
...
v, ok := c.Snapshotter.Data[dir]
if !ok {
continue
}
...
}
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.
@zhuangqh Your code haven't unlocked.
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 think the better codes like these:
if c.Snapshotter == nil || c.Snapshotter.Data == nil {
return
}
lock()
removeDirs []string
for _, dir := range []string{"MergedDir", "WorkDir", "UpperDir"} {
...
v, ok := c.Snapshotter.Data[dir]
if !ok {
continue
}
removeDirs = append(removeDir, v)
}
unlock()
for _, dir := range removeDirs {
os.Remove(...)
}
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.
@rudyfly I know. I just briefly point out how to refactor the code structure.
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.
daemon/mgr/container_types.go
Outdated
// WorkDir. Since the snapshot of container created by containerd will be cleaned by | ||
// containerd, so we only clean rootfs that is RootFSProvided. | ||
func (c *Container) CleanRootfsSnapshotDirs() error { | ||
// if RootFSProvided is set, we no need clean the rootfs |
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 comment is is not set
?
|
||
if v, ok := c.Snapshotter.Data["WorkDir"]; ok { | ||
workDir = v | ||
} |
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.
@zhuangqh Your code haven't unlocked.
daemon/mgr/container_types.go
Outdated
@@ -491,6 +492,51 @@ func (c *Container) GetSpecificBasePath(path string) string { | |||
return "" | |||
} | |||
|
|||
// CleanRootfsSnapshotDirs delete container's rootfs snapshot MergedDir, UpperDir and |
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/delete/deletes
|
||
if v, ok := c.Snapshotter.Data["WorkDir"]; ok { | ||
workDir = v | ||
} |
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 think the better codes like these:
if c.Snapshotter == nil || c.Snapshotter.Data == nil {
return
}
lock()
removeDirs []string
for _, dir := range []string{"MergedDir", "WorkDir", "UpperDir"} {
...
v, ok := c.Snapshotter.Data[dir]
if !ok {
continue
}
removeDirs = append(removeDir, v)
}
unlock()
for _, dir := range removeDirs {
os.Remove(...)
}
d383214
to
61c7e8e
Compare
…r by pouch Signed-off-by: ziren.wzr <ziren.wzr@alibaba-inc.com>
61c7e8e
to
30fd855
Compare
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.
LGTM. also cc @rudyfly
LGTM |
Signed-off-by: ziren.wzr ziren.wzr@alibaba-inc.com
Ⅰ. Describe what this PR did
When using d2p-migrator to upgrade docker to PouchContainer, we take over the old container's network, volumes, but the snapshot of an old container is not charged by pouchd.
So when we delete the old containers, the
UpperDir
andWorkDir
still stay on the host, they will cost many disk space. Moreover, if the directories have disk quota id, it will make the new containers used the same disk quota id cannot use the total storage that they should. we can make it more clear:The old
UpperDir
that has disk quota id 1111 costs 20G disk space, if we create a new container with the same disk quota id 1111 and intend to assign 100G disk space. Since the oldUpperDir
has occupied 20G, so the new container actually just can use 80G disk space.Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews