diff --git a/pkg/server/container_create.go b/pkg/server/container_create.go index a35809756..80ff32bec 100644 --- a/pkg/server/container_create.go +++ b/pkg/server/container_create.go @@ -233,7 +233,7 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C func (c *criContainerdService) generateContainerSpec(id string, sandboxPid uint32, config *runtime.ContainerConfig, sandboxConfig *runtime.PodSandboxConfig, imageConfig *imagespec.ImageConfig, extraMounts []*runtime.Mount) (*runtimespec.Spec, error) { // Creates a spec Generator with the default spec. - spec, err := containerd.GenerateSpec(context.Background(), nil, nil) + spec, err := defaultRuntimeSpec() if err != nil { return nil, err } @@ -609,3 +609,23 @@ func setOCINamespaces(g *generate.Generator, namespaces *runtime.NamespaceOption g.RemoveLinuxNamespace(string(runtimespec.PIDNamespace)) // nolint: errcheck } } + +// defaultRuntimeSpec returns a default runtime spec used in cri-containerd. +func defaultRuntimeSpec() (*runtimespec.Spec, error) { + spec, err := containerd.GenerateSpec(context.Background(), nil, nil) + if err != nil { + return nil, err + } + + // Remove `/run` mount + // TODO(random-liu): Mount tmpfs for /run and handle copy-up. + var mounts []runtimespec.Mount + for _, mount := range spec.Mounts { + if mount.Destination == "/run" { + continue + } + mounts = append(mounts, mount) + } + spec.Mounts = mounts + return spec, nil +} diff --git a/pkg/server/container_create_test.go b/pkg/server/container_create_test.go index b685847ff..7d0addd30 100644 --- a/pkg/server/container_create_test.go +++ b/pkg/server/container_create_test.go @@ -555,3 +555,11 @@ func TestPidNamespace(t *testing.T) { Type: runtimespec.PIDNamespace, }) } + +func TestDefaultRuntimeSpec(t *testing.T) { + spec, err := defaultRuntimeSpec() + assert.NoError(t, err) + for _, mount := range spec.Mounts { + assert.NotEqual(t, "/run", mount.Destination) + } +} diff --git a/pkg/server/sandbox_run.go b/pkg/server/sandbox_run.go index 07000fc77..c36d15121 100644 --- a/pkg/server/sandbox_run.go +++ b/pkg/server/sandbox_run.go @@ -212,7 +212,7 @@ func (c *criContainerdService) generateSandboxContainerSpec(id string, config *r imageConfig *imagespec.ImageConfig, nsPath string) (*runtimespec.Spec, error) { // Creates a spec Generator with the default spec. // TODO(random-liu): [P1] Compare the default settings with docker and containerd default. - spec, err := containerd.GenerateSpec(context.Background(), nil, nil) + spec, err := defaultRuntimeSpec() if err != nil { return nil, err }