shim

package
v1.7.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2023 License: Apache-2.0 Imports: 40 Imported by: 714

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAddress = errors.New("no shim address")

ErrNoAddress is returned when the address file has no content

Functions

func AdjustOOMScore added in v1.3.0

func AdjustOOMScore(pid int) error

AdjustOOMScore sets the OOM score for the process to the parents OOM score +1 to ensure that they parent has a lower* score than the shim if not already at the maximum OOM Score

func AnonDialer

func AnonDialer(address string, timeout time.Duration) (net.Conn, error)

AnonDialer returns a dialer for a socket

func AnonReconnectDialer added in v1.3.0

func AnonReconnectDialer(address string, timeout time.Duration) (net.Conn, error)

AnonReconnectDialer returns a dialer for an existing socket on reconnection

func BinaryName

func BinaryName(runtime string) string

BinaryName returns the shim binary name from the runtime name, empty string returns means runtime name is invalid

func BinaryPath added in v1.5.0

func BinaryPath(runtime string) string

BinaryPath returns the full path for the shim binary from the runtime name, empty string returns means runtime name is invalid

func CanConnect added in v1.3.9

func CanConnect(address string) bool

CanConnect returns true if the socket provided at the address is accepting new connections

func Command

func Command(ctx context.Context, config *CommandConfig) (*exec.Cmd, error)

Command returns the shim command with the provided args and configuration

func Connect

func Connect(address string, d func(string, time.Duration) (net.Conn, error)) (net.Conn, error)

Connect to the provided address

func NewSocket

func NewSocket(address string) (*net.UnixListener, error)

NewSocket returns a new socket

func ReadAddress added in v1.3.0

func ReadAddress(path string) (string, error)

ReadAddress returns the shim's socket address from the path

func ReadRuntimeOptions added in v1.7.0

func ReadRuntimeOptions[T any](reader io.Reader) (T, error)

ReadRuntimeOptions reads config bytes from io.Reader and unmarshals it into the provided type. The type must be registered with typeurl.

The function will return ErrNotFound, if the config is not provided. And ErrInvalidArgument, if unable to cast the config to the provided type T.

func RemoveSocket added in v1.3.9

func RemoveSocket(address string) error

RemoveSocket removes the socket at the specified address if it exists on the filesystem

func Run

func Run(name string, initFunc Init, opts ...BinaryOpts)

Run initializes and runs a shim server TODO(2.0): Remove function

func RunManager added in v1.6.0

func RunManager(ctx context.Context, manager Manager, opts ...BinaryOpts)

RunManager initializes and runs a shim server. TODO(2.0): Rename to Run

func SocketAddress

func SocketAddress(ctx context.Context, socketPath, id string) (string, error)

SocketAddress returns a socket address

func SocketEaddrinuse added in v1.3.9

func SocketEaddrinuse(err error) bool

SocketEaddrinuse returns true if the provided error is caused by the EADDRINUSE error number

func WriteAddress

func WriteAddress(path, address string) error

WriteAddress writes a address file atomically

func WritePidFile

func WritePidFile(path string, pid int) error

WritePidFile writes a pid file atomically

Types

type BinaryOpts added in v1.3.0

type BinaryOpts func(*Config)

BinaryOpts allows the configuration of a shims binary setup

type BootstrapParams added in v1.7.0

type BootstrapParams struct {
	// Version is the version of shim parameters (expected 2 for shim v2)
	Version int `json:"version"`
	// Address is a address containerd should use to connect to shim.
	Address string `json:"address"`
	// Protocol is either TTRPC or GRPC.
	Protocol string `json:"protocol"`
}

BootstrapParams is a JSON payload returned in stdout from shim.Start call.

type CommandConfig added in v1.6.0

type CommandConfig struct {
	Runtime      string
	Address      string
	TTRPCAddress string
	Path         string
	SchedCore    bool
	Args         []string
	Opts         *types.Any
}

type Config added in v1.3.0

type Config struct {
	// NoSubreaper disables setting the shim as a child subreaper
	NoSubreaper bool
	// NoReaper disables the shim binary from reaping any child process implicitly
	NoReaper bool
	// NoSetupLogger disables automatic configuration of logrus to use the shim FIFO
	NoSetupLogger bool
}

Config of shim binary options provided by shim implementations

type Init

type Init func(context.Context, string, Publisher, func()) (Shim, error)

Init func for the creation of a shim server TODO(2.0): Remove init function

type Manager added in v1.6.0

type Manager interface {
	Name() string
	Start(ctx context.Context, id string, opts StartOpts) (string, error)
	Stop(ctx context.Context, id string) (StopStatus, error)
}

Manager is the interface which manages the shim process

type Opts

type Opts struct {
	BundlePath string
	Debug      bool
}

Opts are context options associated with the shim invocation.

type OptsKey

type OptsKey struct{}

OptsKey is the context key for the Opts value.

type Publisher added in v1.3.0

type Publisher interface {
	events.Publisher
	io.Closer
}

Publisher for events

type RemoteEventsPublisher added in v1.3.0

type RemoteEventsPublisher struct {
	// contains filtered or unexported fields
}

RemoteEventsPublisher forwards events to a ttrpc server

func NewPublisher added in v1.3.0

func NewPublisher(address string) (*RemoteEventsPublisher, error)

NewPublisher creates a new remote events publisher

func (*RemoteEventsPublisher) Close added in v1.3.0

func (l *RemoteEventsPublisher) Close() (err error)

Close closes the remote connection and closes the done channel

func (*RemoteEventsPublisher) Done added in v1.3.0

func (l *RemoteEventsPublisher) Done() <-chan struct{}

Done returns a channel which closes when done

func (*RemoteEventsPublisher) Publish added in v1.3.0

func (l *RemoteEventsPublisher) Publish(ctx context.Context, topic string, event events.Event) error

Publish publishes the event by forwarding it to the configured ttrpc server

type Shim

type Shim interface {
	shimapi.TaskService
	Cleanup(ctx context.Context) (*shimapi.DeleteResponse, error)
	StartShim(ctx context.Context, opts StartOpts) (string, error)
}

Shim server interface TODO(2.0): Remove unified shim interface

type StartOpts added in v1.5.0

type StartOpts struct {
	ID               string // TODO(2.0): Remove ID, passed directly to start for call symmetry
	ContainerdBinary string // TODO(2.0): Remove ContainerdBinary, use the TTRPC_ADDRESS env to forward events
	Address          string
	TTRPCAddress     string
	Debug            bool
}

StartOpts describes shim start configuration received from containerd

type StopStatus added in v1.6.0

type StopStatus struct {
	Pid        int
	ExitStatus int
	ExitedAt   time.Time
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL