cruntime

package
v1.33.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 29 Imported by: 12

Documentation

Overview

Package cruntime contains code specific to container runtimes

Index

Constants

View Source
const (
	CNIBinDir   = "/opt/cni/bin"
	CNICacheDir = "/var/lib/cni/cache"
)
View Source
const ExternalDockerCRISocket = "/var/run/cri-dockerd.sock"
View Source
const InternalDockerCRISocket = "/var/run/dockershim.sock"
View Source
const KubernetesContainerPrefix = "k8s_"

KubernetesContainerPrefix is the prefix of each Kubernetes container

Variables

View Source
var ErrContainerRuntimeNotRunning = errors.New("container runtime is not running")

ErrContainerRuntimeNotRunning is thrown when container runtime is not running

Functions

func CheckCompatibility added in v1.22.0

func CheckCompatibility(cr Manager) error

CheckCompatibility checks if the container runtime managed by "cr" is compatible with current minikube code returns: NewErrServiceVersion if not

func CheckKernelCompatibility added in v1.26.0

func CheckKernelCompatibility(cr CommandRunner, major, minor int) error

CheckKernelCompatibility returns an error when the kernel is older than the specified version.

func ContainerStatusCommand added in v1.7.0

func ContainerStatusCommand() string

ContainerStatusCommand works across container runtimes with good formatting

func ValidRuntimes added in v1.12.0

func ValidRuntimes() []string

ValidRuntimes lists the supported container runtimes

Types

type CRIO

type CRIO struct {
	Socket            string
	Runner            CommandRunner
	ImageRepository   string
	KubernetesVersion semver.Version
	Init              sysinit.Manager
}

CRIO contains CRIO runtime state

func (*CRIO) Active

func (r *CRIO) Active() bool

Active returns if CRIO is active on the host

func (*CRIO) Available

func (r *CRIO) Available() error

Available returns an error if it is not possible to use this runtime on a host

func (*CRIO) BuildImage added in v1.20.0

func (r *CRIO) BuildImage(src string, file string, tag string, push bool, env []string, opts []string) error

BuildImage builds an image into this runtime

func (*CRIO) CGroupDriver added in v1.7.0

func (r *CRIO) CGroupDriver() (string, error)

CGroupDriver returns cgroup driver ("cgroupfs" or "systemd")

func (*CRIO) ContainerLogCmd

func (r *CRIO) ContainerLogCmd(id string, len int, follow bool) string

ContainerLogCmd returns the command to retrieve the log for a container based on ID

func (*CRIO) Disable

func (r *CRIO) Disable() error

Disable idempotently disables CRIO on a host

func (*CRIO) Enable

func (r *CRIO) Enable(disOthers bool, cgroupDriver string, inUserNamespace bool) error

Enable idempotently enables CRIO on a host

func (*CRIO) ImageExists added in v1.6.0

func (r *CRIO) ImageExists(name string, sha string) bool

ImageExists checks if image exists based on image name and optionally image sha

func (*CRIO) ImagesPreloaded added in v1.12.3

func (r *CRIO) ImagesPreloaded(images []string) bool

ImagesPreloaded returns true if all images have been preloaded

func (*CRIO) KillContainers

func (r *CRIO) KillContainers(ids []string) error

KillContainers removes containers based on ID

func (*CRIO) KubeletOptions

func (r *CRIO) KubeletOptions() map[string]string

KubeletOptions returns kubelet options for a runtime.

func (*CRIO) ListContainers

func (r *CRIO) ListContainers(o ListContainersOptions) ([]string, error)

ListContainers returns a list of managed by this container runtime

func (*CRIO) ListImages added in v1.19.0

func (r *CRIO) ListImages(ListImagesOptions) ([]ListImage, error)

ListImages returns a list of images managed by this container runtime

func (*CRIO) LoadImage

func (r *CRIO) LoadImage(path string) error

LoadImage loads an image into this runtime

func (*CRIO) Name

func (r *CRIO) Name() string

Name is a human readable name for CRIO

func (*CRIO) PauseContainers added in v1.7.0

func (r *CRIO) PauseContainers(ids []string) error

PauseContainers pauses a running container based on ID

func (*CRIO) Preload added in v1.8.0

func (r *CRIO) Preload(cc config.ClusterConfig) error

Preload preloads the container runtime with k8s images

func (*CRIO) PullImage added in v1.20.0

func (r *CRIO) PullImage(name string) error

PullImage pulls an image

func (*CRIO) PushImage added in v1.23.0

func (r *CRIO) PushImage(name string) error

PushImage pushes an image

func (*CRIO) RemoveImage added in v1.19.0

func (r *CRIO) RemoveImage(name string) error

RemoveImage removes a image

func (*CRIO) SaveImage added in v1.20.0

func (r *CRIO) SaveImage(name string, path string) error

SaveImage saves an image from this runtime

func (*CRIO) SocketPath

func (r *CRIO) SocketPath() string

SocketPath returns the path to the socket file for CRIO

func (*CRIO) StopContainers

func (r *CRIO) StopContainers(ids []string) error

StopContainers stops containers based on ID

func (*CRIO) Style added in v1.1.1

func (r *CRIO) Style() style.Enum

Style is the console style for CRIO

func (*CRIO) SystemLogCmd added in v1.3.0

func (r *CRIO) SystemLogCmd(len int) string

SystemLogCmd returns the command to retrieve system logs

func (*CRIO) TagImage added in v1.23.0

func (r *CRIO) TagImage(source string, target string) error

TagImage tags an image in this runtime

func (*CRIO) UnpauseContainers added in v1.7.0

func (r *CRIO) UnpauseContainers(ids []string) error

UnpauseContainers unpauses a running container based on ID

func (*CRIO) Version added in v1.0.0

func (r *CRIO) Version() (string, error)

Version retrieves the current version of this runtime

type CommandRunner

type CommandRunner interface {
	// RunCmd is a blocking method that runs a command
	// Use this if you don't need to stream stdout and stderr in real-time
	RunCmd(cmd *exec.Cmd) (*command.RunResult, error)
	// StartCmd is a non-blocking method that starts a command
	// Use WaitCmd to block until the command is complete
	// Use this if you need to stream stdout and/or stderr in real-time
	StartCmd(cmd *exec.Cmd) (*command.StartedCmd, error)
	// WaitCmd blocks until the started command completes
	WaitCmd(sc *command.StartedCmd) (*command.RunResult, error)
	// Copy is a convenience method that runs a command to copy a file
	Copy(assets.CopyableFile) error
	// CopyFrom is a convenience method that runs a command to copy a file back
	CopyFrom(assets.CopyableFile) error
	// Remove is a convenience method that runs a command to remove a file
	Remove(assets.CopyableFile) error

	ReadableFile(sourcePath string) (assets.ReadableFile, error)
}

CommandRunner is the subset of command.Runner this package consumes

type Config

type Config struct {
	// Type of runtime to create ("docker, "crio", etc)
	Type string
	// Custom path to a socket file
	Socket string
	// Runner is the CommandRunner object to execute commands with
	Runner CommandRunner
	// NetworkPlugin name of networking plugin ("cni")
	NetworkPlugin string
	// ImageRepository image repository to download image from
	ImageRepository string
	// KubernetesVersion Kubernetes version
	KubernetesVersion semver.Version
	// InsecureRegistry list of insecure registries
	InsecureRegistry []string
	// GPUs add GPU devices to the container
	GPUs bool
}

Config is runtime configuration

type ContainerState added in v1.7.0

type ContainerState int

ContainerState is the run state of a container

const (
	// All is all of the states
	All ContainerState = iota
	// Running is only running
	Running
	// Paused is only paused
	Paused
)

func (ContainerState) String added in v1.7.0

func (cs ContainerState) String() string

type Containerd

type Containerd struct {
	Socket            string
	Runner            CommandRunner
	ImageRepository   string
	KubernetesVersion semver.Version
	Init              sysinit.Manager
	InsecureRegistry  []string
}

Containerd contains containerd runtime state

func (*Containerd) Active

func (r *Containerd) Active() bool

Active returns if containerd is active on the host

func (*Containerd) Available

func (r *Containerd) Available() error

Available returns an error if it is not possible to use this runtime on a host

func (*Containerd) BuildImage added in v1.20.0

func (r *Containerd) BuildImage(src string, file string, tag string, push bool, env []string, opts []string) error

BuildImage builds an image into this runtime

func (*Containerd) CGroupDriver added in v1.7.0

func (r *Containerd) CGroupDriver() (string, error)

CGroupDriver returns cgroup driver ("cgroupfs" or "systemd")

func (*Containerd) ContainerLogCmd

func (r *Containerd) ContainerLogCmd(id string, len int, follow bool) string

ContainerLogCmd returns the command to retrieve the log for a container based on ID

func (*Containerd) Disable

func (r *Containerd) Disable() error

Disable idempotently disables containerd on a host

func (*Containerd) Enable

func (r *Containerd) Enable(disOthers bool, cgroupDriver string, inUserNamespace bool) error

Enable idempotently enables containerd on a host It is also called by docker.Enable() - if bound to containerd, to enforce proper containerd configuration completed by service restart.

func (*Containerd) ImageExists added in v1.6.0

func (r *Containerd) ImageExists(name string, sha string) bool

ImageExists checks if image exists based on image name and optionally image sha

func (*Containerd) ImagesPreloaded added in v1.12.3

func (r *Containerd) ImagesPreloaded(images []string) bool

ImagesPreloaded returns true if all images have been preloaded

func (*Containerd) KillContainers

func (r *Containerd) KillContainers(ids []string) error

KillContainers removes containers based on ID

func (*Containerd) KubeletOptions

func (r *Containerd) KubeletOptions() map[string]string

KubeletOptions returns kubelet options for a containerd

func (*Containerd) ListContainers

func (r *Containerd) ListContainers(o ListContainersOptions) ([]string, error)

ListContainers returns a list of managed by this container runtime

func (*Containerd) ListImages added in v1.19.0

func (r *Containerd) ListImages(ListImagesOptions) ([]ListImage, error)

ListImages lists images managed by this container runtime

func (*Containerd) LoadImage

func (r *Containerd) LoadImage(path string) error

LoadImage loads an image into this runtime

func (*Containerd) Name

func (r *Containerd) Name() string

Name is a human readable name for containerd

func (*Containerd) PauseContainers added in v1.7.0

func (r *Containerd) PauseContainers(ids []string) error

PauseContainers pauses a running container based on ID

func (*Containerd) Preload added in v1.8.0

func (r *Containerd) Preload(cc config.ClusterConfig) error

Preload preloads the container runtime with k8s images

func (*Containerd) PullImage added in v1.20.0

func (r *Containerd) PullImage(name string) error

PullImage pulls an image into this runtime

func (*Containerd) PushImage added in v1.23.0

func (r *Containerd) PushImage(name string) error

PushImage pushes an image

func (*Containerd) RemoveImage added in v1.19.0

func (r *Containerd) RemoveImage(name string) error

RemoveImage removes a image

func (*Containerd) Restart added in v1.10.0

func (r *Containerd) Restart() error

Restart restarts this container runtime on a host

func (*Containerd) SaveImage added in v1.20.0

func (r *Containerd) SaveImage(name string, path string) error

SaveImage save an image from this runtime

func (*Containerd) SocketPath

func (r *Containerd) SocketPath() string

SocketPath returns the path to the socket file for containerd

func (*Containerd) StopContainers

func (r *Containerd) StopContainers(ids []string) error

StopContainers stops containers based on ID

func (*Containerd) Style added in v1.1.1

func (r *Containerd) Style() style.Enum

Style is the console style for containerd

func (*Containerd) SystemLogCmd added in v1.3.0

func (r *Containerd) SystemLogCmd(len int) string

SystemLogCmd returns the command to retrieve system logs

func (*Containerd) TagImage added in v1.23.0

func (r *Containerd) TagImage(source string, target string) error

TagImage tags an image in this runtime

func (*Containerd) UnpauseContainers added in v1.7.0

func (r *Containerd) UnpauseContainers(ids []string) error

UnpauseContainers unpauses a running container based on ID

func (*Containerd) Version added in v1.0.0

func (r *Containerd) Version() (string, error)

Version retrieves the current version of this runtime

type Docker

type Docker struct {
	Socket            string
	Runner            CommandRunner
	NetworkPlugin     string
	ImageRepository   string
	KubernetesVersion semver.Version
	Init              sysinit.Manager
	UseCRI            bool
	CRIService        string
	GPUs              bool
}

Docker contains Docker runtime state

func (*Docker) Active

func (r *Docker) Active() bool

Active returns if docker is active on the host

func (*Docker) Available

func (r *Docker) Available() error

Available returns an error if it is not possible to use this runtime on a host

func (*Docker) BuildImage added in v1.20.0

func (r *Docker) BuildImage(src string, file string, tag string, push bool, env []string, opts []string) error

BuildImage builds an image into this runtime

func (*Docker) CGroupDriver added in v1.7.0

func (r *Docker) CGroupDriver() (string, error)

CGroupDriver returns cgroup driver ("cgroupfs" or "systemd")

func (*Docker) ContainerLogCmd

func (r *Docker) ContainerLogCmd(id string, len int, follow bool) string

ContainerLogCmd returns the command to retrieve the log for a container based on ID

func (*Docker) Disable

func (r *Docker) Disable() error

Disable idempotently disables Docker on a host

func (*Docker) Enable

func (r *Docker) Enable(disOthers bool, cgroupDriver string, inUserNamespace bool) error

Enable idempotently enables Docker on a host

func (*Docker) ImageExists added in v1.6.0

func (r *Docker) ImageExists(name string, sha string) bool

ImageExists checks if image exists based on image name and optionally image sha

func (*Docker) ImagesPreloaded added in v1.12.3

func (r *Docker) ImagesPreloaded(images []string) bool

ImagesPreloaded returns true if all images have been preloaded

func (*Docker) KillContainers

func (r *Docker) KillContainers(ids []string) error

KillContainers forcibly removes a running container based on ID

func (*Docker) KubeletOptions

func (r *Docker) KubeletOptions() map[string]string

KubeletOptions returns kubelet options for a runtime.

func (*Docker) ListContainers

func (r *Docker) ListContainers(o ListContainersOptions) ([]string, error)

ListContainers returns a list of containers

func (*Docker) ListImages added in v1.19.0

func (r *Docker) ListImages(ListImagesOptions) ([]ListImage, error)

ListImages returns a list of images managed by this container runtime

func (*Docker) LoadImage

func (r *Docker) LoadImage(path string) error

LoadImage loads an image into this runtime

func (*Docker) Name

func (r *Docker) Name() string

Name is a human readable name for Docker

func (*Docker) PauseContainers added in v1.7.0

func (r *Docker) PauseContainers(ids []string) error

PauseContainers pauses a running container based on ID

func (*Docker) Preload added in v1.8.0

func (r *Docker) Preload(cc config.ClusterConfig) error

Preload preloads docker with k8s images: 1. Copy over the preloaded tarball into the VM 2. Extract the preloaded tarball to the correct directory 3. Remove the tarball within the VM

func (*Docker) PullImage added in v1.20.0

func (r *Docker) PullImage(name string) error

PullImage pulls an image

func (*Docker) PushImage added in v1.23.0

func (r *Docker) PushImage(name string) error

PushImage pushes an image

func (*Docker) RemoveImage added in v1.19.0

func (r *Docker) RemoveImage(name string) error

RemoveImage removes a image

func (*Docker) Restart added in v1.8.0

func (r *Docker) Restart() error

Restart restarts Docker on a host

func (*Docker) SaveImage added in v1.20.0

func (r *Docker) SaveImage(name string, path string) error

SaveImage saves an image from this runtime

func (*Docker) SocketPath

func (r *Docker) SocketPath() string

SocketPath returns the path to the socket file for Docker

func (*Docker) StopContainers

func (r *Docker) StopContainers(ids []string) error

StopContainers stops a running container based on ID

func (*Docker) Style added in v1.1.1

func (r *Docker) Style() style.Enum

Style is the console style for Docker

func (*Docker) SystemLogCmd added in v1.3.0

func (r *Docker) SystemLogCmd(len int) string

SystemLogCmd returns the command to retrieve system logs

func (*Docker) TagImage added in v1.23.0

func (r *Docker) TagImage(source string, target string) error

TagImage tags an image in this runtime

func (*Docker) UnpauseContainers added in v1.7.0

func (r *Docker) UnpauseContainers(ids []string) error

UnpauseContainers unpauses a container based on ID

func (*Docker) Version added in v1.0.0

func (r *Docker) Version() (string, error)

Version retrieves the current version of this runtime

type ErrISOFeature added in v1.8.2

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

ErrISOFeature is the error returned when disk image is missing features

func NewErrISOFeature added in v1.8.2

func NewErrISOFeature(missing string) *ErrISOFeature

NewErrISOFeature creates a new ErrISOFeature

func (*ErrISOFeature) Error added in v1.8.2

func (e *ErrISOFeature) Error() string

type ErrServiceVersion added in v1.22.0

type ErrServiceVersion struct {
	// Service is the name of the incompatible service
	Service string
	// Installed is the installed version of Service
	Installed string
	// Required is the minimum required version of Service
	Required string
}

ErrServiceVersion is the error returned when disk image has incompatible version of service

func NewErrServiceVersion added in v1.22.0

func NewErrServiceVersion(svc, required, installed string) *ErrServiceVersion

NewErrServiceVersion creates a new ErrServiceVersion

func (ErrServiceVersion) Error added in v1.22.0

func (e ErrServiceVersion) Error() string

type ListContainersOptions added in v1.19.0

type ListContainersOptions struct {
	// State is the container state to filter by (All, Running, Paused)
	State ContainerState
	// Name is a name filter
	Name string
	// Namespaces is the namespaces to look into
	Namespaces []string
}

ListContainersOptions are the options to use for listing containers

type ListImage added in v1.25.0

type ListImage struct {
	ID          string   `json:"id" yaml:"id"`
	RepoDigests []string `json:"repoDigests" yaml:"repoDigests"`
	RepoTags    []string `json:"repoTags" yaml:"repoTags"`
	Size        string   `json:"size" yaml:"size"`
}

type ListImagesOptions added in v1.19.0

type ListImagesOptions struct {
}

ListImagesOptions are the options to use for listing images

type Manager

type Manager interface {
	// Name is a human readable name for a runtime
	Name() string
	// Version retrieves the current version of this runtime
	Version() (string, error)
	// Enable idempotently enables this runtime on a host
	Enable(bool, string, bool) error
	// Disable idempotently disables this runtime on a host
	Disable() error
	// Active returns whether or not a runtime is active on a host
	Active() bool
	// Available returns an error if it is not possible to use this runtime on a host
	Available() error
	// Style is an associated StyleEnum for Name()
	Style() style.Enum

	// CGroupDriver returns cgroup driver ("cgroupfs" or "systemd")
	CGroupDriver() (string, error)
	// KubeletOptions returns kubelet options for a runtime.
	KubeletOptions() map[string]string
	// SocketPath returns the path to the socket file for a given runtime
	SocketPath() string

	// Load an image idempotently into the runtime on a host
	LoadImage(string) error
	// Pull an image to the runtime from the container registry
	PullImage(string) error
	// Build an image idempotently into the runtime on a host
	BuildImage(string, string, string, bool, []string, []string) error
	// Save an image from the runtime on a host
	SaveImage(string, string) error
	// Tag an image
	TagImage(string, string) error
	// Push an image from the runtime to the container registry
	PushImage(string) error

	// ImageExists takes image name and optionally image sha to check if an image exists
	ImageExists(string, string) bool
	// ListImages returns a list of images managed by this container runtime
	ListImages(ListImagesOptions) ([]ListImage, error)

	// RemoveImage remove image based on name
	RemoveImage(string) error

	// ListContainers returns a list of containers managed by this container runtime
	ListContainers(ListContainersOptions) ([]string, error)
	// KillContainers removes containers based on ID
	KillContainers([]string) error
	// StopContainers stops containers based on ID
	StopContainers([]string) error
	// PauseContainers pauses containers based on ID
	PauseContainers([]string) error
	// UnpauseContainers unpauses containers based on ID
	UnpauseContainers([]string) error
	// ContainerLogCmd returns the command to retrieve the log for a container based on ID
	ContainerLogCmd(string, int, bool) string
	// SystemLogCmd returns the command to return the system logs
	SystemLogCmd(int) string
	// Preload preloads the container runtime with k8s images
	Preload(config.ClusterConfig) error
	// ImagesPreloaded returns true if all images have been preloaded
	ImagesPreloaded([]string) bool
}

Manager is a common interface for container runtimes

func New

func New(c Config) (Manager, error)

New returns an appropriately configured runtime

Jump to

Keyboard shortcuts

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