diff --git a/MODULE.bazel b/MODULE.bazel index e512c524e8..ecff15a1ec 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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", @@ -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=", @@ -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=", diff --git a/go.mod b/go.mod index 05ea1fb9d8..2e2c85e0b5 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 459010df85..4ca43fe5ec 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/nogo.yaml b/nogo.yaml index cf08c90bf9..549d7c1fa3 100644 --- a/nogo.yaml +++ b/nogo.yaml @@ -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. diff --git a/pkg/shim/BUILD b/pkg/shim/BUILD new file mode 100644 index 0000000000..88cfd3954d --- /dev/null +++ b/pkg/shim/BUILD @@ -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"], +) diff --git a/pkg/shim/runtimeoptions/BUILD b/pkg/shim/runtimeoptions/BUILD new file mode 100644 index 0000000000..cf9cb6f839 --- /dev/null +++ b/pkg/shim/runtimeoptions/BUILD @@ -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"], +) diff --git a/pkg/shim/v1/runtimeoptions/runtimeoptions.go b/pkg/shim/runtimeoptions/runtimeoptions.go similarity index 100% rename from pkg/shim/v1/runtimeoptions/runtimeoptions.go rename to pkg/shim/runtimeoptions/runtimeoptions.go diff --git a/pkg/shim/v1/runtimeoptions/runtimeoptions.proto b/pkg/shim/runtimeoptions/runtimeoptions.proto similarity index 97% rename from pkg/shim/v1/runtimeoptions/runtimeoptions.proto rename to pkg/shim/runtimeoptions/runtimeoptions.proto index f3c1c605c0..2592fe4466 100644 --- a/pkg/shim/v1/runtimeoptions/runtimeoptions.proto +++ b/pkg/shim/runtimeoptions/runtimeoptions.proto @@ -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 diff --git a/pkg/shim/v1/runtimeoptions/runtimeoptions_cri.go b/pkg/shim/runtimeoptions/runtimeoptions_cri.go similarity index 100% rename from pkg/shim/v1/runtimeoptions/runtimeoptions_cri.go rename to pkg/shim/runtimeoptions/runtimeoptions_cri.go diff --git a/pkg/shim/v1/runtimeoptions/v14/runtimeoptions.go b/pkg/shim/shim.go similarity index 55% rename from pkg/shim/v1/runtimeoptions/v14/runtimeoptions.go rename to pkg/shim/shim.go index 7b34a1f6b6..f5c1ebf9cb 100644 --- a/pkg/shim/v1/runtimeoptions/v14/runtimeoptions.go +++ b/pkg/shim/shim.go @@ -1,11 +1,10 @@ -// 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, @@ -13,8 +12,12 @@ // 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 +} diff --git a/pkg/shim/v1/extension/BUILD b/pkg/shim/v1/extension/BUILD index 0708a47f88..6fb8c2b89b 100644 --- a/pkg/shim/v1/extension/BUILD +++ b/pkg/shim/v1/extension/BUILD @@ -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", ], diff --git a/pkg/shim/v1/extension/extension.go b/pkg/shim/v1/extension/extension.go index 753f684cff..3336bd5580 100644 --- a/pkg/shim/v1/extension/extension.go +++ b/pkg/shim/v1/extension/extension.go @@ -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 @@ -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. diff --git a/pkg/shim/v1/proc/BUILD b/pkg/shim/v1/proc/BUILD index e3bf358468..cb3c94a58c 100644 --- a/pkg/shim/v1/proc/BUILD +++ b/pkg/shim/v1/proc/BUILD @@ -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", diff --git a/pkg/shim/v1/proc/deleted_state.go b/pkg/shim/v1/proc/deleted_state.go index cbde451482..778d55c33d 100644 --- a/pkg/shim/v1/proc/deleted_state.go +++ b/pkg/shim/v1/proc/deleted_state.go @@ -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" ) @@ -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") } diff --git a/pkg/shim/v1/proc/exec.go b/pkg/shim/v1/proc/exec.go index 6393cd791c..d65802ea01 100644 --- a/pkg/shim/v1/proc/exec.go +++ b/pkg/shim/v1/proc/exec.go @@ -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" ) @@ -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") } diff --git a/pkg/shim/v1/proc/exec_state.go b/pkg/shim/v1/proc/exec_state.go index 35ac724625..46aa744a6b 100644 --- a/pkg/shim/v1/proc/exec_state.go +++ b/pkg/shim/v1/proc/exec_state.go @@ -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) @@ -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") } @@ -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") } @@ -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") } diff --git a/pkg/shim/v1/proc/init.go b/pkg/shim/v1/proc/init.go index 1868286fdc..c4f4c84cc2 100644 --- a/pkg/shim/v1/proc/init.go +++ b/pkg/shim/v1/proc/init.go @@ -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" @@ -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 @@ -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() diff --git a/pkg/shim/v1/proc/init_state.go b/pkg/shim/v1/proc/init_state.go index d564f3a2e3..c67c2fb1a3 100644 --- a/pkg/shim/v1/proc/init_state.go +++ b/pkg/shim/v1/proc/init_state.go @@ -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" ) @@ -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) @@ -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 @@ -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") } @@ -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") } diff --git a/pkg/shim/v1/runsc/BUILD b/pkg/shim/v1/runsc/BUILD index 788bb4ca1a..05d58298bc 100644 --- a/pkg/shim/v1/runsc/BUILD +++ b/pkg/shim/v1/runsc/BUILD @@ -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", diff --git a/pkg/shim/v1/runsc/service.go b/pkg/shim/v1/runsc/service.go index 9bb73b4772..cd8fe54109 100644 --- a/pkg/shim/v1/runsc/service.go +++ b/pkg/shim/v1/runsc/service.go @@ -51,12 +51,11 @@ import ( "github.com/sirupsen/logrus" "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/cleanup" - "gvisor.dev/gvisor/pkg/shim/v1/runtimeoptions/v14" + "gvisor.dev/gvisor/pkg/shim/runtimeoptions" "gvisor.dev/gvisor/pkg/shim/v1/extension" "gvisor.dev/gvisor/pkg/shim/v1/proc" "gvisor.dev/gvisor/pkg/shim/v1/runsccmd" - "gvisor.dev/gvisor/pkg/shim/v1/runtimeoptions" "gvisor.dev/gvisor/pkg/shim/v1/utils" "gvisor.dev/gvisor/runsc/specutils" ) @@ -219,26 +218,6 @@ func (s *runscService) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) } var path string switch o := v.(type) { - case *runctypes.CreateOptions: // containerd 1.2.x - s.opts.IoUID = o.IoUid - s.opts.IoGID = o.IoGid - s.opts.ShimCgroup = o.ShimCgroup - case *runctypes.RuncOptions: // containerd 1.2.x - root := proc.RunscRoot - if o.RuntimeRoot != "" { - root = o.RuntimeRoot - } - - s.opts.BinaryName = o.Runtime - - path = filepath.Join(root, configFile) - if _, err := os.Stat(path); err != nil { - if !os.IsNotExist(err) { - return nil, fmt.Errorf("stat config file %q: %w", path, err) - } - // A config file in runtime root is not required. - path = "" - } case *runtimeoptions.Options: // containerd 1.5+ if o.ConfigPath == "" { break @@ -247,14 +226,6 @@ func (s *runscService) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) return nil, fmt.Errorf("unsupported option type %q", o.TypeUrl) } path = o.ConfigPath - case *v14.Options: // containerd 1.4- - if o.ConfigPath == "" { - break - } - if o.TypeUrl != optionsType { - return nil, fmt.Errorf("unsupported option type %q", o.TypeUrl) - } - path = o.ConfigPath default: return nil, fmt.Errorf("unsupported option type %q", r.Options.TypeUrl) } diff --git a/pkg/shim/v1/runtimeoptions/BUILD b/pkg/shim/v1/runtimeoptions/BUILD index 7db78e7e3d..5587b33b33 100644 --- a/pkg/shim/v1/runtimeoptions/BUILD +++ b/pkg/shim/v1/runtimeoptions/BUILD @@ -1,33 +1,16 @@ -load("//tools:defs.bzl", "go_library", "go_test", "proto_library") +load("//tools:defs.bzl", "go_test") 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/v1/runsc:__pkg__"], - deps = ["@com_github_gogo_protobuf//proto:go_default_library"], -) - go_test( name = "runtimeoptions_test", size = "small", srcs = ["runtimeoptions_test.go"], - library = ":runtimeoptions", deps = [ + "//pkg/shim/runtimeoptions", "@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", diff --git a/pkg/shim/v1/runtimeoptions/runtimeoptions_test.go b/pkg/shim/v1/runtimeoptions/runtimeoptions_test.go index 44ef0c9454..5406d6ddb9 100644 --- a/pkg/shim/v1/runtimeoptions/runtimeoptions_test.go +++ b/pkg/shim/v1/runtimeoptions/runtimeoptions_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package runtimeoptions +package runtimeoptions_test import ( "bytes" @@ -21,12 +21,13 @@ import ( shim "github.com/containerd/containerd/runtime/v1/shim/v1" "github.com/containerd/typeurl" "github.com/gogo/protobuf/proto" + "gvisor.dev/gvisor/pkg/shim/runtimeoptions" ) func TestCreateTaskRequest(t *testing.T) { // Serialize the top-level message. const encodedText = `options: < - type_url: "runtimeoptions.v1.Options" + type_url: "runtimeoptions.Options" value: "\n\010type_url\022\013config_path" >` got := &shim.CreateTaskRequest{} // Should have raw options. @@ -40,14 +41,14 @@ func TestCreateTaskRequest(t *testing.T) { t.Logf("got: %s", string(textBuffer.Bytes())) // Check the options. - wantOptions := &Options{} + wantOptions := &runtimeoptions.Options{} wantOptions.TypeUrl = "type_url" wantOptions.ConfigPath = "config_path" gotMessage, err := typeurl.UnmarshalAny(got.Options) if err != nil { t.Fatalf("unable to unmarshal any: %v", err) } - gotOptions, ok := gotMessage.(*Options) + gotOptions, ok := gotMessage.(*runtimeoptions.Options) if !ok { t.Fatalf("got %v, want %v", gotMessage, wantOptions) } diff --git a/pkg/shim/v1/runtimeoptions/v14/BUILD b/pkg/shim/v1/runtimeoptions/v14/BUILD deleted file mode 100644 index 0277202179..0000000000 --- a/pkg/shim/v1/runtimeoptions/v14/BUILD +++ /dev/null @@ -1,35 +0,0 @@ -load("//tools:defs.bzl", "go_library", "go_test", "proto_library") - -package( - default_applicable_licenses = ["//:license"], - licenses = ["notice"], -) - -proto_library( - name = "api", - srcs = [ - "runtimeoptions.proto", - ], -) - -go_library( - name = "v14", - srcs = [ - "runtimeoptions.go", - "runtimeoptions_cri.go", - ], - visibility = ["//pkg/shim/v1/runsc:__pkg__"], - deps = ["@com_github_gogo_protobuf//proto:go_default_library"], -) - -go_test( - name = "runtimeoptions_test", - size = "small", - srcs = ["runtimeoptions_test.go"], - library = ":v14", - 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", - ], -) diff --git a/pkg/shim/v1/runtimeoptions/v14/runtimeoptions.proto b/pkg/shim/v1/runtimeoptions/v14/runtimeoptions.proto deleted file mode 100644 index d52f58a575..0000000000 --- a/pkg/shim/v1/runtimeoptions/v14/runtimeoptions.proto +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020 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 -// -// 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. - -syntax = "proto3"; - -package cri.runtimeoptions.v1; - -// This is a version of the runtimeoptions CRI API that is vendored. -// Source: cri/pkg/api/runtimeoptions/v1/api.proto -// -// Importing the full CRI package is a nightmare. -message Options { - // TypeUrl specifies the type of the content inside the config file. - string type_url = 1; - // ConfigPath specifies the filesystem location of the config file - // used by the runtime. - string config_path = 2; -} diff --git a/pkg/shim/v1/runtimeoptions/v14/runtimeoptions_cri.go b/pkg/shim/v1/runtimeoptions/v14/runtimeoptions_cri.go deleted file mode 100644 index 1dd2817d5f..0000000000 --- a/pkg/shim/v1/runtimeoptions/v14/runtimeoptions_cri.go +++ /dev/null @@ -1,386 +0,0 @@ -// Copyright 2018 The containerd Authors. -// Copyright 2018 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 -// -// 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. - -//go:build !false -// +build !false - -package v14 - -import ( - "fmt" - "io" - "reflect" - "strings" - - proto "github.com/gogo/protobuf/proto" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package - -type Options struct { - // TypeUrl specifies the type of the content inside the config file. - TypeUrl string `protobuf:"bytes,1,opt,name=type_url,json=typeUrl,proto3" json:"type_url,omitempty"` - // ConfigPath specifies the filesystem location of the config file - // used by the runtime. - ConfigPath string `protobuf:"bytes,2,opt,name=config_path,json=configPath,proto3" json:"config_path,omitempty"` -} - -func (m *Options) Reset() { *m = Options{} } -func (*Options) ProtoMessage() {} -func (*Options) Descriptor() ([]byte, []int) { return fileDescriptorApi, []int{0} } - -func (m *Options) GetTypeUrl() string { - if m != nil { - return m.TypeUrl - } - return "" -} - -func (m *Options) GetConfigPath() string { - if m != nil { - return m.ConfigPath - } - return "" -} - -func init() { - proto.RegisterType((*Options)(nil), "cri.runtimeoptions.v1.Options") -} - -func (m *Options) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Options) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if len(m.TypeUrl) > 0 { - dAtA[i] = 0xa - i++ - i = encodeVarintApi(dAtA, i, uint64(len(m.TypeUrl))) - i += copy(dAtA[i:], m.TypeUrl) - } - if len(m.ConfigPath) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintApi(dAtA, i, uint64(len(m.ConfigPath))) - i += copy(dAtA[i:], m.ConfigPath) - } - return i, nil -} - -func encodeVarintApi(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} - -func (m *Options) Size() (n int) { - var l int - _ = l - l = len(m.TypeUrl) - if l > 0 { - n += 1 + l + sovApi(uint64(l)) - } - l = len(m.ConfigPath) - if l > 0 { - n += 1 + l + sovApi(uint64(l)) - } - return n -} - -func sovApi(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} - -func sozApi(x uint64) (n int) { - return sovApi(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} - -func (this *Options) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Options{`, - `TypeUrl:` + fmt.Sprintf("%v", this.TypeUrl) + `,`, - `ConfigPath:` + fmt.Sprintf("%v", this.ConfigPath) + `,`, - `}`, - }, "") - return s -} - -func valueToStringApi(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} - -func (m *Options) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowApi - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Options: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Options: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field TypeUrl", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowApi - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthApi - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.TypeUrl = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ConfigPath", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowApi - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthApi - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ConfigPath = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipApi(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthApi - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} - -func skipApi(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowApi - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowApi - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowApi - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthApi - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowApi - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipApi(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthApi = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowApi = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("api.proto", fileDescriptorApi) } - -var fileDescriptorApi = []byte{ - // 183 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4c, 0x2c, 0xc8, 0xd4, - 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x4d, 0x2e, 0xca, 0xd4, 0x2b, 0x2a, 0xcd, 0x2b, 0xc9, - 0xcc, 0x4d, 0xcd, 0x2f, 0x28, 0xc9, 0xcc, 0xcf, 0x2b, 0xd6, 0x2b, 0x33, 0x94, 0xd2, 0x4d, 0xcf, - 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xcf, 0x4f, 0xcf, 0xd7, 0x07, 0xab, - 0x4e, 0x2a, 0x4d, 0x03, 0xf3, 0xc0, 0x1c, 0x30, 0x0b, 0x62, 0x8a, 0x92, 0x2b, 0x17, 0xbb, 0x3f, - 0x44, 0xb3, 0x90, 0x24, 0x17, 0x47, 0x49, 0x65, 0x41, 0x6a, 0x7c, 0x69, 0x51, 0x8e, 0x04, 0xa3, - 0x02, 0xa3, 0x06, 0x67, 0x10, 0x3b, 0x88, 0x1f, 0x5a, 0x94, 0x23, 0x24, 0xcf, 0xc5, 0x9d, 0x9c, - 0x9f, 0x97, 0x96, 0x99, 0x1e, 0x5f, 0x90, 0x58, 0x92, 0x21, 0xc1, 0x04, 0x96, 0xe5, 0x82, 0x08, - 0x05, 0x24, 0x96, 0x64, 0x38, 0xc9, 0x9c, 0x78, 0x28, 0xc7, 0x78, 0xe3, 0xa1, 0x1c, 0x43, 0xc3, - 0x23, 0x39, 0xc6, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, - 0xc2, 0x63, 0x39, 0x86, 0x24, 0x36, 0xb0, 0x5d, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, - 0x00, 0xf2, 0x18, 0xbe, 0x00, 0x00, 0x00, -} diff --git a/pkg/shim/v2/runtimeoptions/BUILD b/pkg/shim/v2/runtimeoptions/BUILD new file mode 100644 index 0000000000..af84692a70 --- /dev/null +++ b/pkg/shim/v2/runtimeoptions/BUILD @@ -0,0 +1,18 @@ +load("//tools:defs.bzl", "go_test") + +package( + default_applicable_licenses = ["//:license"], + licenses = ["notice"], +) + +go_test( + name = "runtimeoptions_test", + size = "small", + srcs = ["runtimeoptions_test.go"], + deps = [ + "//pkg/shim/runtimeoptions", + "@com_github_containerd_containerd_api//runtime/task/v3:go_default_library", + "@com_github_containerd_typeurl_v2//:go_default_library", + "@com_github_gogo_protobuf//proto:go_default_library", + ], +) diff --git a/pkg/shim/v1/runtimeoptions/v14/runtimeoptions_test.go b/pkg/shim/v2/runtimeoptions/runtimeoptions_test.go similarity index 80% rename from pkg/shim/v1/runtimeoptions/v14/runtimeoptions_test.go rename to pkg/shim/v2/runtimeoptions/runtimeoptions_test.go index cfa28d1a39..e8f4e6c53e 100644 --- a/pkg/shim/v1/runtimeoptions/v14/runtimeoptions_test.go +++ b/pkg/shim/v2/runtimeoptions/runtimeoptions_test.go @@ -12,24 +12,25 @@ // See the License for the specific language governing permissions and // limitations under the License. -package v14 +package runtimeoptions_test import ( "bytes" "testing" - shim "github.com/containerd/containerd/runtime/v1/shim/v1" - "github.com/containerd/typeurl" + task "github.com/containerd/containerd/api/runtime/task/v3" + typeurl "github.com/containerd/typeurl/v2" "github.com/gogo/protobuf/proto" + "gvisor.dev/gvisor/pkg/shim/runtimeoptions" ) func TestCreateTaskRequest(t *testing.T) { // Serialize the top-level message. const encodedText = `options: < - type_url: "cri.runtimeoptions.v1.Options" + type_url: "runtimeoptions.Options" value: "\n\010type_url\022\013config_path" >` - got := &shim.CreateTaskRequest{} // Should have raw options. + got := &task.CreateTaskRequest{} // Should have raw options. if err := proto.UnmarshalText(encodedText, got); err != nil { t.Fatalf("unable to unmarshal text: %v", err) } @@ -40,14 +41,14 @@ func TestCreateTaskRequest(t *testing.T) { t.Logf("got: %s", string(textBuffer.Bytes())) // Check the options. - wantOptions := &Options{} + wantOptions := &runtimeoptions.Options{} wantOptions.TypeUrl = "type_url" wantOptions.ConfigPath = "config_path" gotMessage, err := typeurl.UnmarshalAny(got.Options) if err != nil { t.Fatalf("unable to unmarshal any: %v", err) } - gotOptions, ok := gotMessage.(*Options) + gotOptions, ok := gotMessage.(*runtimeoptions.Options) if !ok { t.Fatalf("got %v, want %v", gotMessage, wantOptions) }