Skip to content
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
12 changes: 12 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ use_repo(
"com_github_containerd_cgroups",
"com_github_containerd_console",
"com_github_containerd_containerd",
"com_github_containerd_containerd_api",
"com_github_containerd_errdefs",
"com_github_containerd_fifo",
"com_github_containerd_go_runc",
"com_github_containerd_log",
"com_github_containerd_typeurl",
"com_github_containerd_typeurl_v2",
"com_github_coreos_go_systemd_v22",
"com_github_distribution_reference",
"com_github_docker_docker",
Expand Down Expand Up @@ -527,6 +529,11 @@ go_deps.module(
sum = "h1:Bcj0ZXqgIs6GG+YbaKkMX3Dap0JsIVG4UYFOLRo7iX4=",
version = "v1.6.36",
)
go_deps.module(
path = "github.com/containerd/containerd/api",
sum = "h1:HZ/licowTRazus+wt9fM6r/9BQO7S0vD5lMcWspGIg0=",
version = "v1.9.0",
)
go_deps.module(
path = "github.com/containerd/cgroups",
sum = "h1:iJnMvco9XGvKUvNQkv88bE4uJXxRQH18efbKo9w5vHQ=",
Expand All @@ -542,6 +549,11 @@ go_deps.module(
sum = "h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=",
version = "v0.1.0",
)
go_deps.module(
path = "github.com/containerd/typeurl/v2",
sum = "h1:yNA/94zxWdvYACdYO8zofhrTVuQY73fFU1y++dYSw40=",
version = "v2.2.3",
)
go_deps.module(
path = "github.com/googleapis/gnostic",
sum = "h1:9fHAtK0uDfpveeqqo1hkEZJcFvYXAiCN3UutL8F9xHw=",
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ require (
github.com/containerd/cgroups v1.0.4
github.com/containerd/console v1.0.3
github.com/containerd/containerd v1.6.36
github.com/containerd/containerd/api v1.9.0
github.com/containerd/errdefs v0.1.0
github.com/containerd/fifo v1.0.0
github.com/containerd/go-runc v1.0.0
github.com/containerd/log v0.1.0
github.com/containerd/typeurl v1.0.2
github.com/containerd/typeurl/v2 v2.2.3
github.com/coreos/go-systemd/v22 v22.6.0
github.com/godbus/dbus/v5 v5.1.0
github.com/gofrs/flock v0.8.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ github.com/containerd/containerd v1.5.1/go.mod h1:0DOxVqwDy2iZvrZp2JUx/E+hS0UNTV
github.com/containerd/containerd v1.5.7/go.mod h1:gyvv6+ugqY25TiXxcZC3L5yOeYgEw0QMhscqVp1AR9c=
github.com/containerd/containerd v1.6.36 h1:Bcj0ZXqgIs6GG+YbaKkMX3Dap0JsIVG4UYFOLRo7iX4=
github.com/containerd/containerd v1.6.36/go.mod h1:gSufNaPbqri6ifEQ3eihFSXoGwqTENkqB7j//aEgE0s=
github.com/containerd/containerd/api v1.9.0 h1:HZ/licowTRazus+wt9fM6r/9BQO7S0vD5lMcWspGIg0=
github.com/containerd/containerd/api v1.9.0/go.mod h1:GhghKFmTR3hNtyznBoQ0EMWr9ju5AqHjcZPsSpTKutI=
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20190815185530-f2a389ac0a02/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20191127005431-f65d91d395eb/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
Expand Down Expand Up @@ -206,6 +208,8 @@ github.com/containerd/typeurl v0.0.0-20190911142611-5eb25027c9fd/go.mod h1:GeKYz
github.com/containerd/typeurl v1.0.1/go.mod h1:TB1hUtrpaiO88KEK56ijojHS1+NeF0izUACaJW2mdXg=
github.com/containerd/typeurl v1.0.2 h1:Chlt8zIieDbzQFzXzAeBEF92KhExuE4p9p92/QmY7aY=
github.com/containerd/typeurl v1.0.2/go.mod h1:9trJWW2sRlGub4wZJRTW83VtbOLS6hwcDZXTn6oPz9s=
github.com/containerd/typeurl/v2 v2.2.3 h1:yNA/94zxWdvYACdYO8zofhrTVuQY73fFU1y++dYSw40=
github.com/containerd/typeurl/v2 v2.2.3/go.mod h1:95ljDnPfD3bAbDJRugOiShd/DlAAsxGtUBhJxIn7SCk=
github.com/containerd/zfs v0.0.0-20200918131355-0a33824f23a2/go.mod h1:8IgZOBdv8fAgXddBT4dBXJPtxyRsejFIpXoklgxgEjw=
github.com/containerd/zfs v0.0.0-20210301145711-11e8f1707f62/go.mod h1:A9zfAbMlQwE+/is6hi0Xw8ktpL+6glmqZYtevJgaB8Y=
github.com/containerd/zfs v0.0.0-20210315114300-dde8f0fda960/go.mod h1:m+m51S1DvAP6r3FcmYCp54bQ34pyOwTieQDNRIRHsFY=
Expand Down
3 changes: 1 addition & 2 deletions nogo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ global:
- "panic recovered: .*types/sizes.go:82: assertion failed"
exclude:
# Generated: exempt all.
- pkg/shim/v1/runtimeoptions/runtimeoptions_cri.go
- pkg/shim/v1/runtimeoptions/v14/runtimeoptions_cri.go
- pkg/shim/runtimeoptions/runtimeoptions_cri.go
analyzers:
asmdecl:
generated: # Enabled.
Expand Down
20 changes: 20 additions & 0 deletions pkg/shim/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("//tools:defs.bzl", "go_library")

package(
default_applicable_licenses = ["//:license"],
default_visibility = [":users"],
licenses = ["notice"],
)

package_group(
name = "users",
packages = [
"//...",
"//cloud/kubernetes/node/snapshot/...",
],
)

go_library(
name = "shim",
srcs = ["shim.go"],
)
25 changes: 25 additions & 0 deletions pkg/shim/runtimeoptions/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("//tools:defs.bzl", "go_library", "proto_library")

package(
default_applicable_licenses = ["//:license"],
licenses = ["notice"],
)

proto_library(
name = "api",
srcs = [
"runtimeoptions.proto",
],
)

go_library(
name = "runtimeoptions",
srcs = [
"runtimeoptions.go",
"runtimeoptions_cri.go",
],
visibility = [
"//pkg/shim:__subpackages__",
],
deps = ["@com_github_gogo_protobuf//proto:go_default_library"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

syntax = "proto3";

package runtimeoptions.v1;
package runtimeoptions;

// This is a version of the runtimeoptions CRI API that is vendored.
// Source: cri/pkg/api/runtimeoptions/v1/api.proto
Expand Down
19 changes: 11 additions & 8 deletions ...m/v1/runtimeoptions/v14/runtimeoptions.go → pkg/shim/shim.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
// Copyright 2018 The containerd Authors.
// Copyright 2018 The gVisor Authors.
// Copyright 2025 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package v14 contains the runtimeoptions proto for containerd 1.4 and earlier.
// The package for runtimeoptions proto changed from "cri.runtimeoptions.v1" to
// "runtimeoptions.v1" in 1.5, So keep both versions until 1.4 doesn't need to
// be supported anymore.
package v14
// Package shim provides shared libraries for the gVisor shim.
package shim

// RestoreConfig is the configuration for a restore request.
type RestoreConfig struct {
ImagePath string
Direct bool
Background bool
}
1 change: 1 addition & 0 deletions pkg/shim/v1/extension/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ go_library(
srcs = ["extension.go"],
visibility = ["//visibility:public"],
deps = [
"//pkg/shim",
"@com_github_containerd_containerd//pkg/process:go_default_library",
"@com_github_containerd_containerd//runtime/v2/task:go_default_library",
],
Expand Down
12 changes: 3 additions & 9 deletions pkg/shim/v1/extension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/containerd/containerd/pkg/process"
"github.com/containerd/containerd/runtime/v2/task"
"gvisor.dev/gvisor/pkg/shim"
)

// NewExtension registers an extension constructor. It may return nil, nil to indicate that the
Expand All @@ -30,21 +31,14 @@ var NewExtension func(ctx context.Context, next TaskServiceExt, req *task.Create
// task.StartRequest with restore functionality.
type RestoreRequest struct {
Start task.StartRequest
Conf RestoreConfig
Conf shim.RestoreConfig
}

// Process extends process.Process with extra restore functionality.
type Process interface {
process.Process
// Restore restores the container from a snapshot.
Restore(context.Context, *RestoreConfig) error
}

// RestoreConfig is the configuration for a restore request.
type RestoreConfig struct {
ImagePath string
Direct bool
Background bool
Restore(context.Context, *shim.RestoreConfig) error
}

// TaskServiceExt extends TaskRequest with extra functionality required by the shim.
Expand Down
1 change: 1 addition & 0 deletions pkg/shim/v1/proc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ go_library(
deps = [
"//pkg/atomicbitops",
"//pkg/cleanup",
"//pkg/shim",
"//pkg/shim/v1/extension",
"//pkg/shim/v1/runsccmd",
"//pkg/shim/v1/utils",
Expand Down
3 changes: 2 additions & 1 deletion pkg/shim/v1/proc/deleted_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/containerd/console"
"github.com/containerd/errdefs"
runc "github.com/containerd/go-runc"
"gvisor.dev/gvisor/pkg/shim"
"gvisor.dev/gvisor/pkg/shim/v1/extension"
)

Expand All @@ -31,7 +32,7 @@ func (*deletedState) Resize(console.WinSize) error {
return fmt.Errorf("cannot resize a deleted container/process")
}

func (*deletedState) Start(context.Context, *extension.RestoreConfig) error {
func (*deletedState) Start(context.Context, *shim.RestoreConfig) error {
return fmt.Errorf("cannot start a deleted container/process")
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/shim/v1/proc/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
specs "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/cleanup"
"gvisor.dev/gvisor/pkg/shim/v1/extension"
"gvisor.dev/gvisor/pkg/shim"
"gvisor.dev/gvisor/pkg/shim/v1/runsccmd"
)

Expand Down Expand Up @@ -276,7 +276,7 @@ func (e *execProcess) start(ctx context.Context) error {
return nil
}

func (e *execProcess) Restore(context.Context, *extension.RestoreConfig) error {
func (e *execProcess) Restore(context.Context, *shim.RestoreConfig) error {
return fmt.Errorf("cannot restore an exec'd process")
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/shim/v1/proc/exec_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"fmt"

"github.com/containerd/console"
"gvisor.dev/gvisor/pkg/shim/v1/extension"
"gvisor.dev/gvisor/pkg/shim"
)

type execState interface {
Resize(console.WinSize) error
Start(context.Context, *extension.RestoreConfig) error
Start(context.Context, *shim.RestoreConfig) error
Delete(context.Context) error
Kill(context.Context, uint32, bool) error
SetExited(int)
Expand Down Expand Up @@ -56,7 +56,7 @@ func (s *execCreatedState) Resize(ws console.WinSize) error {
return s.p.resize(ws)
}

func (s *execCreatedState) Start(ctx context.Context, restoreConf *extension.RestoreConfig) error {
func (s *execCreatedState) Start(ctx context.Context, restoreConf *shim.RestoreConfig) error {
if restoreConf != nil {
return fmt.Errorf("cannot restore an exec'd process")
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func (s *execRunningState) Resize(ws console.WinSize) error {
return s.p.resize(ws)
}

func (s *execRunningState) Start(context.Context, *extension.RestoreConfig) error {
func (s *execRunningState) Start(context.Context, *shim.RestoreConfig) error {
return fmt.Errorf("cannot start a running process")
}

Expand Down Expand Up @@ -141,7 +141,7 @@ func (s *execStoppedState) Resize(console.WinSize) error {
return fmt.Errorf("cannot resize a stopped container")
}

func (s *execStoppedState) Start(context.Context, *extension.RestoreConfig) error {
func (s *execStoppedState) Start(context.Context, *shim.RestoreConfig) error {
return fmt.Errorf("cannot start a stopped process")
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/shim/v1/proc/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
runc "github.com/containerd/go-runc"
specs "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/shim"
"gvisor.dev/gvisor/pkg/shim/v1/extension"
"gvisor.dev/gvisor/pkg/shim/v1/runsccmd"
"gvisor.dev/gvisor/pkg/shim/v1/utils"
Expand Down Expand Up @@ -229,7 +230,7 @@ func (p *Init) Start(ctx context.Context) error {
return p.initState.Start(ctx, nil /* restoreConf */)
}

func (p *Init) start(ctx context.Context, restoreConf *extension.RestoreConfig) error {
func (p *Init) start(ctx context.Context, restoreConf *shim.RestoreConfig) error {
var cio runc.IO
if !p.Sandbox {
cio = p.io
Expand Down Expand Up @@ -265,7 +266,7 @@ func (p *Init) start(ctx context.Context, restoreConf *extension.RestoreConfig)
}

// Restore restores the container from a snapshot.
func (p *Init) Restore(ctx context.Context, conf *extension.RestoreConfig) error {
func (p *Init) Restore(ctx context.Context, conf *shim.RestoreConfig) error {
p.mu.Lock()
defer p.mu.Unlock()

Expand Down
9 changes: 5 additions & 4 deletions pkg/shim/v1/proc/init_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
runc "github.com/containerd/go-runc"
"golang.org/x/sys/unix"

"gvisor.dev/gvisor/pkg/shim"
"gvisor.dev/gvisor/pkg/shim/v1/extension"
)

Expand Down Expand Up @@ -50,7 +51,7 @@ func (s stateTransition) String() string {
type initState interface {
// Start starts the process. If RestoreConfig is provided, the process is
// restored using the checkpoint image provided in the config.
Start(context.Context, *extension.RestoreConfig) error
Start(context.Context, *shim.RestoreConfig) error
Delete(context.Context) error
Exec(context.Context, string, *ExecConfig) (extension.Process, error)
State(ctx context.Context) (string, error)
Expand Down Expand Up @@ -80,7 +81,7 @@ func (s *createdState) transition(transition stateTransition) {
}
}

func (s *createdState) Start(ctx context.Context, restoreConf *extension.RestoreConfig) error {
func (s *createdState) Start(ctx context.Context, restoreConf *shim.RestoreConfig) error {
if err := s.p.start(ctx, restoreConf); err != nil {
// Containerd doesn't allow deleting container in created state.
// However, for gVisor, a non-root container in created state can
Expand Down Expand Up @@ -149,7 +150,7 @@ func (s *runningState) transition(transition stateTransition) {
}
}

func (s *runningState) Start(context.Context, *extension.RestoreConfig) error {
func (s *runningState) Start(context.Context, *shim.RestoreConfig) error {
return fmt.Errorf("cannot start a running container")
}

Expand Down Expand Up @@ -199,7 +200,7 @@ func (s *stoppedState) transition(transition stateTransition) {
}
}

func (s *stoppedState) Start(context.Context, *extension.RestoreConfig) error {
func (s *stoppedState) Start(context.Context, *shim.RestoreConfig) error {
return fmt.Errorf("cannot start a stopped container")
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/shim/v1/runsc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ go_library(
visibility = ["//pkg/shim:__subpackages__"],
deps = [
"//pkg/cleanup",
"//pkg/shim/runtimeoptions",
"//pkg/shim/v1/extension",
"//pkg/shim/v1/proc",
"//pkg/shim/v1/runsccmd",
"//pkg/shim/v1/runtimeoptions",
"//pkg/shim/v1/runtimeoptions/v14",
"//pkg/shim/v1/utils",
"//runsc/specutils",
"@com_github_burntsushi_toml//:go_default_library",
Expand Down
Loading
Loading