-
Notifications
You must be signed in to change notification settings - Fork 374
runtime: Fix /var/lib/vc/sbs/${sid} dir residual #2922
Conversation
/test-ubuntu |
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.
@keloyang, I'm not sure if I understand this fix.
Would you mind to elaborate why it's needed? Please, also add the details to the commit message.
Codecov Report
@@ Coverage Diff @@
## master #2922 +/- ##
==========================================
- Coverage 51.44% 50.00% -1.44%
==========================================
Files 118 118
Lines 17428 15559 -1869
==========================================
- Hits 8966 7781 -1185
+ Misses 7379 6717 -662
+ Partials 1083 1061 -22 |
@keloyang - Thanks for raising! A couple of things:
|
Let me give it a try on my environment here, thanks for the update @keloyang. |
@keloyang Thanks for the fix! LGTM. Could you please add add a unit/integration test verifying this behaviour? |
@amshinde @jodh-intel unit test case added, ptal, thanks. |
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'd like to ask @amshinde, @jodh-intel, to not merge this one yet!
I want to try to reproduce this one and will most likely find some time this evening to do so.
There are a few things puzzling me here, which I'm commenting inline.
virtcontainers/sandbox.go
Outdated
@@ -837,7 +837,10 @@ func (s *Sandbox) Delete() error { | |||
} | |||
|
|||
s.agent.cleanup(s) | |||
|
|||
vcStore, err := store.NewVCSandboxStore(s.ctx, s.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.
Do we really have to create a new vcStore or should we just use s.store?
virtcontainers/sandbox.go
Outdated
|
||
vcStore, err := store.NewVCSandboxStore(s.ctx, s.id) | ||
if err == nil { | ||
vcStore.Delete() |
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.
We definitely should check for errors here, at least to log them.
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.
Thanks @keloyang - just one comment.
virtcontainers/sandbox_test.go
Outdated
assert.NoError(err) | ||
|
||
// expect runtimSidPath not exist, if exist, it means this case failed. | ||
if _, err := os.Stat(runtimSidPath); err == nil || os.IsExist(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.
I think it would be clearer to write this as separate tests:
err := os.Stat(runtimSidPath)
assert.Error(err)
assert.True(os.IsNotExist(err))
@fidencio - agreed - added |
thanks for your review. runtime set s.store only when useOldStore(ctx) is true in https://github.com/kata-containers/runtime/blob/master/virtcontainers/sandbox.go#L573, this need loadSandboxConfigFromOldStore return nil, but it return error if old store don't exist. this means everytime when fetchSandbox is called ,it will create a vcStore, but s.store is nil. so we can't use s.store simplely. |
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've made some comments inline, but I must admit I'm failing to reproduce the issues.
What's exactly the version of the runtime you're using that you can reproduce it?
@@ -728,14 +728,14 @@ func fetchSandbox(ctx context.Context, sandboxID string) (sandbox *Sandbox, err | |||
|
|||
var config SandboxConfig | |||
|
|||
// Try to load sandbox config from old store at first. | |||
c, ctx, err := loadSandboxConfigFromOldStore(ctx, sandboxID) | |||
// Try to load sandbox config from new store at first. |
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.
@keloyang, what was the reason of inverting the logic here?
I think we still should try to load from the old store at first.
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 root cause of the residue is loadSandboxConfigFromOldStore is called but old store file is not exist, and if load sandbox from new store successfull, there is no need to call loadSandboxConfigFromOldStore.
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.
Let me ask some more experienced people for some help.
I think we still should try to load the old store first.
In that very same code path we call createSandbox()
, which calls newSandbox()
and there depending on whether we use the old store or not we'd call store.NewCVSandboxStore()
.
My question here is, why we only call that for one case?
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.
@jodh-intel, maybe you can help me with this one? ^^
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.
@amshinde, @jodh-intel, @egernst,
ping about this question.
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.
@fidencio This patch makes sense to me. We have kept the old store code around for backward compatibility. But by checking for the old store and trying to initialize one and checking for failure while using the old store, we were inadvertently creating the directory structure under /var/lib/vc/sbs/{sandbox_id}
and leaving that around after the sandbox is deleted.
It makes sense to me to check for the new store first instead. I tested this patch and works as expected.
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.
ack then!
virtcontainers/sandbox.go
Outdated
@@ -837,7 +837,11 @@ func (s *Sandbox) Delete() error { | |||
} | |||
|
|||
s.agent.cleanup(s) | |||
|
|||
if useOldStore(s.ctx) && s.store != nil { |
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.
@keloyang what's the reason of only doing this for an old store?
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.
useOldStore return true only loadSandboxConfigFromOldStore return successfully, so I add useOldStore here, but it's not necessary.
@fidencio please show me how do you try to reproduce, I use the master branch, and it's easy to reproduce.
|
@keloyang - please check the CI's at the end of your PR. Travis is failing on this one too:
|
I was able to reproduce the issue and I raised a comment on a part that I don't have a clear understanding. Let's wait till the other developers jump into that. |
Create and delete a kata container everytime, the directory of /var/lib/vc/sbs/ will have a new directory which's name is the ${sandbox-id}, e.g. d3e0482b22b9e25cd3268608b12ab8c1eb666960c4fa9a6a72a3e4d0b1606551 Fixes: #2921 Signed-off-by: Shukui Yang <keloyangsk@gmail.com>
updated and sorry for not gofmt, thanks @jodh-intel |
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.
Thanks @keloyang.
lgtm
/test |
/test-ubuntu-qemu-metrics |
@keloyang - I've restarted the failing metrics CI to see if this PR now passes. Please can you port this to 2.0 (https://github.com/kata-containers/kata-containers), or add a link to the 2.0 PR here if already done? |
I had tested a previous version of this PR, will like to take another look before this is merged. |
lgtm @fidencio. I think this one is ready to be merged. |
I think there is no need to do porting for 2.0-dev, because there is no code to call loadSandboxConfigFromOldStore in fetchSandbox, see https://github.com/kata-containers/kata-containers/blob/2.0-dev/src/runtime/virtcontainers/sandbox.go#L650. |
/test-centos |
/test-rhel |
@keloyang - Regarding, #2922 (comment), I think you are correct, so I'm removing the |
Fixes: #2921
runtime call fetchSandbox-->loadSandboxConfigFromOldStore-->store.NewVCSandboxStore--> ... f.initialize --> os.MkdirAll(f.path, DirMode)
and at last create /var/lib/vc/sbs/${sid}, but don't delete it before delete sandbox.
Signed-off-by: Shukui Yang keloyangsk@gmail.com