mirror of
https://github.com/containerd/containerd.git
synced 2026-06-30 19:58:29 +00:00
Deprecate old pkg/shim interfaces
Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
committed by
Mike Brown
parent
3fbdb132bf
commit
243cab594e
@@ -25,5 +25,5 @@ import (
|
||||
|
||||
func main() {
|
||||
// init and execute the shim
|
||||
shim.Run(context.Background(), example.NewManager("io.containerd.example.v1"))
|
||||
shim.RunShim(context.Background(), example.NewManager("io.containerd.example.v1"))
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
bootapi "github.com/containerd/containerd/api/runtime/bootstrap/v1"
|
||||
taskAPI "github.com/containerd/containerd/api/runtime/task/v2"
|
||||
apitypes "github.com/containerd/containerd/api/types"
|
||||
ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types"
|
||||
@@ -55,7 +56,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func NewManager(name string) shim.Manager {
|
||||
func NewManager(name string) shim.Shim {
|
||||
return manager{name: name}
|
||||
}
|
||||
|
||||
@@ -67,7 +68,7 @@ func (m manager) Name() string {
|
||||
return m.name
|
||||
}
|
||||
|
||||
func (m manager) Start(ctx context.Context, opts *shim.BootstrapParams) (*shim.BootstrapResult, error) {
|
||||
func (m manager) Start(ctx context.Context, opts *bootapi.BootstrapParams) (*bootapi.BootstrapResult, error) {
|
||||
return nil, errdefs.ErrNotImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
|
||||
crmetadata "github.com/checkpoint-restore/checkpointctl/lib"
|
||||
eventstypes "github.com/containerd/containerd/api/events"
|
||||
bootapi "github.com/containerd/containerd/api/runtime/bootstrap/v1"
|
||||
task "github.com/containerd/containerd/api/runtime/task/v3"
|
||||
"github.com/containerd/containerd/api/types"
|
||||
"github.com/containerd/errdefs"
|
||||
@@ -219,8 +220,8 @@ type clientVersionDowngrader interface {
|
||||
Downgrade() error
|
||||
}
|
||||
|
||||
func parseStartResponse(response []byte) (*client.BootstrapResult, error) {
|
||||
var params client.BootstrapResult
|
||||
func parseStartResponse(response []byte) (*bootapi.BootstrapResult, error) {
|
||||
var params bootapi.BootstrapResult
|
||||
|
||||
if err := json.Unmarshal(response, ¶ms); err != nil || params.Version < 2 {
|
||||
// Use TTRPC for legacy shims
|
||||
@@ -237,7 +238,7 @@ func parseStartResponse(response []byte) (*client.BootstrapResult, error) {
|
||||
}
|
||||
|
||||
// writeBootstrapParams writes shim's bootstrap configuration (e.g. how to connect, version, etc).
|
||||
func writeBootstrapParams(path string, params *client.BootstrapResult) error {
|
||||
func writeBootstrapParams(path string, params *bootapi.BootstrapResult) error {
|
||||
path, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -262,7 +263,7 @@ func writeBootstrapParams(path string, params *client.BootstrapResult) error {
|
||||
return f.Close()
|
||||
}
|
||||
|
||||
func readBootstrapParams(path string) (*client.BootstrapResult, error) {
|
||||
func readBootstrapParams(path string) (*bootapi.BootstrapResult, error) {
|
||||
path, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -278,7 +279,7 @@ func readBootstrapParams(path string) (*client.BootstrapResult, error) {
|
||||
|
||||
// makeConnection creates a new TTRPC or GRPC connection object from address.
|
||||
// address can be either a socket path for TTRPC or JSON serialized BootstrapParams.
|
||||
func makeConnection(ctx context.Context, id string, params *client.BootstrapResult, onClose func()) (_ io.Closer, retErr error) {
|
||||
func makeConnection(ctx context.Context, id string, params *bootapi.BootstrapResult, onClose func()) (_ io.Closer, retErr error) {
|
||||
log.G(ctx).WithFields(log.Fields{
|
||||
"address": params.Address,
|
||||
"protocol": params.Protocol,
|
||||
|
||||
@@ -33,6 +33,7 @@ import (
|
||||
"github.com/containerd/plugin/registry"
|
||||
"github.com/containerd/typeurl/v2"
|
||||
|
||||
bootapi "github.com/containerd/containerd/api/runtime/bootstrap/v1"
|
||||
"github.com/containerd/containerd/v2/core/containers"
|
||||
"github.com/containerd/containerd/v2/core/events/exchange"
|
||||
"github.com/containerd/containerd/v2/core/metadata"
|
||||
@@ -169,7 +170,7 @@ func (m *ShimManager) ID() string {
|
||||
func (m *ShimManager) Start(ctx context.Context, id string, bundle *Bundle, opts runtime.CreateOpts) (_ ShimInstance, retErr error) {
|
||||
shouldInvokeShimBinary := false
|
||||
|
||||
var params = &shimbinary.BootstrapResult{}
|
||||
var params = &bootapi.BootstrapResult{}
|
||||
if opts.SandboxID != "" {
|
||||
_, sbErr := m.sandboxStore.Get(ctx, opts.SandboxID)
|
||||
if sbErr != nil {
|
||||
@@ -193,7 +194,7 @@ func (m *ShimManager) Start(ctx context.Context, id string, bundle *Bundle, opts
|
||||
return nil, fmt.Errorf("the scheme of sandbox address should be in " +
|
||||
" the form of <protocol>+<unix|vsock|tcp>, i.e. ttrpc+unix or grpc+vsock")
|
||||
}
|
||||
params = &shimbinary.BootstrapResult{
|
||||
params = &bootapi.BootstrapResult{
|
||||
Version: int32(opts.Version),
|
||||
Protocol: protocol,
|
||||
Address: address,
|
||||
@@ -310,7 +311,7 @@ func (m *ShimManager) startShim(ctx context.Context, bundle *Bundle, id string,
|
||||
// restoreBootstrapParams reads bootstrap.json to restore shim configuration.
|
||||
// If its an old shim, this will perform migration - read address file and write default bootstrap
|
||||
// configuration (version = 2, protocol = ttrpc, and address).
|
||||
func restoreBootstrapParams(bundlePath string) (*shimbinary.BootstrapResult, error) {
|
||||
func restoreBootstrapParams(bundlePath string) (*bootapi.BootstrapResult, error) {
|
||||
filePath := filepath.Join(bundlePath, "bootstrap.json")
|
||||
|
||||
// Read bootstrap.json if exists
|
||||
@@ -327,7 +328,7 @@ func restoreBootstrapParams(bundlePath string) (*shimbinary.BootstrapResult, err
|
||||
return nil, fmt.Errorf("unable to migrate shim: failed to get socket address for bundle %s: %w", bundlePath, err)
|
||||
}
|
||||
|
||||
params := shimbinary.BootstrapResult{
|
||||
params := bootapi.BootstrapResult{
|
||||
Version: 2,
|
||||
Address: address,
|
||||
Protocol: "ttrpc",
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
client "github.com/containerd/containerd/v2/pkg/shim"
|
||||
bootapi "github.com/containerd/containerd/api/runtime/bootstrap/v1"
|
||||
"github.com/containerd/errdefs"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -31,13 +31,13 @@ func TestParseStartResponse(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
Name string
|
||||
Response string
|
||||
Expected client.BootstrapResult
|
||||
Expected bootapi.BootstrapResult
|
||||
Err error
|
||||
}{
|
||||
{
|
||||
Name: "v2 shim",
|
||||
Response: "/somedirectory/somesocket",
|
||||
Expected: client.BootstrapResult{
|
||||
Expected: bootapi.BootstrapResult{
|
||||
Version: 2,
|
||||
Address: "/somedirectory/somesocket",
|
||||
Protocol: "ttrpc",
|
||||
@@ -46,7 +46,7 @@ func TestParseStartResponse(t *testing.T) {
|
||||
{
|
||||
Name: "v2 shim using grpc",
|
||||
Response: `{"version":2,"address":"/somedirectory/somesocket","protocol":"grpc"}`,
|
||||
Expected: client.BootstrapResult{
|
||||
Expected: bootapi.BootstrapResult{
|
||||
Version: 2,
|
||||
Address: "/somedirectory/somesocket",
|
||||
Protocol: "grpc",
|
||||
@@ -55,7 +55,7 @@ func TestParseStartResponse(t *testing.T) {
|
||||
{
|
||||
Name: "v2 shim using ttrpc",
|
||||
Response: `{"version":2,"address":"/somedirectory/somesocket","protocol":"ttrpc"}`,
|
||||
Expected: client.BootstrapResult{
|
||||
Expected: bootapi.BootstrapResult{
|
||||
Version: 2,
|
||||
Address: "/somedirectory/somesocket",
|
||||
Protocol: "ttrpc",
|
||||
@@ -64,7 +64,7 @@ func TestParseStartResponse(t *testing.T) {
|
||||
{
|
||||
Name: "invalid shim v2 response",
|
||||
Response: `{"address":"/somedirectory/somesocket","protocol":"ttrpc"}`,
|
||||
Expected: client.BootstrapResult{
|
||||
Expected: bootapi.BootstrapResult{
|
||||
Version: 2,
|
||||
Address: `{"address":"/somedirectory/somesocket","protocol":"ttrpc"}`,
|
||||
Protocol: "ttrpc",
|
||||
@@ -73,7 +73,7 @@ func TestParseStartResponse(t *testing.T) {
|
||||
{
|
||||
Name: "later unsupported shim",
|
||||
Response: `{"Version": 4,"Address":"/somedirectory/somesocket","Protocol":"ttrpc"}`,
|
||||
Expected: client.BootstrapResult{},
|
||||
Expected: bootapi.BootstrapResult{},
|
||||
Err: errdefs.ErrNotImplemented,
|
||||
},
|
||||
} {
|
||||
@@ -109,7 +109,7 @@ func TestRestoreBootstrapParams(t *testing.T) {
|
||||
restored, err := restoreBootstrapParams(bundlePath)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := &client.BootstrapResult{
|
||||
expected := &bootapi.BootstrapResult{
|
||||
Version: 2,
|
||||
Address: "unix://123",
|
||||
Protocol: "ttrpc",
|
||||
|
||||
Reference in New Issue
Block a user