Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

virtcontainers/sandbox: calculate container's CPU from sandbox.contai… #2130

Merged
merged 1 commit into from
Oct 23, 2019

Conversation

fuxiao511
Copy link

…ners

sandbox.config.Containers is not up to date, so use container.config directly

Fixes: #2129

Signed-off-by: Wang Liang wangliangzz@inspur.com

@@ -1873,8 +1873,8 @@ func (s *Sandbox) calculateSandboxMemory() int64 {
func (s *Sandbox) calculateSandboxCPUs() uint32 {
mCPU := uint32(0)

for _, c := range s.config.Containers {
if cpu := c.Resources.CPU; cpu != nil {
for _, c := range s.containers {
Copy link
Member

@lifupan lifupan Oct 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think you can't simply using sandbox containers, since when creating a container in sandbox, the s.containers is updated later than calculating resources, thus you could lost accounting the created container's resources.
IMO the root cause is that the container's ContainerConfig pointer doesn't point to the instance located in sandbox's SandboxConfig's map of ContainerConfig, which caused the configure's not sync.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like we need some more unit tests in this area.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think there are issues for both of the cpu and memory resource updating.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lifupan Yes, the root cause is that the container's ContainerConfig pointer doesn't point to the instance located in sandbox's SandboxConfig's map of ContainerConfig.

If we want to fix this way, we need to modify code in fetchSandbox->fetchContainers->newContainer, pass by reference, and more tests.

Or we can just update sandbox's SandboxConfig's map of ContainerConfig at container.go:update(), which need a add method such like
func (s *Sandbox) updateConfig() error

Which way do you perfer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lifupan Yes, the root cause is that the container's ContainerConfig pointer doesn't point to the instance located in sandbox's SandboxConfig's map of ContainerConfig.

If we want to fix this way, we need to modify code in fetchSandbox->fetchContainers->newContainer, pass by reference, and more tests.

I'd prefer this one, thus we can keep only one instance of container's config in memory and changed it at one place would be saw in other place.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,I'll try to code it.

@@ -785,7 +785,7 @@ func newContainer(sandbox *Sandbox, contConfig ContainerConfig) (*Container, err
return nil, err
}

if err = c.createDevices(contConfig); err != nil {
if err = c.createDevices(*contConfig); err != nil {
Copy link
Member

@lifupan lifupan Oct 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For c.createDevice function, I think you can also change it's parameter from instance to pointer.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can change it in code. But I don't think we can change its semantics, we cannot change contConfig at createDevices procedure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is change it in code, since there is no need to pass an config instance here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll change it.
Should I change and force-push all this two commits again, or just add a new commit?
which one is better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to change them in a single commit and do a force push

container.config does not point to sandbox.config.Containers.ContainerConfig
which caused the ContainerConfig not sync.

Fixes: kata-containers#2129

Signed-off-by: Wang Liang <wangliangzz@inspur.com>
@bergwolf
Copy link
Member

/test

@codecov
Copy link

codecov bot commented Oct 14, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@c7b4c5e). Click here to learn what that means.
The diff coverage is 100%.

@@            Coverage Diff            @@
##             master    #2130   +/-   ##
=========================================
  Coverage          ?   51.35%           
=========================================
  Files             ?      109           
  Lines             ?    15074           
  Branches          ?        0           
=========================================
  Hits              ?     7742           
  Misses            ?     6380           
  Partials          ?      952

@fuxiao511
Copy link
Author

@bergwolf There are two tests failed. They seem to have nothing to do with this commit.
Can I do something, or should I just wait it to be fixed by others?

Copy link
Contributor

@jodh-intel jodh-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@egernst
Copy link
Member

egernst commented Oct 23, 2019

virtio-fs CI failure is the dnf issue which is known.

@egernst egernst merged commit da98191 into kata-containers:master Oct 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot update sandbox‘s CPU config
5 participants