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

Commit

Permalink
virtcontainers: update resources after adding container to sandbox
Browse files Browse the repository at this point in the history
Status of container should know prior to calculate the number of CPU
and memory

Signed-off-by: Julio Montes <julio.montes@intel.com>
  • Loading branch information
Julio Montes committed Nov 25, 2019
1 parent fea166d commit 43f0513
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -1176,12 +1176,6 @@ func (s *Sandbox) CreateContainer(contConfig ContainerConfig) (VCContainer, erro
}
}()

// Sandbox is reponsable to update VM resources needed by Containers
err = s.updateResources()
if err != nil {
return nil, err
}

err = c.create()
if err != nil {
return nil, err
Expand All @@ -1192,6 +1186,14 @@ func (s *Sandbox) CreateContainer(contConfig ContainerConfig) (VCContainer, erro
return nil, err
}

// Sandbox is reponsable to update VM resources needed by Containers
// Update resources after having added containers to the sandbox, since
// container status is requiered to know if more resources should be added.
err = s.updateResources()
if err != nil {
return nil, err
}

// Store it.
err = c.storeContainer()
if err != nil {
Expand Down Expand Up @@ -1228,7 +1230,13 @@ func (s *Sandbox) StartContainer(containerID string) (VCContainer, error) {
}

s.Logger().Info("Container is started")
//Fixme Container delete from sandbox, need to update resources

// Update sandbox resources in case a stopped container
// is started
err = s.updateResources()
if err != nil {
return nil, err
}

return c, nil
}
Expand Down Expand Up @@ -1487,10 +1495,6 @@ func (s *Sandbox) createContainers() error {
span, _ := s.trace("createContainers")
defer span.Finish()

if err := s.updateResources(); err != nil {
return err
}

for _, contConfig := range s.config.Containers {

c, err := newContainer(s, &contConfig)
Expand All @@ -1506,6 +1510,12 @@ func (s *Sandbox) createContainers() error {
}
}

// Update resources after having added containers to the sandbox, since
// container status is requiered to know if more resources should be added.
if err := s.updateResources(); err != nil {
return err
}

if err := s.cgroupsUpdate(); err != nil {
return err
}
Expand Down

0 comments on commit 43f0513

Please sign in to comment.