Expose shim instance version

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko 2023-10-13 10:53:03 -07:00
parent f66c46806a
commit 7a2d801d62
No known key found for this signature in database
2 changed files with 18 additions and 7 deletions

View File

@ -140,8 +140,9 @@ func (b *binary) Start(ctx context.Context, opts *types.Any, onClose func()) (_
} }
return &shim{ return &shim{
bundle: b.bundle, bundle: b.bundle,
client: conn, client: conn,
version: params.Version,
}, nil }, nil
} }

View File

@ -177,6 +177,9 @@ func cleanupAfterDeadShim(ctx context.Context, id string, rt *runtime.NSMap[Shim
}) })
} }
// CurrentShimVersion is the latest shim version supported by containerd (e.g. TaskService v3).
const CurrentShimVersion = 3
// ShimInstance represents running shim process managed by ShimManager. // ShimInstance represents running shim process managed by ShimManager.
type ShimInstance interface { type ShimInstance interface {
io.Closer io.Closer
@ -192,6 +195,8 @@ type ShimInstance interface {
Client() any Client() any
// Delete will close the client and remove bundle from disk. // Delete will close the client and remove bundle from disk.
Delete(ctx context.Context) error Delete(ctx context.Context) error
// Version returns shim's features compatibility version.
Version() int
} }
func parseStartResponse(ctx context.Context, response []byte) (client.BootstrapParams, error) { func parseStartResponse(ctx context.Context, response []byte) (client.BootstrapParams, error) {
@ -201,9 +206,10 @@ func parseStartResponse(ctx context.Context, response []byte) (client.BootstrapP
// Use TTRPC for legacy shims // Use TTRPC for legacy shims
params.Address = string(response) params.Address = string(response)
params.Protocol = "ttrpc" params.Protocol = "ttrpc"
params.Version = 2
} }
if params.Version > 2 { if params.Version > CurrentShimVersion {
return client.BootstrapParams{}, fmt.Errorf("unsupported shim version (%d): %w", params.Version, errdefs.ErrNotImplemented) return client.BootstrapParams{}, fmt.Errorf("unsupported shim version (%d): %w", params.Version, errdefs.ErrNotImplemented)
} }
@ -303,8 +309,9 @@ func (gc *grpcConn) UserOnCloseWait(ctx context.Context) error {
} }
type shim struct { type shim struct {
bundle *Bundle bundle *Bundle
client any client any
version int
} }
var _ ShimInstance = (*shim)(nil) var _ ShimInstance = (*shim)(nil)
@ -314,6 +321,10 @@ func (s *shim) ID() string {
return s.bundle.ID return s.bundle.ID
} }
func (s *shim) Version() int {
return s.version
}
func (s *shim) Namespace() string { func (s *shim) Namespace() string {
return s.bundle.Namespace return s.bundle.Namespace
} }
@ -379,8 +390,7 @@ type shimTask struct {
} }
func newShimTask(shim ShimInstance) (*shimTask, error) { func newShimTask(shim ShimInstance) (*shimTask, error) {
// TODO: Fix version taskClient, err := NewTaskClient(shim.Client(), shim.Version())
taskClient, err := NewTaskClient(shim.Client(), 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }