Move local sandbox controller under plugins package
Add options to sandbox controller interface. Update sandbox controller interface to fully utilize sandbox controller interface. Move grpc error conversion to service. Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
@@ -20,23 +20,57 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/api/types"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/containerd/typeurl"
|
||||
)
|
||||
|
||||
type CreateOptions struct {
|
||||
Rootfs []*types.Mount
|
||||
Options typeurl.Any
|
||||
}
|
||||
|
||||
type CreateOpt func(*CreateOptions)
|
||||
|
||||
// WithRootFS is used to create a sandbox with the provided rootfs mount
|
||||
// TODO: Switch to mount.Mount once target added
|
||||
func WithRootFS(m []*types.Mount) CreateOpt {
|
||||
return func(co *CreateOptions) {
|
||||
co.Rootfs = m
|
||||
}
|
||||
}
|
||||
|
||||
func WithOptions(a typeurl.Any) CreateOpt {
|
||||
return func(co *CreateOptions) {
|
||||
co.Options = a
|
||||
}
|
||||
}
|
||||
|
||||
type StopOptions struct {
|
||||
Timeout *time.Duration
|
||||
}
|
||||
|
||||
type StopOpt func(*StopOptions)
|
||||
|
||||
func WithTimeout(timeout time.Duration) StopOpt {
|
||||
return func(so *StopOptions) {
|
||||
so.Timeout = &timeout
|
||||
}
|
||||
}
|
||||
|
||||
// Controller is an interface to manage sandboxes at runtime.
|
||||
// When running in sandbox mode, shim expected to implement `SandboxService`.
|
||||
// Shim lifetimes are now managed manually via sandbox API by the containerd's client.
|
||||
type Controller interface {
|
||||
// Create is used to initialize sandbox environment.
|
||||
Create(ctx context.Context, sandboxID string) error
|
||||
// Create is used to initialize sandbox environment. (mounts, any)
|
||||
Create(ctx context.Context, sandboxID string, opts ...CreateOpt) error
|
||||
// Start will start previously created sandbox.
|
||||
Start(ctx context.Context, sandboxID string) (ControllerInstance, error)
|
||||
// Platform returns target sandbox OS that will be used by Controller.
|
||||
// containerd will rely on this to generate proper OCI spec.
|
||||
Platform(_ctx context.Context, _sandboxID string) (platforms.Platform, error)
|
||||
// Stop will stop sandbox instance
|
||||
Stop(ctx context.Context, sandboxID string) error
|
||||
Stop(ctx context.Context, sandboxID string, opts ...StopOpt) error
|
||||
// Wait blocks until sandbox process exits.
|
||||
Wait(ctx context.Context, sandboxID string) (ExitStatus, error)
|
||||
// Status will query sandbox process status. It is heavier than Ping call and must be used whenever you need to
|
||||
|
Reference in New Issue
Block a user