Skip to content
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

feature: support multiple containerd-shim #2363

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apis/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,11 @@ definitions:
items:
type: "string"
example: ["--debug", "--systemd-cgroup=false"]
shim:
description: |
shim name, pass to containerd to choose which shim is used for container.
type: "string"


Commit:
description: |
Expand Down Expand Up @@ -2421,6 +2426,10 @@ definitions:
Runtime:
type: "string"
description: "Runtime to use with this container."
Shim:
description: |
Shim name, pass to containerd to choose which shim is used for container.
type: "string"
# Applicable to Windows
ConsoleSize:
type: "array"
Expand Down
12 changes: 12 additions & 0 deletions apis/types/host_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions apis/types/runtime.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/common_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func addCommonFlags(flagSet *pflag.FlagSet) *container {
flagSet.BoolVar(&c.privileged, "privileged", false, "Give extended privileges to the container")

flagSet.StringVar(&c.restartPolicy, "restart", "", "Restart policy to apply when container exits")
flagSet.StringVar(&c.shim, "shim", "io.containerd.runtime.v1.linux", "containerd shim used for this container")
flagSet.StringVar(&c.runtime, "runtime", "", "OCI runtime to use for this container")

flagSet.StringSliceVar(&c.securityOpt, "security-opt", nil, "Security Options")
Expand Down
2 changes: 2 additions & 0 deletions cli/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type container struct {
tty bool
volume []string
volumesFrom []string
shim string
runtime string
env []string
entrypoint string
Expand Down Expand Up @@ -206,6 +207,7 @@ func (c *container) config() (*types.ContainerCreateConfig, error) {
Binds: c.volume,
VolumesFrom: c.volumesFrom,
Runtime: c.runtime,
Shim: c.shim,
Resources: types.Resources{
// cpu
CPUShares: c.cpushare,
Expand Down
3 changes: 1 addition & 2 deletions ctrd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"runtime"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -504,7 +503,7 @@ func (c *Client) createContainer(ctx context.Context, ref, id, checkpointDir str
// create container
options := []containerd.NewContainerOpts{
containerd.WithContainerLabels(container.Labels),
containerd.WithRuntime(fmt.Sprintf("io.containerd.runtime.v1.%s", runtime.GOOS), &runctypes.RuncOptions{
containerd.WithRuntime(container.Shim, &runctypes.RuncOptions{
Runtime: container.Runtime,
RuntimeRoot: runtimeRoot,
}),
Expand Down
6 changes: 5 additions & 1 deletion ctrd/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ import (
type Container struct {
ID string
Image string
Runtime string
Labels map[string]string
IO *containerio.IO
Spec *specs.Spec
SnapshotID string

// Shim is shim name, specify shim used for container
Shim string
// Runtime is runtime name, specify runtime used for container
Runtime string

// BaseFS is rootfs used by containerd container
BaseFS string

Expand Down
6 changes: 6 additions & 0 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,17 @@ func (mgr *ContainerManager) createContainerdContainer(ctx context.Context, c *C
return err
}

// shim always need for containerd.
if c.HostConfig.Shim == "" {
c.HostConfig.Shim = DefaultShim
}

c.Lock()
ctrdContainer := &ctrd.Container{
ID: c.ID,
Image: c.Config.Image,
Labels: c.Config.Labels,
Shim: c.HostConfig.Shim,
Runtime: runtime,
Spec: sw.s,
IO: mgr.IOs.Get(c.ID),
Expand Down
3 changes: 3 additions & 0 deletions daemon/mgr/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ var (

// ProfileUnconfined means run a container without the default seccomp profile.
ProfileUnconfined = "unconfined"

// DefaultShim is default shim used for container.
DefaultShim = "io.containerd.runtime.v1.linux"
)

var (
Expand Down