Integrate runsc shim with containerd 2.1.

PiperOrigin-RevId: 916119129
This commit is contained in:
Jing Chen
2026-05-15 12:06:54 -07:00
committed by gVisor bot
parent 100be8fd1d
commit 09ecb96788
27 changed files with 638 additions and 1343 deletions
+138 -28
View File
@@ -142,29 +142,40 @@ use_repo(
"com_github_burntsushi_toml",
"com_github_cenkalti_backoff",
"com_github_cilium_ebpf",
"com_github_containerd_cgroups",
"com_github_containerd_cgroups_v3",
"com_github_containerd_console",
"com_github_containerd_containerd",
"com_github_containerd_containerd_api",
"com_github_containerd_containerd_v2",
"com_github_containerd_continuity",
"com_github_containerd_errdefs",
"com_github_containerd_errdefs_pkg",
"com_github_containerd_fifo",
"com_github_containerd_go_runc",
"com_github_containerd_log",
"com_github_containerd_plugin",
"com_github_containerd_ttrpc",
"com_github_containerd_typeurl",
"com_github_containerd_typeurl_v2",
"com_github_coreos_go_systemd_v22",
"com_github_creack_pty",
"com_github_distribution_reference",
"com_github_docker_docker",
"com_github_docker_go_connections",
"com_github_docker_go_units",
"com_github_emicklei_go_restful_v3",
"com_github_felixge_httpsnoop",
"com_github_fxamacker_cbor_v2",
"com_github_go_echarts_go_echarts_v2",
"com_github_go_logr_logr",
"com_github_go_logr_stdr",
"com_github_go_openapi_jsonpointer",
"com_github_go_openapi_jsonreference",
"com_github_go_openapi_swag",
"com_github_godbus_dbus_v5",
"com_github_gofrs_flock",
"com_github_gogo_protobuf",
"com_github_golang_protobuf",
"com_github_google_btree",
"com_github_google_gnostic_models",
"com_github_google_go_cmp",
"com_github_google_go_github_v56",
"com_github_google_go_querystring",
@@ -179,11 +190,21 @@ use_repo(
"com_github_hanwen_go_fuse_v2",
"com_github_ianlancetaylor_demangle",
"com_github_imdario_mergo",
"com_github_josharian_intern",
"com_github_mailru_easyjson",
"com_github_mattbaird_jsonpatch",
"com_github_matttproud_golang_protobuf_extensions",
"com_github_mdlayher_socket",
"com_github_mdlayher_vsock",
"com_github_moby_docker_image_spec",
"com_github_moby_sys_capability",
"com_github_moby_sys_sequential",
"com_github_moby_sys_signal",
"com_github_moby_sys_symlink",
"com_github_moby_sys_user",
"com_github_moby_sys_userns",
"com_github_mohae_deepcopy",
"com_github_munnerz_goautoneg",
"com_github_opencontainers_image_spec",
"com_github_opencontainers_runtime_spec",
"com_github_prometheus_client_model",
@@ -191,6 +212,7 @@ use_repo(
"com_github_sirupsen_logrus",
"com_github_spf13_pflag",
"com_github_vishvananda_netlink",
"com_github_x448_float16",
"com_github_xeipuuv_gojsonpointer",
"com_github_xeipuuv_gojsonreference",
"com_github_xeipuuv_gojsonschema",
@@ -202,6 +224,7 @@ use_repo(
"com_google_cloud_go_container",
"com_google_cloud_go_iam",
"com_google_cloud_go_storage",
"in_gopkg_evanphx_json_patch_v4",
"in_gopkg_yaml_v2",
"in_gopkg_yaml_v3",
"io_k8s_api",
@@ -225,9 +248,11 @@ use_repo(
"org_golang_x_oauth2",
"org_golang_x_sync",
"org_golang_x_sys",
"org_golang_x_telemetry",
"org_golang_x_term",
"org_golang_x_time",
"org_golang_x_tools",
"org_golang_x_xerrors",
"org_uber_go_atomic",
"org_uber_go_multierr",
)
@@ -404,8 +429,8 @@ go_deps.module(
)
go_deps.module(
path = "github.com/google/uuid",
sum = "h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=",
version = "v1.3.0",
sum = "h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=",
version = "v1.6.0",
)
go_deps.module(
path = "github.com/googleapis/enterprise-certificate-proxy",
@@ -527,21 +552,6 @@ go_deps.module(
sum = "h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=",
version = "v1.0.1",
)
go_deps.module(
path = "github.com/containerd/containerd",
sum = "h1:Bcj0ZXqgIs6GG+YbaKkMX3Dap0JsIVG4UYFOLRo7iX4=",
version = "v1.6.36",
)
go_deps.module(
path = "github.com/containerd/cgroups",
sum = "h1:iJnMvco9XGvKUvNQkv88bE4uJXxRQH18efbKo9w5vHQ=",
version = "v1.0.1",
)
go_deps.module(
path = "github.com/containerd/errdefs",
sum = "h1:m0wCRBiu1WJT/Fr+iOoQHMQS/eP5myQ8lCv4Dz5ZURM=",
version = "v0.1.0",
)
go_deps.module(
path = "github.com/containerd/log",
sum = "h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=",
@@ -553,14 +563,114 @@ go_deps.module(
version = "v0.5.5",
)
go_deps.module(
path = "k8s.io/api",
sum = "h1:op+yeqZLQxDt2tEnrOP9Y+WA7l4Lxh+7R0IWEzyuk2I=",
version = "v0.23.16",
path = "github.com/fxamacker/cbor/v2",
sum = "h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=",
version = "v2.7.0",
)
go_deps.module(
path = "k8s.io/apimachinery",
sum = "h1:f6Q+3qYv3qWvbDZp2iUhwC2rzMRBkSb7JYBhmeVK5pc=",
version = "v0.23.16",
path = "github.com/x448/float16",
sum = "h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=",
version = "v0.8.4",
)
go_deps.module(
path = "github.com/moby/sys/userns",
sum = "h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g=",
version = "v0.1.0",
)
go_deps.module(
path = "github.com/docker/go-units",
sum = "h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=",
version = "v0.5.0",
)
go_deps.module(
path = "github.com/mdlayher/vsock",
sum = "h1:pC1mTJTvjo1r9n9fbm7S1j04rCgCzhCOS5DY0zqHlnQ=",
version = "v1.2.1",
)
go_deps.module(
path = "github.com/mdlayher/socket",
sum = "h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos=",
version = "v0.5.1",
)
go_deps.module(
path = "github.com/containerd/continuity",
sum = "h1:ZRoN1sXq9u7V6QoHMcVWGhOwDFqZ4B9i5H6un1Wh0x4=",
version = "v0.4.5",
)
go_deps.module(
path = "github.com/moby/sys/user",
sum = "h1:jhcMKit7SA80hivmFJcbB1vqmw//wU61Zdui2eQXuMs=",
version = "v0.4.0",
)
go_deps.module(
path = "github.com/moby/sys/sequential",
sum = "h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU=",
version = "v0.6.0",
)
go_deps.module(
path = "github.com/moby/sys/signal",
sum = "h1:PrQxdvxcGijdo6UXXo/lU/TvHUWyPhj7UOpSo8tuvk0=",
version = "v0.7.1",
)
go_deps.module(
path = "github.com/moby/sys/symlink",
sum = "h1:GZX89mEZ9u53f97npBy4Rc3vJKj7JBDj/PN2I22GrNU=",
version = "v0.3.0",
)
go_deps.module(
path = "github.com/munnerz/goautoneg",
sum = "h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=",
version = "v0.0.0-20191010083416-a7dc8b61c822",
)
go_deps.module(
path = "github.com/google/gnostic-models",
sum = "h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=",
version = "v0.6.8",
)
go_deps.module(
path = "gopkg.in/evanphx/json-patch.v4",
sum = "h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4=",
version = "v4.12.0",
)
go_deps.module(
path = "github.com/go-openapi/jsonreference",
sum = "h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE=",
version = "v0.20.2",
)
go_deps.module(
path = "github.com/go-openapi/jsonpointer",
sum = "h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=",
version = "v0.21.0",
)
go_deps.module(
path = "github.com/go-openapi/swag",
sum = "h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=",
version = "v0.23.0",
)
go_deps.module(
path = "github.com/emicklei/go-restful/v3",
sum = "h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=",
version = "v3.11.0",
)
go_deps.module(
path = "github.com/mailru/easyjson",
sum = "h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=",
version = "v0.7.7",
)
go_deps.module(
path = "github.com/josharian/intern",
sum = "h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=",
version = "v1.0.0",
)
go_deps.module(
path = "golang.org/x/telemetry",
sum = "h1:dHQOQddU4YHS5gY33/6klKjq7Gp3WwMyOXGNp5nzRj8=",
version = "v0.0.0-20250908211612-aef8a434d053",
)
go_deps.module(
path = "golang.org/x/xerrors",
sum = "h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=",
version = "v0.0.0-20220907171357-04be3eba64a2",
)
go_deps.gazelle_override(
directives = [
@@ -572,13 +682,13 @@ go_deps.gazelle_override(
directives = [
"gazelle:proto disable",
],
path = "github.com/containerd/containerd",
path = "github.com/containerd/containerd/v2",
)
go_deps.gazelle_override(
directives = [
"gazelle:proto disable",
],
path = "github.com/containerd/cgroups",
path = "github.com/containerd/cgroups/v3",
)
go_deps.gazelle_override(
directives = [
+48 -39
View File
@@ -7,17 +7,20 @@ require (
cloud.google.com/go/auth/oauth2adapt v0.2.8
cloud.google.com/go/storage v1.62.1
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c
github.com/bazelbuild/rules_go v0.44.2
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cilium/ebpf v0.12.3
github.com/containerd/cgroups v1.0.4
github.com/containerd/console v1.0.3
github.com/containerd/containerd v1.6.36
github.com/containerd/errdefs v0.1.0
github.com/containerd/fifo v1.0.0
github.com/containerd/go-runc v1.0.0
github.com/cilium/ebpf v0.16.0
github.com/containerd/cgroups/v3 v3.0.5
github.com/containerd/console v1.0.4
github.com/containerd/containerd/api v1.10.0
github.com/containerd/containerd/v2 v2.1.5
github.com/containerd/errdefs v1.0.0
github.com/containerd/errdefs/pkg v0.3.0
github.com/containerd/fifo v1.1.0
github.com/containerd/go-runc v1.1.0
github.com/containerd/log v0.1.0
github.com/containerd/typeurl v1.0.2
github.com/containerd/plugin v1.0.0
github.com/containerd/ttrpc v1.2.7
github.com/containerd/typeurl/v2 v2.2.3
github.com/coreos/go-systemd/v22 v22.6.0
github.com/creack/pty v1.1.24
github.com/godbus/dbus/v5 v5.1.0
@@ -30,18 +33,19 @@ require (
github.com/mohae/deepcopy v0.0.0-20170308212314-bb9b5e7adda9
github.com/opencontainers/runtime-spec v1.2.1
github.com/sirupsen/logrus v1.9.3
github.com/vishvananda/netlink v1.1.1-0.20211118161826-650dca95af54
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
github.com/vishvananda/netlink v1.3.1-0.20250303224720-0e7078ed04c8
golang.org/x/exp v0.0.0-20250711185948-6ae5c78190dc
golang.org/x/mod v0.34.0
golang.org/x/sync v0.20.0
golang.org/x/sys v0.43.0
golang.org/x/time v0.15.0
golang.org/x/tools v0.43.0
google.golang.org/api v0.274.0
google.golang.org/grpc v1.80.0
google.golang.org/protobuf v1.36.11
k8s.io/api v0.23.16
k8s.io/apimachinery v0.23.16
k8s.io/client-go v0.23.16
k8s.io/api v0.32.3
k8s.io/apimachinery v0.32.3
k8s.io/client-go v0.32.3
)
require (
@@ -54,41 +58,49 @@ require (
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.55.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.55.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.9.12 // indirect
github.com/Microsoft/hcsshim v0.13.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5 // indirect
github.com/containerd/ttrpc v1.1.2 // indirect
github.com/containerd/continuity v0.4.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/envoyproxy/go-control-plane v0.14.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/envoyproxy/go-control-plane/envoy v1.36.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.3.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-jose/go-jose/v4 v4.1.4 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/s2a-go v0.1.9 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.15 // indirect
github.com/googleapis/gax-go/v2 v2.22.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.14 // indirect
github.com/googleapis/gax-go/v2 v2.21.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/moby/sys/mountinfo v0.6.2 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mdlayher/socket v0.5.1 // indirect
github.com/mdlayher/vsock v1.2.1 // indirect
github.com/moby/sys/mountinfo v0.7.2 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/spiffe/go-spiffe/v2 v2.6.0 // indirect
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect
github.com/vishvananda/netns v0.0.5 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.39.0 // indirect
@@ -99,24 +111,21 @@ require (
go.opentelemetry.io/otel/sdk v1.43.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.43.0 // indirect
go.opentelemetry.io/otel/trace v1.43.0 // indirect
golang.org/x/crypto v0.50.0 // indirect
golang.org/x/crypto v0.49.0 // indirect
golang.org/x/net v0.52.0 // indirect
golang.org/x/oauth2 v0.36.0 // indirect
golang.org/x/telemetry v0.0.0-20260311193753-579e4da9a98c // indirect
golang.org/x/term v0.42.0 // indirect
golang.org/x/text v0.36.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4 // indirect
google.golang.org/grpc v1.80.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
+149 -1030
View File
File diff suppressed because it is too large Load Diff
+9 -8
View File
@@ -24,16 +24,17 @@ go_library(
"//pkg/shim/v1/runsccmd",
"//pkg/sync",
"@com_github_burntsushi_toml//:go_default_library",
"@com_github_containerd_containerd//mount:go_default_library",
"@com_github_containerd_containerd//namespaces:go_default_library",
"@com_github_containerd_containerd//pkg/shutdown:go_default_library",
"@com_github_containerd_containerd//runtime/v2/shim:go_default_library",
"@com_github_containerd_containerd//runtime/v2/task:go_default_library",
"@com_github_containerd_containerd//sys:go_default_library",
"@com_github_containerd_errdefs//:go_default_library",
"@com_github_containerd_containerd_api//runtime/task/v2:go_default_library",
"@com_github_containerd_containerd_api//types:go_default_library",
"@com_github_containerd_containerd_v2//core/mount:go_default_library",
"@com_github_containerd_containerd_v2//pkg/namespaces:go_default_library",
"@com_github_containerd_containerd_v2//pkg/protobuf/types:go_default_library",
"@com_github_containerd_containerd_v2//pkg/shim:go_default_library",
"@com_github_containerd_containerd_v2//pkg/shutdown:go_default_library",
"@com_github_containerd_containerd_v2//pkg/sys:go_default_library",
"@com_github_containerd_errdefs_pkg//errgrpc:go_default_library",
"@com_github_containerd_log//:go_default_library",
"@com_github_containerd_ttrpc//:go_default_library",
"@com_github_gogo_protobuf//types:go_default_library",
"@org_golang_x_sys//unix:go_default_library",
],
)
+3 -2
View File
@@ -11,7 +11,8 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/shim/v1/runsc:hibernate_go_proto",
"@com_github_containerd_containerd//pkg/process:go_default_library",
"@com_github_containerd_containerd//runtime/v2/task:go_default_library",
"@com_github_containerd_console//:go_default_library",
"@com_github_containerd_containerd_api//runtime/task/v2:go_default_library",
"@com_github_containerd_containerd_v2//pkg/stdio:go_default_library",
],
)
+32 -4
View File
@@ -17,9 +17,12 @@ package extension
import (
"context"
"io"
"time"
"github.com/containerd/containerd/pkg/process"
"github.com/containerd/containerd/runtime/v2/task"
"github.com/containerd/console"
task "github.com/containerd/containerd/api/runtime/task/v2"
"github.com/containerd/containerd/v2/pkg/stdio"
hibernatepb "gvisor.dev/gvisor/pkg/shim/v1/runsc/hibernate_go_proto"
)
@@ -45,9 +48,34 @@ type RestoreConfig struct {
Background bool
}
// Process extends process.Process with extra restore functionality.
// Process is the interface representing a process inside the container.
type Process interface {
process.Process
// ID returns the id for the process
ID() string
// Pid returns the pid for the process
Pid() int
// ExitStatus returns the exit status
ExitStatus() int
// ExitedAt is the time the process exited
ExitedAt() time.Time
// Stdin returns the process STDIN
Stdin() io.Closer
// Stdio returns io information for the container
Stdio() stdio.Stdio
// Status returns the process status
Status(context.Context) (string, error)
// Wait blocks until the process has exited
Wait()
// Resize resizes the process console
Resize(ws console.WinSize) error
// Start execution of the process
Start(context.Context) error
// Delete deletes the process and its resources
Delete(context.Context) error
// Kill kills the process
Kill(context.Context, uint32, bool) error
// SetExited sets the exit status for the process
SetExited(status int)
// Restore restores the container from a snapshot.
Restore(context.Context, *RestoreConfig) error
}
+43 -28
View File
@@ -22,11 +22,14 @@ import (
"os/exec"
"time"
"io"
"github.com/BurntSushi/toml"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/runtime/v2/shim"
"github.com/containerd/containerd/sys"
types "github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/v2/core/mount"
"github.com/containerd/containerd/v2/pkg/namespaces"
"github.com/containerd/containerd/v2/pkg/shim"
"github.com/containerd/containerd/v2/pkg/sys"
"github.com/containerd/log"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/cleanup"
@@ -54,7 +57,7 @@ type manager struct {
var _ shim.Manager = (*manager)(nil)
func newCommand(ctx context.Context, id, containerdBinary, containerdAddress string, debug bool) (*exec.Cmd, error) {
func newCommand(ctx context.Context, id, containerdAddress string, debug bool) (*exec.Cmd, error) {
ns, err := namespaces.NamespaceRequired(ctx)
if err != nil {
return nil, err
@@ -71,7 +74,6 @@ func newCommand(ctx context.Context, id, containerdBinary, containerdAddress str
"-namespace", ns,
"-address", containerdAddress,
"-id", id,
"-publish-binary", containerdBinary,
}
if debug {
args = append(args, "-debug")
@@ -90,19 +92,19 @@ func (m manager) Name() string {
}
// Start implements shim.Manager.Start.
func (m *manager) Start(ctx context.Context, id string, opts shim.StartOpts) (string, error) {
func (m *manager) Start(ctx context.Context, id string, opts shim.StartOpts) (shim.BootstrapParams, error) {
grouping := id
enableGrouping := getEnableGrouping()
if enableGrouping {
// The config.json is always at the current directory by containerd.
configFile, err := os.Open("config.json")
if err != nil {
return "", fmt.Errorf("failed to read config.json when starting shim: %w", err)
return shim.BootstrapParams{}, fmt.Errorf("failed to read config.json when starting shim: %w", err)
}
var readSpec spec
if err := json.NewDecoder(configFile).Decode(&readSpec); err != nil {
configFile.Close()
return "", err
return shim.BootstrapParams{}, err
}
configFile.Close()
if groupID, ok := readSpec.Annotations[kubernetesGroupAnnotation]; ok {
@@ -111,14 +113,14 @@ func (m *manager) Start(ctx context.Context, id string, opts shim.StartOpts) (st
}
}
cmd, err := newCommand(ctx, id, opts.ContainerdBinary, opts.Address, opts.Debug)
cmd, err := newCommand(ctx, id, opts.Address, opts.Debug)
if err != nil {
return "", err
return shim.BootstrapParams{}, err
}
address, err := shim.SocketAddress(ctx, opts.Address, grouping)
address, err := shim.SocketAddress(ctx, opts.Address, grouping, opts.Debug)
if err != nil {
return "", err
return shim.BootstrapParams{}, err
}
socket, err := shim.NewSocket(address)
if err != nil {
@@ -127,19 +129,19 @@ func (m *manager) Start(ctx context.Context, id string, opts shim.StartOpts) (st
// grouping functionality where the new process should be run with the same
// shim as an existing container.
if !shim.SocketEaddrinuse(err) {
return "", fmt.Errorf("create new shim socket: %w", err)
return shim.BootstrapParams{}, fmt.Errorf("create new shim socket: %w", err)
}
if shim.CanConnect(address) {
if err := shim.WriteAddress("address", address); err != nil {
return "", fmt.Errorf("write existing socket for shim: %w", err)
if err := writeAddress("address", address); err != nil {
return shim.BootstrapParams{}, fmt.Errorf("write existing socket for shim: %w", err)
}
return address, nil
return shim.BootstrapParams{Version: 2, Address: address, Protocol: "ttrpc"}, nil
}
if err := shim.RemoveSocket(address); err != nil {
return "", fmt.Errorf("remove pre-existing socket: %w", err)
return shim.BootstrapParams{}, fmt.Errorf("remove pre-existing socket: %w", err)
}
if socket, err = shim.NewSocket(address); err != nil {
return "", fmt.Errorf("try create new shim socket 2x: %w", err)
return shim.BootstrapParams{}, fmt.Errorf("try create new shim socket 2x: %w", err)
}
}
cu := cleanup.Make(func() {
@@ -149,20 +151,20 @@ func (m *manager) Start(ctx context.Context, id string, opts shim.StartOpts) (st
defer cu.Clean()
// make sure that reexec shim binary use the value if need.
if err := shim.WriteAddress("address", address); err != nil {
return "", err
if err := writeAddress("address", address); err != nil {
return shim.BootstrapParams{}, err
}
f, err := socket.File()
if err != nil {
return "", err
return shim.BootstrapParams{}, err
}
cmd.ExtraFiles = append(cmd.ExtraFiles, f)
if err := cmd.Start(); err != nil {
f.Close()
return "", err
return shim.BootstrapParams{}, err
}
cu.Add(func() {
@@ -172,16 +174,16 @@ func (m *manager) Start(ctx context.Context, id string, opts shim.StartOpts) (st
// make sure to wait after start
go cmd.Wait()
if err := shim.WritePidFile("shim.pid", cmd.Process.Pid); err != nil {
return "", err
return shim.BootstrapParams{}, err
}
if err := shim.WriteAddress(shimAddressPath, address); err != nil {
return "", err
if err := writeAddress(shimAddressPath, address); err != nil {
return shim.BootstrapParams{}, err
}
if err := sys.SetOOMScore(cmd.Process.Pid, oomScoreMax); err != nil {
return "", fmt.Errorf("failed to set OOM Score on shim: %w", err)
return shim.BootstrapParams{}, fmt.Errorf("failed to set OOM Score on shim: %w", err)
}
cu.Release()
return address, nil
return shim.BootstrapParams{Version: 2, Address: address, Protocol: "ttrpc"}, nil
}
// Stop implements shim.Manager.Stop.
@@ -245,3 +247,16 @@ func getEnableGrouping() bool {
}
return opts.Grouping
}
func (m *manager) Info(ctx context.Context, optionsR io.Reader) (*types.RuntimeInfo, error) {
return &types.RuntimeInfo{
Name: "io.containerd.runsc.v1",
Version: &types.RuntimeVersion{
Version: "v1.0.0",
},
}, nil
}
func writeAddress(path, address string) error {
return os.WriteFile(path, []byte(address), 0o644)
}
+5 -3
View File
@@ -11,8 +11,10 @@ go_library(
visibility = ["//shim:__subpackages__"],
deps = [
"//pkg/shim/v1", # keep
"@com_github_containerd_containerd//pkg/shutdown:go_default_library",
"@com_github_containerd_containerd//plugin:go_default_library",
"@com_github_containerd_containerd//runtime/v2/shim:go_default_library",
"@com_github_containerd_containerd_v2//pkg/shim:go_default_library",
"@com_github_containerd_containerd_v2//pkg/shutdown:go_default_library",
"@com_github_containerd_containerd_v2//plugins:go_default_library",
"@com_github_containerd_plugin//:go_default_library",
"@com_github_containerd_plugin//registry:go_default_library",
],
)
+11 -9
View File
@@ -19,26 +19,28 @@
package plugin
import (
"github.com/containerd/containerd/pkg/shutdown"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/runtime/v2/shim"
"github.com/containerd/containerd/v2/pkg/shim"
"github.com/containerd/containerd/v2/pkg/shutdown"
"github.com/containerd/containerd/v2/plugins"
"github.com/containerd/plugin"
"github.com/containerd/plugin/registry"
"gvisor.dev/gvisor/pkg/shim/v1"
)
func init() {
plugin.Register(&plugin.Registration{
Type: plugin.TTRPCPlugin,
registry.Register(&plugin.Registration{
Type: plugins.TTRPCPlugin,
ID: "task",
Requires: []plugin.Type{
plugin.EventPlugin,
plugin.InternalPlugin,
plugins.EventPlugin,
plugins.InternalPlugin,
},
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
pp, err := ic.GetByID(plugin.EventPlugin, "publisher")
pp, err := ic.GetByID(plugins.EventPlugin, "publisher")
if err != nil {
return nil, err
}
ss, err := ic.GetByID(plugin.InternalPlugin, "shutdown")
ss, err := ic.GetByID(plugins.InternalPlugin, "shutdown")
if err != nil {
return nil, err
}
+6 -5
View File
@@ -29,13 +29,14 @@ go_library(
"//pkg/shim/v1/runsccmd",
"//pkg/shim/v1/utils",
"@com_github_containerd_console//:go_default_library",
"@com_github_containerd_containerd//mount:go_default_library",
"@com_github_containerd_containerd//pkg/stdio:go_default_library",
"@com_github_containerd_containerd_v2//core/mount:go_default_library",
"@com_github_containerd_containerd_v2//pkg/protobuf/types:go_default_library",
"@com_github_containerd_containerd_v2//pkg/stdio:go_default_library",
"@com_github_containerd_errdefs//:go_default_library",
"@com_github_containerd_errdefs_pkg//errgrpc:go_default_library",
"@com_github_containerd_fifo//:go_default_library",
"@com_github_containerd_go_runc//:go_default_library",
"@com_github_containerd_log//:go_default_library",
"@com_github_gogo_protobuf//types:go_default_library",
"@com_github_opencontainers_runtime_spec//specs-go:go_default_library",
"@org_golang_x_sys//unix:go_default_library",
],
@@ -48,8 +49,8 @@ go_test(
library = ":proc",
deps = [
"//pkg/shim/v1/runsccmd",
"@com_github_containerd_containerd//pkg/stdio:go_default_library",
"@com_github_containerd_containerd_v2//pkg/protobuf/types:go_default_library",
"@com_github_containerd_containerd_v2//pkg/stdio:go_default_library",
"@com_github_containerd_errdefs//:go_default_library",
"@com_github_gogo_protobuf//types:go_default_library",
],
)
+1 -1
View File
@@ -25,7 +25,7 @@ import (
"time"
"github.com/containerd/console"
"github.com/containerd/containerd/pkg/stdio"
"github.com/containerd/containerd/v2/pkg/stdio"
"github.com/containerd/errdefs"
"github.com/containerd/fifo"
runc "github.com/containerd/go-runc"
+3 -3
View File
@@ -27,14 +27,14 @@ import (
"github.com/containerd/console"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/pkg/stdio"
"github.com/containerd/containerd/v2/core/mount"
"github.com/containerd/containerd/v2/pkg/stdio"
"github.com/containerd/errdefs"
"github.com/containerd/log"
google_protobuf "github.com/containerd/containerd/v2/pkg/protobuf/types"
"github.com/containerd/fifo"
runc "github.com/containerd/go-runc"
google_protobuf "github.com/gogo/protobuf/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/shim/v1/extension"
+2 -1
View File
@@ -20,6 +20,7 @@ import (
"fmt"
"github.com/containerd/errdefs"
errgrpc "github.com/containerd/errdefs/pkg/errgrpc"
runc "github.com/containerd/go-runc"
"golang.org/x/sys/unix"
@@ -238,6 +239,6 @@ func handleStoppedKill(signal uint32) error {
// already been killed.
return nil
default:
return errdefs.ToGRPCf(errdefs.ErrNotFound, "process not found")
return errgrpc.ToGRPCf(errdefs.ErrNotFound, "process not found")
}
}
+1 -1
View File
@@ -18,8 +18,8 @@ package proc
import (
"time"
types "github.com/containerd/containerd/v2/pkg/protobuf/types"
runc "github.com/containerd/go-runc"
"github.com/gogo/protobuf/types"
)
// Mount holds filesystem mount configuration.
+2 -2
View File
@@ -19,9 +19,9 @@ import (
"strings"
"testing"
"github.com/containerd/containerd/pkg/stdio"
"github.com/containerd/containerd/v2/pkg/protobuf/types"
"github.com/containerd/containerd/v2/pkg/stdio"
"github.com/containerd/errdefs"
"github.com/gogo/protobuf/types"
"gvisor.dev/gvisor/pkg/shim/v1/runsccmd"
)
+26 -23
View File
@@ -41,31 +41,34 @@ go_library(
"//pkg/shim/v1/utils",
"//runsc/specutils",
"@com_github_burntsushi_toml//:go_default_library",
"@com_github_containerd_cgroups//:go_default_library",
"@com_github_containerd_cgroups//stats/v1:go_default_library",
"@com_github_containerd_cgroups//v2:go_default_library",
"@com_github_containerd_cgroups//v2/stats:go_default_library",
"@com_github_containerd_cgroups_v3//:go_default_library",
"@com_github_containerd_cgroups_v3//cgroup1:go_default_library",
"@com_github_containerd_cgroups_v3//cgroup1/stats:go_default_library", # keep
"@com_github_containerd_cgroups_v3//cgroup2:go_default_library",
"@com_github_containerd_cgroups_v3//cgroup2/stats:go_default_library", # keep
"@com_github_containerd_console//:go_default_library",
"@com_github_containerd_containerd//api/events:go_default_library",
"@com_github_containerd_containerd//api/types/task:go_default_library",
"@com_github_containerd_containerd//events:go_default_library",
"@com_github_containerd_containerd//mount:go_default_library",
"@com_github_containerd_containerd//namespaces:go_default_library",
"@com_github_containerd_containerd//pkg/process:go_default_library",
"@com_github_containerd_containerd//pkg/shutdown:go_default_library",
"@com_github_containerd_containerd//pkg/stdio:go_default_library",
"@com_github_containerd_containerd//runtime:go_default_library",
"@com_github_containerd_containerd//runtime/linux/runctypes:go_default_library",
"@com_github_containerd_containerd//runtime/v2/shim:go_default_library",
"@com_github_containerd_containerd//runtime/v2/task:go_default_library",
"@com_github_containerd_containerd//sys/reaper:go_default_library",
"@com_github_containerd_containerd_api//events:go_default_library",
"@com_github_containerd_containerd_api//runtime/task/v2:go_default_library",
"@com_github_containerd_containerd_api//types/runc/options:go_default_library",
"@com_github_containerd_containerd_api//types/task:go_default_library",
"@com_github_containerd_containerd_v2//cmd/containerd-shim-runc-v2/process:go_default_library",
"@com_github_containerd_containerd_v2//core/events:go_default_library",
"@com_github_containerd_containerd_v2//core/mount:go_default_library",
"@com_github_containerd_containerd_v2//core/runtime:go_default_library",
"@com_github_containerd_containerd_v2//pkg/namespaces:go_default_library",
"@com_github_containerd_containerd_v2//pkg/protobuf:go_default_library",
"@com_github_containerd_containerd_v2//pkg/protobuf/types:go_default_library",
"@com_github_containerd_containerd_v2//pkg/shim:go_default_library",
"@com_github_containerd_containerd_v2//pkg/shutdown:go_default_library",
"@com_github_containerd_containerd_v2//pkg/stdio:go_default_library",
"@com_github_containerd_containerd_v2//pkg/sys/reaper:go_default_library",
"@com_github_containerd_errdefs//:go_default_library",
"@com_github_containerd_errdefs_pkg//errgrpc:go_default_library",
"@com_github_containerd_fifo//:go_default_library",
"@com_github_containerd_go_runc//:go_default_library",
"@com_github_containerd_log//:go_default_library",
"@com_github_containerd_ttrpc//:go_default_library",
"@com_github_containerd_typeurl//:go_default_library",
"@com_github_gogo_protobuf//types:go_default_library",
"@com_github_containerd_typeurl_v2//:go_default_library",
"@com_github_opencontainers_runtime_spec//specs-go:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@org_golang_x_sys//unix:go_default_library",
@@ -82,10 +85,10 @@ go_test(
library = ":runsc",
deps = [
"//pkg/shim/v1/utils",
"@com_github_containerd_cgroups//v2:go_default_library",
"@com_github_containerd_containerd//events:go_default_library",
"@com_github_containerd_containerd//runtime:go_default_library",
"@com_github_containerd_containerd//runtime/v2/task:go_default_library",
"@com_github_containerd_cgroups_v3//cgroup2:go_default_library",
"@com_github_containerd_containerd_api//runtime/task/v2:go_default_library",
"@com_github_containerd_containerd_v2//core/events:go_default_library",
"@com_github_containerd_containerd_v2//core/runtime:go_default_library",
"@com_github_containerd_errdefs//:go_default_library",
"@com_github_google_go_cmp//cmp:go_default_library",
"@com_github_opencontainers_runtime_spec//specs-go:go_default_library",
+12 -11
View File
@@ -23,18 +23,19 @@ import (
"sync"
"github.com/BurntSushi/toml"
"github.com/containerd/cgroups"
cgroupsstats "github.com/containerd/cgroups/stats/v1"
cgroupsv2stats "github.com/containerd/cgroups/v2/stats"
cgroups "github.com/containerd/cgroups/v3"
cgroupsstats "github.com/containerd/cgroups/v3/cgroup1/stats"
cgroupsv2stats "github.com/containerd/cgroups/v3/cgroup2/stats"
"github.com/containerd/console"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/pkg/stdio"
"github.com/containerd/containerd/runtime/v2/task"
task "github.com/containerd/containerd/api/runtime/task/v2"
"github.com/containerd/containerd/v2/core/mount"
"github.com/containerd/containerd/v2/pkg/namespaces"
"github.com/containerd/containerd/v2/pkg/stdio"
"github.com/containerd/errdefs"
errgrpc "github.com/containerd/errdefs/pkg/errgrpc"
runc "github.com/containerd/go-runc"
"github.com/containerd/log"
"github.com/containerd/typeurl"
typeurl "github.com/containerd/typeurl/v2"
"github.com/sirupsen/logrus"
"gvisor.dev/gvisor/pkg/cleanup"
"gvisor.dev/gvisor/pkg/shim/v1/extension"
@@ -420,7 +421,7 @@ func (c *Container) Restore(ctx context.Context, r *extension.RestoreRequest) (e
func (c *Container) Stats(ctx context.Context) (*task.StatsResponse, error) {
p, err := c.Process("")
if err != nil {
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
stats, err := p.(*proc.Init).Stats(ctx, c.ID)
if err != nil {
@@ -484,7 +485,7 @@ func (c *Container) getV1Stats(stats *runc.Stats) (*task.StatsResponse, error) {
Limit: stats.Pids.Limit,
},
}
data, err := typeurl.MarshalAny(metrics)
data, err := typeurl.MarshalAnyToProto(metrics)
if err != nil {
log.L.Debugf("Stats error v1, id: %s: %v", c.ID, err)
return nil, err
@@ -518,7 +519,7 @@ func (c *Container) getV2Stats(stats *runc.Stats) (*task.StatsResponse, error) {
Limit: stats.Pids.Limit,
},
}
data, err := typeurl.MarshalAny(metrics)
data, err := typeurl.MarshalAnyToProto(metrics)
if err != nil {
log.L.Debugf("Stats error v2, id: %s: %v", c.ID, err)
return nil, err
+3 -3
View File
@@ -23,9 +23,9 @@ import (
"fmt"
"sync"
"github.com/containerd/cgroups"
"github.com/containerd/containerd/events"
"github.com/containerd/containerd/runtime"
cgroups "github.com/containerd/cgroups/v3/cgroup1"
"github.com/containerd/containerd/v2/core/events"
"github.com/containerd/containerd/v2/core/runtime"
"golang.org/x/sys/unix"
)
+3 -3
View File
@@ -23,9 +23,9 @@ import (
"fmt"
"sync"
cgroupsv2 "github.com/containerd/cgroups/v2"
"github.com/containerd/containerd/runtime"
"github.com/containerd/containerd/runtime/v2/shim"
cgroupsv2 "github.com/containerd/cgroups/v3/cgroup2"
"github.com/containerd/containerd/v2/core/runtime"
"github.com/containerd/containerd/v2/pkg/shim"
"github.com/sirupsen/logrus"
)
+3 -3
View File
@@ -24,9 +24,9 @@ import (
"testing"
"time"
cgroupsv2 "github.com/containerd/cgroups/v2"
"github.com/containerd/containerd/events"
"github.com/containerd/containerd/runtime"
cgroupsv2 "github.com/containerd/cgroups/v3/cgroup2"
"github.com/containerd/containerd/v2/core/events"
"github.com/containerd/containerd/v2/core/runtime"
)
// mockPublisher records published events for test assertions.
+71 -68
View File
@@ -24,22 +24,25 @@ import (
"strings"
"sync"
"github.com/containerd/cgroups"
cgroupsv2 "github.com/containerd/cgroups/v2"
cgroups "github.com/containerd/cgroups/v3"
cgroup1 "github.com/containerd/cgroups/v3/cgroup1"
cgroupsv2 "github.com/containerd/cgroups/v3/cgroup2"
"github.com/containerd/containerd/api/events"
"github.com/containerd/containerd/api/types/task"
"github.com/containerd/containerd/pkg/process"
"github.com/containerd/containerd/pkg/shutdown"
"github.com/containerd/containerd/pkg/stdio"
"github.com/containerd/containerd/runtime"
"github.com/containerd/containerd/runtime/linux/runctypes"
"github.com/containerd/containerd/runtime/v2/shim"
taskAPI "github.com/containerd/containerd/runtime/v2/task"
"github.com/containerd/containerd/sys/reaper"
task "github.com/containerd/containerd/api/runtime/task/v2"
runctypes "github.com/containerd/containerd/api/types/runc/options"
tasktypes "github.com/containerd/containerd/api/types/task"
"github.com/containerd/containerd/v2/cmd/containerd-shim-runc-v2/process"
"github.com/containerd/containerd/v2/core/runtime"
"github.com/containerd/containerd/v2/pkg/protobuf"
types "github.com/containerd/containerd/v2/pkg/protobuf/types"
"github.com/containerd/containerd/v2/pkg/shim"
"github.com/containerd/containerd/v2/pkg/shutdown"
"github.com/containerd/containerd/v2/pkg/stdio"
"github.com/containerd/containerd/v2/pkg/sys/reaper"
"github.com/containerd/errdefs"
errgrpc "github.com/containerd/errdefs/pkg/errgrpc"
"github.com/containerd/log"
"github.com/containerd/typeurl"
"github.com/gogo/protobuf/types"
typeurl "github.com/containerd/typeurl/v2"
specs "github.com/opencontainers/runtime-spec/specs-go"
"gvisor.dev/gvisor/pkg/shim/v1/extension"
@@ -166,14 +169,14 @@ func (s *runscService) getContainer(id string) (*Container, error) {
defer s.mu.Unlock()
c := s.containers[id]
if c == nil {
return nil, errdefs.ToGRPCf(errdefs.ErrNotFound, "container not created")
return nil, errgrpc.ToGRPCf(errdefs.ErrNotFound, "container not created")
}
return c, nil
}
// Create creates a new initial process and container with the underlying OCI
// runtime.
func (s *runscService) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (*taskAPI.CreateTaskResponse, error) {
func (s *runscService) Create(ctx context.Context, r *task.CreateTaskRequest) (*task.CreateTaskResponse, error) {
return s.CreateWithFSRestore(ctx, &extension.CreateWithFSRestoreRequest{
Create: r,
})
@@ -181,7 +184,7 @@ func (s *runscService) Create(ctx context.Context, r *taskAPI.CreateTaskRequest)
// CreateWithFSRestore is the same as Create, but it additionally restores the
// container's filesystem from a snapshot.
func (s *runscService) CreateWithFSRestore(ctx context.Context, rfs *extension.CreateWithFSRestoreRequest) (*taskAPI.CreateTaskResponse, error) {
func (s *runscService) CreateWithFSRestore(ctx context.Context, rfs *extension.CreateWithFSRestoreRequest) (*task.CreateTaskResponse, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -213,10 +216,10 @@ func (s *runscService) CreateWithFSRestore(ctx context.Context, rfs *extension.C
var cgPath string
cgPath, err = cgroupsv2.PidGroupPath(pid)
if err == nil {
cg, err = cgroupsv2.LoadManager("/sys/fs/cgroup", cgPath)
cg, err = cgroupsv2.Load(cgPath)
}
} else {
cg, err = cgroups.Load(cgroups.V1, cgroups.PidPath(pid))
cg, err = cgroup1.Load(cgroup1.PidPath(pid))
}
if err != nil {
return nil, fmt.Errorf("loading cgroup for %d: %w", pid, err)
@@ -227,36 +230,36 @@ func (s *runscService) CreateWithFSRestore(ctx context.Context, rfs *extension.C
return nil, fmt.Errorf("add cg to OOM monitor: %w", err)
}
}
return &taskAPI.CreateTaskResponse{
return &task.CreateTaskResponse{
Pid: uint32(pid),
}, nil
}
// Start starts the container.
func (s *runscService) Start(ctx context.Context, r *taskAPI.StartRequest) (*taskAPI.StartResponse, error) {
func (s *runscService) Start(ctx context.Context, r *task.StartRequest) (*task.StartResponse, error) {
c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
}
p, err := c.Start(ctx, r)
if err != nil {
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
// TODO: Set the cgroup and oom notifications on restore.
return &taskAPI.StartResponse{
return &task.StartResponse{
Pid: uint32(p.Pid()),
}, nil
}
// Delete deletes the initial process and container.
func (s *runscService) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (*taskAPI.DeleteResponse, error) {
func (s *runscService) Delete(ctx context.Context, r *task.DeleteRequest) (*task.DeleteResponse, error) {
c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
}
p, err := c.Delete(ctx, r)
if err != nil {
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
// ExecID will be empty for init container process.
@@ -270,15 +273,15 @@ func (s *runscService) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (*t
s.platform.Close()
}
}
return &taskAPI.DeleteResponse{
return &task.DeleteResponse{
ExitStatus: uint32(p.ExitStatus()),
ExitedAt: p.ExitedAt(),
ExitedAt: protobuf.ToTimestamp(p.ExitedAt()),
Pid: uint32(p.Pid()),
}, nil
}
// Exec spawns an additional process inside the container.
func (s *runscService) Exec(ctx context.Context, r *taskAPI.ExecProcessRequest) (*types.Empty, error) {
func (s *runscService) Exec(ctx context.Context, r *task.ExecProcessRequest) (*types.Empty, error) {
c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
@@ -286,7 +289,7 @@ func (s *runscService) Exec(ctx context.Context, r *taskAPI.ExecProcessRequest)
// Check whether or not the process already exists in the container.
p, _ := c.Process(r.ExecID)
if p != nil {
return nil, errdefs.ToGRPCf(errdefs.ErrAlreadyExists, "id %s", r.ExecID)
return nil, errgrpc.ToGRPCf(errdefs.ErrAlreadyExists, "id %s", r.ExecID)
}
p, err = c.Exec(ctx, r)
if err != nil {
@@ -300,19 +303,19 @@ func (s *runscService) Exec(ctx context.Context, r *taskAPI.ExecProcessRequest)
}
// ResizePty resizes the terminal of a process.
func (s *runscService) ResizePty(ctx context.Context, r *taskAPI.ResizePtyRequest) (*types.Empty, error) {
func (s *runscService) ResizePty(ctx context.Context, r *task.ResizePtyRequest) (*types.Empty, error) {
c, err := s.getContainer(r.ID)
if err != nil {
return nil, errdefs.ToGRPCf(errdefs.ErrFailedPrecondition, "container must be created")
return nil, errgrpc.ToGRPCf(errdefs.ErrFailedPrecondition, "container must be created")
}
if err := c.ResizePty(ctx, r); err != nil {
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
return empty, nil
}
// State returns runtime state information for the container.
func (s *runscService) State(ctx context.Context, r *taskAPI.StateRequest) (*taskAPI.StateResponse, error) {
func (s *runscService) State(ctx context.Context, r *task.StateRequest) (*task.StateResponse, error) {
c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
@@ -320,26 +323,26 @@ func (s *runscService) State(ctx context.Context, r *taskAPI.StateRequest) (*tas
p, err := c.Process(r.ExecID)
if err != nil {
log.L.Debugf("State failed to find process: %v", err)
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
st, err := p.Status(ctx)
if err != nil {
log.L.Debugf("State failed: %v", err)
return nil, err
}
status := task.StatusUnknown
status := tasktypes.Status_UNKNOWN
switch st {
case "created":
status = task.StatusCreated
status = tasktypes.Status_CREATED
case "running":
status = task.StatusRunning
status = tasktypes.Status_RUNNING
case "stopped":
status = task.StatusStopped
status = tasktypes.Status_STOPPED
case "pausing":
status = task.StatusPausing
status = tasktypes.Status_PAUSING
}
sio := p.Stdio()
return &taskAPI.StateResponse{
return &task.StateResponse{
ID: p.ID(),
Bundle: c.Bundle,
Pid: uint32(p.Pid()),
@@ -349,18 +352,18 @@ func (s *runscService) State(ctx context.Context, r *taskAPI.StateRequest) (*tas
Stderr: sio.Stderr,
Terminal: sio.Terminal,
ExitStatus: uint32(p.ExitStatus()),
ExitedAt: p.ExitedAt(),
ExitedAt: protobuf.ToTimestamp(p.ExitedAt()),
}, nil
}
// Pause the container.
func (s *runscService) Pause(ctx context.Context, r *taskAPI.PauseRequest) (*types.Empty, error) {
func (s *runscService) Pause(ctx context.Context, r *task.PauseRequest) (*types.Empty, error) {
c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
}
if err := c.Pause(ctx, r); err != nil {
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
s.send(&events.TaskPaused{
ContainerID: c.ID,
@@ -369,13 +372,13 @@ func (s *runscService) Pause(ctx context.Context, r *taskAPI.PauseRequest) (*typ
}
// Resume the container.
func (s *runscService) Resume(ctx context.Context, r *taskAPI.ResumeRequest) (*types.Empty, error) {
func (s *runscService) Resume(ctx context.Context, r *task.ResumeRequest) (*types.Empty, error) {
c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
}
if err := c.Resume(ctx, r); err != nil {
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
s.send(&events.TaskResumed{
ContainerID: c.ID,
@@ -384,30 +387,30 @@ func (s *runscService) Resume(ctx context.Context, r *taskAPI.ResumeRequest) (*t
}
// Kill the container with the provided signal.
func (s *runscService) Kill(ctx context.Context, r *taskAPI.KillRequest) (*types.Empty, error) {
func (s *runscService) Kill(ctx context.Context, r *task.KillRequest) (*types.Empty, error) {
c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
}
if err := c.Kill(ctx, r); err != nil {
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
return empty, nil
}
// Pids returns all pids inside the container.
func (s *runscService) Pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskAPI.PidsResponse, error) {
func (s *runscService) Pids(ctx context.Context, r *task.PidsRequest) (*task.PidsResponse, error) {
c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
}
pids, err := s.getContainerPids(ctx, c)
if err != nil {
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
var processes []*task.ProcessInfo
var processes []*tasktypes.ProcessInfo
for _, pid := range pids {
pInfo := task.ProcessInfo{
pInfo := tasktypes.ProcessInfo{
Pid: pid,
}
for _, p := range c.ExecdProcesses() {
@@ -415,7 +418,7 @@ func (s *runscService) Pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskA
d := &runctypes.ProcessDetails{
ExecID: p.ID(),
}
a, err := typeurl.MarshalAny(d)
a, err := typeurl.MarshalAnyToProto(d)
if err != nil {
return nil, fmt.Errorf("failed to marshal process %d info: %w", pid, err)
}
@@ -425,30 +428,30 @@ func (s *runscService) Pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskA
}
processes = append(processes, &pInfo)
}
return &taskAPI.PidsResponse{
return &task.PidsResponse{
Processes: processes,
}, nil
}
// CloseIO closes the I/O context of the container.
func (s *runscService) CloseIO(ctx context.Context, r *taskAPI.CloseIORequest) (*types.Empty, error) {
func (s *runscService) CloseIO(ctx context.Context, r *task.CloseIORequest) (*types.Empty, error) {
c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
}
if err := c.CloseIO(ctx, r); err != nil {
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
return empty, nil
}
// Checkpoint checkpoints the container.
func (s *runscService) Checkpoint(ctx context.Context, r *taskAPI.CheckpointTaskRequest) (*types.Empty, error) {
func (s *runscService) Checkpoint(ctx context.Context, r *task.CheckpointTaskRequest) (*types.Empty, error) {
return empty, errdefs.ErrNotImplemented
}
// Restore restores the container.
func (s *runscService) Restore(ctx context.Context, r *extension.RestoreRequest) (*taskAPI.StartResponse, error) {
func (s *runscService) Restore(ctx context.Context, r *extension.RestoreRequest) (*task.StartResponse, error) {
c, err := s.getContainer(r.Start.ID)
if err != nil {
return nil, err
@@ -457,24 +460,24 @@ func (s *runscService) Restore(ctx context.Context, r *extension.RestoreRequest)
if err != nil {
return nil, err
}
return &taskAPI.StartResponse{
return &task.StartResponse{
Pid: uint32(p.Pid()),
}, nil
}
// Connect returns shim information such as the shim's pid.
func (s *runscService) Connect(ctx context.Context, r *taskAPI.ConnectRequest) (*taskAPI.ConnectResponse, error) {
func (s *runscService) Connect(ctx context.Context, r *task.ConnectRequest) (*task.ConnectResponse, error) {
var pid int
if c, err := s.getContainer(r.ID); err == nil {
pid = c.Pid()
}
return &taskAPI.ConnectResponse{
return &task.ConnectResponse{
ShimPid: uint32(os.Getpid()),
TaskPid: uint32(pid),
}, nil
}
func (s *runscService) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest) (*types.Empty, error) {
func (s *runscService) Shutdown(ctx context.Context, r *task.ShutdownRequest) (*types.Empty, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -485,7 +488,7 @@ func (s *runscService) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest)
return empty, nil
}
func (s *runscService) Stats(ctx context.Context, r *taskAPI.StatsRequest) (*taskAPI.StatsResponse, error) {
func (s *runscService) Stats(ctx context.Context, r *task.StatsRequest) (*task.StatsResponse, error) {
c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
@@ -502,32 +505,32 @@ func (s *runscService) Stats(ctx context.Context, r *taskAPI.StatsRequest) (*tas
}
// Update updates a running container.
func (s *runscService) Update(ctx context.Context, r *taskAPI.UpdateTaskRequest) (*types.Empty, error) {
func (s *runscService) Update(ctx context.Context, r *task.UpdateTaskRequest) (*types.Empty, error) {
c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
}
if err := c.Update(ctx, r); err != nil {
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
return empty, nil
}
// Wait waits for the container to exit.
func (s *runscService) Wait(ctx context.Context, r *taskAPI.WaitRequest) (*taskAPI.WaitResponse, error) {
func (s *runscService) Wait(ctx context.Context, r *task.WaitRequest) (*task.WaitResponse, error) {
c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
}
p, err := c.Process(r.ExecID)
if err != nil {
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
p.Wait()
res := &taskAPI.WaitResponse{
res := &task.WaitResponse{
ExitStatus: uint32(p.ExitStatus()),
ExitedAt: p.ExitedAt(),
ExitedAt: protobuf.ToTimestamp(p.ExitedAt()),
}
log.L.Debugf("Wait succeeded, response: %+v", res)
return res, nil
@@ -587,7 +590,7 @@ func (s *runscService) checkProcesses(ctx context.Context, e proc.Exit) {
ID: p.ID(),
Pid: uint32(p.Pid()),
ExitStatus: uint32(e.Status),
ExitedAt: p.ExitedAt(),
ExitedAt: protobuf.ToTimestamp(p.ExitedAt()),
})
}
+1 -1
View File
@@ -18,7 +18,7 @@ import (
"errors"
"testing"
"github.com/containerd/containerd/runtime/v2/task"
task "github.com/containerd/containerd/api/runtime/task/v2"
"github.com/containerd/errdefs"
specs "github.com/opencontainers/runtime-spec/specs-go"
"gvisor.dev/gvisor/pkg/shim/v1/utils"
+3 -3
View File
@@ -28,8 +28,8 @@ go_test(
srcs = ["runtimeoptions_test.go"],
library = ":runtimeoptions",
deps = [
"@com_github_containerd_containerd//runtime/v1/shim/v1:go_default_library",
"@com_github_containerd_typeurl//:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_containerd_containerd_api//runtime/task/v2:go_default_library",
"@com_github_containerd_typeurl_v2//:go_default_library",
"@org_golang_google_protobuf//encoding/prototext:go_default_library",
],
)
@@ -15,12 +15,11 @@
package runtimeoptions
import (
"bytes"
"testing"
shim "github.com/containerd/containerd/runtime/v1/shim/v1"
"github.com/containerd/typeurl"
"github.com/gogo/protobuf/proto"
task "github.com/containerd/containerd/api/runtime/task/v2"
typeurl "github.com/containerd/typeurl/v2"
"google.golang.org/protobuf/encoding/prototext"
)
func TestCreateTaskRequest(t *testing.T) {
@@ -29,15 +28,15 @@ func TestCreateTaskRequest(t *testing.T) {
type_url: "runtimeoptions.v1.Options"
value: "\n\010type_url\022\013config_path"
>`
got := &shim.CreateTaskRequest{} // Should have raw options.
if err := proto.UnmarshalText(encodedText, got); err != nil {
got := &task.CreateTaskRequest{} // Should have raw options.
if err := prototext.Unmarshal([]byte(encodedText), got); err != nil {
t.Fatalf("unable to unmarshal text: %v", err)
}
var textBuffer bytes.Buffer
if err := proto.MarshalText(&textBuffer, got); err != nil {
gotText, err := prototext.Marshal(got)
if err != nil {
t.Errorf("unable to marshal text: %v", err)
}
t.Logf("got: %s", textBuffer.String())
t.Logf("got: %s", string(gotText))
// Check the options.
wantOptions := &Options{}
@@ -49,9 +48,9 @@ func TestCreateTaskRequest(t *testing.T) {
}
gotOptions, ok := gotMessage.(*Options)
if !ok {
t.Fatalf("got %v, want %v", gotMessage, wantOptions)
t.Fatalf("got %T, want %T", gotMessage, wantOptions)
}
if !proto.Equal(gotOptions, wantOptions) {
t.Fatalf("got %v, want %v", gotOptions, wantOptions)
if gotOptions.TypeUrl != wantOptions.TypeUrl || gotOptions.ConfigPath != wantOptions.ConfigPath {
t.Fatalf("got %+v, want %+v", gotOptions, wantOptions)
}
}
+49 -49
View File
@@ -20,13 +20,13 @@ import (
"fmt"
"os"
"github.com/containerd/containerd/pkg/shutdown"
"github.com/containerd/containerd/runtime/v2/shim"
shimapi "github.com/containerd/containerd/runtime/v2/task"
"github.com/containerd/errdefs"
task "github.com/containerd/containerd/api/runtime/task/v2"
types "github.com/containerd/containerd/v2/pkg/protobuf/types"
"github.com/containerd/containerd/v2/pkg/shim"
"github.com/containerd/containerd/v2/pkg/shutdown"
errgrpc "github.com/containerd/errdefs/pkg/errgrpc"
"github.com/containerd/log"
"github.com/containerd/ttrpc"
"github.com/gogo/protobuf/types"
hibernatepb "gvisor.dev/gvisor/pkg/shim/v1/runsc/hibernate_go_proto"
"gvisor.dev/gvisor/pkg/shim/v1/extension"
@@ -142,7 +142,7 @@ func isDaemon() bool {
}
// initExt initializes the extension that may intercept calls to the container's shim.
func (s *shimRedirector) initExt(ctx context.Context, r *shimapi.CreateTaskRequest) error {
func (s *shimRedirector) initExt(ctx context.Context, r *task.CreateTaskRequest) error {
s.mu.Lock()
defer s.mu.Unlock()
@@ -198,110 +198,110 @@ func (s *shimRedirector) initExt(ctx context.Context, r *shimapi.CreateTaskReque
// Create creates a new initial process and container with the underlying OCI
// runtime.
func (s *shimRedirector) Create(ctx context.Context, r *shimapi.CreateTaskRequest) (*shimapi.CreateTaskResponse, error) {
func (s *shimRedirector) Create(ctx context.Context, r *task.CreateTaskRequest) (*task.CreateTaskResponse, error) {
log.L.Debugf("Create, id: %s, bundle: %q", r.ID, r.Bundle)
if err := s.initExt(ctx, r); err != nil {
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
resp, err := s.get().Create(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// CreateWithFSRestore creates a container which restores its filesystem from a snapshot.
func (s *shimRedirector) CreateWithFSRestore(ctx context.Context, r *extension.CreateWithFSRestoreRequest) (*shimapi.CreateTaskResponse, error) {
func (s *shimRedirector) CreateWithFSRestore(ctx context.Context, r *extension.CreateWithFSRestoreRequest) (*task.CreateTaskResponse, error) {
log.L.Debugf("CreateWithFSRestore, id: %s, bundle: %q", r.Create.ID, r.Create.Bundle)
if err := s.initExt(ctx, r.Create); err != nil {
return nil, errdefs.ToGRPC(err)
return nil, errgrpc.ToGRPC(err)
}
resp, err := s.get().CreateWithFSRestore(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// Start starts the container.
func (s *shimRedirector) Start(ctx context.Context, r *shimapi.StartRequest) (*shimapi.StartResponse, error) {
func (s *shimRedirector) Start(ctx context.Context, r *task.StartRequest) (*task.StartResponse, error) {
log.L.Debugf("Start, id: %s, execID: %s", r.ID, r.ExecID)
resp, err := s.get().Start(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// Delete deletes container.
func (s *shimRedirector) Delete(ctx context.Context, r *shimapi.DeleteRequest) (*shimapi.DeleteResponse, error) {
func (s *shimRedirector) Delete(ctx context.Context, r *task.DeleteRequest) (*task.DeleteResponse, error) {
log.L.Debugf("Delete, id: %s, execID: %s", r.ID, r.ExecID)
resp, err := s.get().Delete(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// Exec spawns a process inside the container.
func (s *shimRedirector) Exec(ctx context.Context, r *shimapi.ExecProcessRequest) (*types.Empty, error) {
func (s *shimRedirector) Exec(ctx context.Context, r *task.ExecProcessRequest) (*types.Empty, error) {
log.L.Debugf("Exec, id: %s, execID: %s", r.ID, r.ExecID)
resp, err := s.get().Exec(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// ResizePty resizes the terminal of a process.
func (s *shimRedirector) ResizePty(ctx context.Context, r *shimapi.ResizePtyRequest) (*types.Empty, error) {
func (s *shimRedirector) ResizePty(ctx context.Context, r *task.ResizePtyRequest) (*types.Empty, error) {
log.L.Debugf("ResizePty, id: %s, execID: %s, dimension: %dx%d", r.ID, r.ExecID, r.Height, r.Width)
resp, err := s.get().ResizePty(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// State returns runtime state information for the container.
func (s *shimRedirector) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.StateResponse, error) {
func (s *shimRedirector) State(ctx context.Context, r *task.StateRequest) (*task.StateResponse, error) {
log.L.Debugf("State, id: %s, execID: %s", r.ID, r.ExecID)
resp, err := s.get().State(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// Pause the container.
func (s *shimRedirector) Pause(ctx context.Context, r *shimapi.PauseRequest) (*types.Empty, error) {
func (s *shimRedirector) Pause(ctx context.Context, r *task.PauseRequest) (*types.Empty, error) {
log.L.Debugf("Pause, id: %s", r.ID)
resp, err := s.get().Pause(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// Resume the container.
func (s *shimRedirector) Resume(ctx context.Context, r *shimapi.ResumeRequest) (*types.Empty, error) {
func (s *shimRedirector) Resume(ctx context.Context, r *task.ResumeRequest) (*types.Empty, error) {
log.L.Debugf("Resume, id: %s", r.ID)
resp, err := s.get().Resume(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// Kill the container with the provided signal.
func (s *shimRedirector) Kill(ctx context.Context, r *shimapi.KillRequest) (*types.Empty, error) {
func (s *shimRedirector) Kill(ctx context.Context, r *task.KillRequest) (*types.Empty, error) {
log.L.Debugf("Kill, id: %s, execID: %s, signal: %d, all: %t", r.ID, r.ExecID, r.Signal, r.All)
resp, err := s.get().Kill(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// Pids returns all pids inside the container.
func (s *shimRedirector) Pids(ctx context.Context, r *shimapi.PidsRequest) (*shimapi.PidsResponse, error) {
func (s *shimRedirector) Pids(ctx context.Context, r *task.PidsRequest) (*task.PidsResponse, error) {
log.L.Debugf("Pids, id: %s", r.ID)
resp, err := s.get().Pids(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// CloseIO closes the I/O context of the container.
func (s *shimRedirector) CloseIO(ctx context.Context, r *shimapi.CloseIORequest) (*types.Empty, error) {
func (s *shimRedirector) CloseIO(ctx context.Context, r *task.CloseIORequest) (*types.Empty, error) {
log.L.Debugf("CloseIO, id: %s, execID: %s, stdin: %t", r.ID, r.ExecID, r.Stdin)
resp, err := s.get().CloseIO(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// Checkpoint checkpoints the container.
func (s *shimRedirector) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskRequest) (*types.Empty, error) {
func (s *shimRedirector) Checkpoint(ctx context.Context, r *task.CheckpointTaskRequest) (*types.Empty, error) {
log.L.Debugf("Checkpoint, id: %s", r.ID)
resp, err := s.get().Checkpoint(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// Connect returns shim information such as the shim's pid.
func (s *shimRedirector) Connect(ctx context.Context, r *shimapi.ConnectRequest) (*shimapi.ConnectResponse, error) {
func (s *shimRedirector) Connect(ctx context.Context, r *task.ConnectRequest) (*task.ConnectResponse, error) {
log.L.Debugf("Connect, id: %s", r.ID)
resp, err := s.get().Connect(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
func (s *shimRedirector) Shutdown(ctx context.Context, r *shimapi.ShutdownRequest) (*types.Empty, error) {
func (s *shimRedirector) Shutdown(ctx context.Context, r *task.ShutdownRequest) (*types.Empty, error) {
log.L.Debugf("Shutdown, id: %s", r.ID)
resp, err := s.get().Shutdown(ctx, r)
if err != nil {
@@ -313,53 +313,53 @@ func (s *shimRedirector) Shutdown(ctx context.Context, r *shimapi.ShutdownReques
// signal without error. The error from runscService's Shutdown call is used
// as an indicator to identify if there are any active containers in the shim.
log.L.Debugf("Shutdown, shim did not shutdown due to: %v", err)
return resp, errdefs.ToGRPC(nil)
return resp, errgrpc.ToGRPC(nil)
}
s.shutdown.Shutdown()
os.Exit(0)
panic("Should not get here")
}
func (s *shimRedirector) Stats(ctx context.Context, r *shimapi.StatsRequest) (*shimapi.StatsResponse, error) {
func (s *shimRedirector) Stats(ctx context.Context, r *task.StatsRequest) (*task.StatsResponse, error) {
log.L.Debugf("Stats, id: %s", r.ID)
resp, err := s.get().Stats(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// Update updates a running container.
func (s *shimRedirector) Update(ctx context.Context, r *shimapi.UpdateTaskRequest) (*types.Empty, error) {
func (s *shimRedirector) Update(ctx context.Context, r *task.UpdateTaskRequest) (*types.Empty, error) {
log.L.Debugf("Update, id: %s", r.ID)
resp, err := s.get().Update(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// Wait waits for the container to exit.
func (s *shimRedirector) Wait(ctx context.Context, r *shimapi.WaitRequest) (*shimapi.WaitResponse, error) {
func (s *shimRedirector) Wait(ctx context.Context, r *task.WaitRequest) (*task.WaitResponse, error) {
log.L.Debugf("Wait, id: %s, execID: %s", r.ID, r.ExecID)
resp, err := s.get().Wait(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
// Restore restores the container.
func (s *shimRedirector) Restore(ctx context.Context, r *extension.RestoreRequest) (*shimapi.StartResponse, error) {
func (s *shimRedirector) Restore(ctx context.Context, r *extension.RestoreRequest) (*task.StartResponse, error) {
log.L.Debugf("Restore, id: %s", r.Start.ID)
resp, err := s.get().Restore(ctx, r)
return resp, errdefs.ToGRPC(err)
return resp, errgrpc.ToGRPC(err)
}
func (s *shimRedirector) Hide(ctx context.Context, r *hibernatepb.HideRequest, resp *hibernatepb.HideResponse) error {
log.L.Debugf("Hide, id: %s", r.GetContainerId())
err := s.get().Hide(ctx, r, resp)
return errdefs.ToGRPC(err)
return errgrpc.ToGRPC(err)
}
func (s *shimRedirector) Unhide(ctx context.Context, r *hibernatepb.UnhideRequest, resp *hibernatepb.UnhideResponse) error {
log.L.Debugf("Unhide, id: %s", r.GetContainerId())
err := s.get().Unhide(ctx, r, resp)
return errdefs.ToGRPC(err)
return errgrpc.ToGRPC(err)
}
func (s *shimRedirector) RegisterTTRPC(server *ttrpc.Server) error {
shimapi.RegisterTaskService(server, s)
task.RegisterTaskService(server, s)
return nil
}
+1 -1
View File
@@ -15,6 +15,6 @@ go_library(
deps = [
"//pkg/shim/v1",
"//pkg/shim/v1/plugin",
"@com_github_containerd_containerd//runtime/v2/shim:go_default_library",
"@com_github_containerd_containerd_v2//pkg/shim:go_default_library",
],
)
+2 -2
View File
@@ -19,7 +19,7 @@ package cli
import (
"context"
containerdshim "github.com/containerd/containerd/runtime/v2/shim"
containerdshim "github.com/containerd/containerd/v2/pkg/shim"
// This import registers the runsc plugin with containerd.
shim "gvisor.dev/gvisor/pkg/shim/v1"
_ "gvisor.dev/gvisor/pkg/shim/v1/plugin"
@@ -27,5 +27,5 @@ import (
// Main is the main entrypoint.
func Main() {
containerdshim.RunManager(context.Background(), shim.NewShimManager("io.containerd.runsc.v1"))
containerdshim.Run(context.Background(), shim.NewShimManager("io.containerd.runsc.v1"))
}