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

Commit

Permalink
Merge pull request #3019 from jcvenegas/stable-1.11-backports
Browse files Browse the repository at this point in the history
Stable 1.11 backports
  • Loading branch information
jcvenegas authored Oct 20, 2020
2 parents 9d82056 + 7e7c2ec commit 9a1aa02
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 38 deletions.
64 changes: 38 additions & 26 deletions containerd-shim-v2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,34 +337,46 @@ func (s *service) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (_ *
s.mu.Lock()
defer s.mu.Unlock()

var c *container

c, err = create(ctx, s, r)
if err != nil {
return nil, err
}

c.status = task.StatusCreated

s.containers[r.ID] = c
type Result struct {
container *container
err error
}
ch := make(chan Result, 1)
go func() {
container, err := create(ctx, s, r)
ch <- Result{container, err}
}()

s.send(&eventstypes.TaskCreate{
ContainerID: r.ID,
Bundle: r.Bundle,
Rootfs: r.Rootfs,
IO: &eventstypes.TaskIO{
Stdin: r.Stdin,
Stdout: r.Stdout,
Stderr: r.Stderr,
Terminal: r.Terminal,
},
Checkpoint: r.Checkpoint,
Pid: s.pid,
})
select {
case <-ctx.Done():
return nil, errors.Errorf("create container timeout: %v", r.ID)
case res := <-ch:
if res.err != nil {
return nil, res.err
}
container := res.container
container.status = task.StatusCreated

s.containers[r.ID] = container

s.send(&eventstypes.TaskCreate{
ContainerID: r.ID,
Bundle: r.Bundle,
Rootfs: r.Rootfs,
IO: &eventstypes.TaskIO{
Stdin: r.Stdin,
Stdout: r.Stdout,
Stderr: r.Stderr,
Terminal: r.Terminal,
},
Checkpoint: r.Checkpoint,
Pid: s.pid,
})

return &taskAPI.CreateTaskResponse{
Pid: s.pid,
}, nil
return &taskAPI.CreateTaskResponse{
Pid: s.pid,
}, nil
}
}

// Start a process
Expand Down
6 changes: 3 additions & 3 deletions pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ func (h hypervisor) defaultMaxVCPUs() uint32 {
}

func (h hypervisor) defaultMemSz() uint32 {
if h.MemorySize < vc.MinHypervisorMemory {
return defaultMemSize // MiB
if h.MemorySize > 0 {
return h.MemorySize
}

return h.MemorySize
return defaultMemSize
}

func (h hypervisor) defaultMemSlots() uint32 {
Expand Down
8 changes: 8 additions & 0 deletions virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,14 @@ func (c *Container) update(resources specs.LinuxResources) error {
}
}

// There currently isn't a notion of cpusets.cpus or mems being tracked
// inside of the guest. Make sure we clear these before asking agent to update
// the container's cgroups.
if resources.CPU != nil {
resources.CPU.Mems = ""
resources.CPU.Cpus = ""
}

return c.sandbox.agent.updateContainer(c.sandbox, *c, resources)
}

Expand Down
3 changes: 0 additions & 3 deletions virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ const (
// Port where the agent will send the logs. Logs are sent through the vsock in cases
// where the hypervisor has no console.sock, i.e firecracker
vSockLogsPort = 1025

// MinHypervisorMemory is the minimum memory required for a VM.
MinHypervisorMemory = 256
)

// In some architectures the maximum number of vCPUs depends on the number of physical cores.
Expand Down
6 changes: 1 addition & 5 deletions virtcontainers/pkg/oci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,7 @@ func addHypervisorMemoryOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConfig
if value, ok := ocispec.Annotations[vcAnnotations.DefaultMemory]; ok {
memorySz, err := strconv.ParseUint(value, 10, 32)
if err != nil {
return fmt.Errorf("Error encountered parsing annotation for default_memory: %v, please specify positive numeric value greater than 8", err)
}

if memorySz < vc.MinHypervisorMemory {
return fmt.Errorf("Memory specified in annotation %s is less than minimum required %d, please specify a larger value", vcAnnotations.DefaultMemory, vc.MinHypervisorMemory)
return fmt.Errorf("Error encountered parsing annotation for default_memory: %v", err)
}

sbConfig.HypervisorConfig.MemorySize = uint32(memorySz)
Expand Down
1 change: 0 additions & 1 deletion virtcontainers/pkg/oci/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,6 @@ func TestAddHypervisorAnnotations(t *testing.T) {
assert.Error(err)

ocispec.Annotations[vcAnnotations.DefaultMaxVCPUs] = "1"
ocispec.Annotations[vcAnnotations.DefaultMemory] = fmt.Sprintf("%d", vc.MinHypervisorMemory+1)
assert.Error(err)
}

Expand Down
9 changes: 9 additions & 0 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,10 @@ func (s *Sandbox) CreateContainer(contConfig ContainerConfig) (VCContainer, erro
if len(s.config.Containers) > 0 {
// delete container config
s.config.Containers = s.config.Containers[:len(s.config.Containers)-1]
// need to flush change to persist storage
if newErr := s.storeSandbox(); newErr != nil {
s.Logger().WithError(newErr).Error("Fail to flush s.config.Containers change into sandbox store")
}
}
}
}()
Expand Down Expand Up @@ -1605,6 +1609,11 @@ func (s *Sandbox) Stop(force bool) error {
return err
}

// Stop communicating with the agent.
if err := s.agent.disconnect(); err != nil && !force {
return err
}

return nil
}

Expand Down

0 comments on commit 9a1aa02

Please sign in to comment.