oci

package
v1.23.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBindIPV4 is The default IP the container will listen on.
	DefaultBindIPV4 = "127.0.0.1"
	// Docker is docker
	Docker = "docker"
	// Podman is podman
	Podman = "podman"
	// ProfileLabelKey is applied to any container or volume created by a specific minikube profile name.minikube.sigs.k8s.io=PROFILE_NAME
	ProfileLabelKey = "name.minikube.sigs.k8s.io"
	// NodeLabelKey is applied to each volume so it can be referred to by name
	NodeLabelKey = "mode.minikube.sigs.k8s.io"

	// CreatedByLabelKey is applied to any container/volume that is created by minikube created_by.minikube.sigs.k8s.io=true
	CreatedByLabelKey = "created_by.minikube.sigs.k8s.io"
)

Variables

View Source
var ErrCPUCountLimit = &FailFastError{errors.New("not enough CPUs is available for container")}

ErrCPUCountLimit is thrown when docker daemon doesn't have enough CPUs for the requested container

View Source
var ErrDaemonInfo = errors.New("daemon info not responding")

ErrDaemonInfo is thrown when docker/podman info is failing or not responding

View Source
var ErrExitedUnexpectedly = errors.New("container exited unexpectedly")

ErrExitedUnexpectedly is thrown when container is created/started without error but later it exists and it's status is not running anymore.

View Source
var ErrGetPortContainerNotRunning = errors.New("unable to inspect a not running container to get port")

ErrGetPortContainerNotRunning happens when you try to inspect a container (in order to get Port) that "exists" but is no longer running

View Source
var ErrGetSSHPortContainerNotRunning = errors.New("unable to inspect a not running container to get SSH port")

ErrGetSSHPortContainerNotRunning happens when you try to inspect a container (in order to get SSH port) that "exists" but is no longer running

View Source
var ErrIPinUse = &FailFastError{errors.New("can't create with that IP, address already in use")}

ErrIPinUse is thrown when the container been given an IP used by another container

View Source
var ErrInsufficientDockerStorage = &FailFastError{errors.New("insufficient docker storage, no space left on device")}

ErrInsufficientDockerStorage is thrown when there is not more storage for docker

View Source
var ErrMinDockerVersion = &FailFastError{errors.New("docker version is less than the minimum required")}

ErrMinDockerVersion is thrown when docker version is less than minimum requited by Minikube

View Source
var ErrNetworkGatewayTaken = errors.New("network gateway is taken")

ErrNetworkGatewayTaken is when given network gatway is taken

View Source
var ErrNetworkInUse = errors.New("unable to delete a network that is attached to a running container")

ErrNetworkInUse is when trying to delete a network which is attached to another container

View Source
var ErrNetworkNotFound = errors.New("kic network not found")

ErrNetworkNotFound is when given network was not found

View Source
var ErrNetworkSubnetTaken = errors.New("subnet is taken")

ErrNetworkSubnetTaken is thrown when a subnet is taken by another network

View Source
var ErrVolumeNotFound = errors.New("kic volume not found")

ErrVolumeNotFound is when given volume was not found

View Source
var ErrWindowsContainers = &FailFastError{errors.New("docker container type is windows")}

ErrWindowsContainers is thrown when docker been configured to run windows containers instead of Linux

View Source
var MountPropagationNameToValue = map[string]MountPropagation{
	"None":            MountPropagationNone,
	"HostToContainer": MountPropagationHostToContainer,
	"Bidirectional":   MountPropagationBidirectional,
}

MountPropagationNameToValue is a map of valid MountPropagation names to their values

View Source
var MountPropagationValueToName = map[MountPropagation]string{
	MountPropagationNone:            "None",
	MountPropagationHostToContainer: "HostToContainer",
	MountPropagationBidirectional:   "Bidirectional",
}

MountPropagationValueToName is a map of valid MountPropagation values to their string names

Functions

func ContainerExists added in v1.8.0

func ContainerExists(ociBin string, name string, warnSlow ...bool) (bool, error)

ContainerExists checks if container name exists (either running or exited)

func ContainerID

func ContainerID(ociBin string, nameOrID string) (string, error)

ContainerID returns id of a container name

func ContainerIPs

func ContainerIPs(ociBin string, name string) (string, string, error)

ContainerIPs returns ipv4,ipv6, error of a container by their name

func ContainerRunning added in v1.10.0

func ContainerRunning(ociBin string, name string, warnSlow ...bool) (bool, error)

ContainerRunning returns running state of a container

func ContainerStatus added in v1.8.0

func ContainerStatus(ociBin string, name string, warnSlow ...bool) (state.State, error)

ContainerStatus returns status of a container running,exited,...

func CreateContainerNode

func CreateContainerNode(p CreateParams) error

CreateContainerNode creates a new container node

func CreateNetwork added in v1.14.0

func CreateNetwork(ociBin string, networkName string) (net.IP, error)

CreateNetwork creates a network returns gateway and error, minikube creates one network per cluster

func DaemonHost added in v1.16.0

func DaemonHost(driver string) string

DaemonHost returns the ip/hostname where OCI daemon service for driver is running For Podman return the host part of CONTAINER_HOST environment variable if set For Docker return the host part of DOCKER_HOST environment variable if set or DefaultBindIPV4 otherwise

func DeleteAllVolumesByLabel added in v1.7.3

func DeleteAllVolumesByLabel(ctx context.Context, ociBin string, label string, warnSlow ...bool) []error

DeleteAllVolumesByLabel deletes all volumes that have a specific label if there is no volume to delete it will return nil

func DeleteContainer added in v1.8.0

func DeleteContainer(ctx context.Context, ociBin string, name string) error

DeleteContainer deletes a container by ID or Name

func DeleteContainersByLabel added in v1.8.0

func DeleteContainersByLabel(ociBin string, label string) []error

DeleteContainersByLabel deletes all containers that have a specific label if there no containers found with the given label, it will return nil

func DeleteKICNetworks added in v1.14.0

func DeleteKICNetworks(ociBin string) []error

DeleteKICNetworks deletes all networks created by kic

func ExtractTarballToVolume added in v1.8.0

func ExtractTarballToVolume(ociBin string, tarballPath, volumeName, imageName string) error

ExtractTarballToVolume runs a docker image imageName which extracts the tarball at tarballPath to the volume named volumeName

func ForwardedPort added in v1.9.0

func ForwardedPort(ociBin string, ociID string, contPort int) (int, error)

ForwardedPort will return port mapping for a container using cli. example : ForwardedPort("docker", "minikube", "22") will return the docker assigned port: 32769, nil only supports TCP ports

func HasMemoryCgroup added in v1.18.0

func HasMemoryCgroup() bool

HasMemoryCgroup checks whether it is possible to set memory limit for cgroup.

func InitialEnv added in v1.16.0

func InitialEnv(env string) string

InitialEnv returns the value of the environment variable env before any environment changes made by minikube

func IsCgroup2UnifiedMode added in v1.18.0

func IsCgroup2UnifiedMode() (bool, error)

IsCgroup2UnifiedMode returns whether we are running in cgroup 2 cgroup2 mode.

func IsCreatedByMinikube added in v1.8.0

func IsCreatedByMinikube(ociBin string, nameOrID string) bool

IsCreatedByMinikube returns true if the container was created by minikube with default assumption that it is not created by minikube when we don't know for sure

func IsExternalDaemonHost added in v1.16.0

func IsExternalDaemonHost(driver string) bool

IsExternalDaemonHost returns whether or not the OCI runtime is running on an external/virtual host For Podman driver return true if CONTAINER_HOST is set to a URI, and the URI contains a host item For Docker driver return true if DOCKER_HOST is set to a URI, and the URI contains a host item

func ListContainersByLabel added in v1.10.0

func ListContainersByLabel(ctx context.Context, ociBin string, label string, warnSlow ...bool) ([]string, error)

ListContainersByLabel returns all the container names with a specified label

func ListOwnedContainers

func ListOwnedContainers(ociBin string) ([]string, error)

ListOwnedContainers lists all the containres that kic driver created on user's machine using a label

func LogContainerDebug added in v1.12.0

func LogContainerDebug(ociBin string, name string) string

LogContainerDebug will print relevant docker/podman infos after a container fails

func LookupInitialEnv added in v1.16.0

func LookupInitialEnv(env string) (string, bool)

LookupInitialEnv returns the value of the environment variable env before any environment changes made by minikube

func PointToHostDockerDaemon

func PointToHostDockerDaemon() error

PointToHostDockerDaemon will unset env variables that point to docker inside minikube to make sure it points to the docker daemon installed by user.

func PointToHostPodman added in v1.10.0

func PointToHostPodman() error

PointToHostPodman will unset env variables that point to podman inside minikube

func PrefixCmd added in v1.10.0

func PrefixCmd(cmd *exec.Cmd) *exec.Cmd

PrefixCmd adds any needed prefix (such as sudo) to the command

func PrepareContainerNode added in v1.10.0

func PrepareContainerNode(p CreateParams) error

PrepareContainerNode sets up the container node before CreateContainerNode is called. For the container runtime, it creates a volume which will be mounted into kic

func PruneAllVolumesByLabel added in v1.7.3

func PruneAllVolumesByLabel(ctx context.Context, ociBin string, label string, warnSlow ...bool) []error

PruneAllVolumesByLabel deletes all volumes that have a specific label if there is no volume to delete it will return nil example: docker volume prune -f --filter label=name.minikube.sigs.k8s.io=minikube

func RemoveNetwork added in v1.14.0

func RemoveNetwork(ociBin string, name string) error

RemoveNetwork removes a network

func RemoveVolume added in v1.18.0

func RemoveVolume(ociBin string, name string) error

RemoveVolume removes a volume

func RoutableHostIPFromInside added in v1.8.0

func RoutableHostIPFromInside(ociBin string, clusterName string, containerName string) (net.IP, error)

RoutableHostIPFromInside returns the ip/dns of the host that container lives on is routable from inside the container

func ShutDown added in v1.10.0

func ShutDown(ociBin string, name string) error

ShutDown will run command to shut down the container to ensure the containers process and networking bindings are all closed to avoid containers getting stuck before delete https://github.com/kubernetes/minikube/issues/7657

func StartContainer added in v1.10.0

func StartContainer(ociBin string, container string) error

StartContainer starts a container with "docker/podman start"

Types

type CreateParams

type CreateParams struct {
	ClusterName   string            // cluster(profile name) that this container belongs to
	Name          string            // used for container name and hostname
	Image         string            // container image to use to create the node.
	ClusterLabel  string            // label the clusters we create using minikube so we can clean up
	NodeLabel     string            // label the nodes so we can clean up by node name
	Role          string            // currently only role supported is control-plane
	Mounts        []Mount           // volume mounts
	APIServerPort int               // Kubernetes api server port
	PortMappings  []PortMapping     // ports to map to container from host
	CPUs          string            // number of cpu cores assign to container
	Memory        string            // memory (mbs) to assign to the container
	Envs          map[string]string // environment variables to pass to the container
	ExtraArgs     []string          // a list of any extra option to pass to oci binary during creation time, for example --expose 8080...
	OCIBinary     string            // docker or podman
	Network       string            // network name that the container will attach to
	IP            string            // static IP to assign for th container in the cluster network
}

CreateParams are parameters needed to create a container

type FailFastError added in v1.12.0

type FailFastError struct {
	Err error
}

FailFastError type is an error that could not be solved by trying again

func (*FailFastError) Error added in v1.12.0

func (f *FailFastError) Error() string

type Mount

type Mount struct {
	// Path of the mount within the container.
	ContainerPath string `protobuf:"bytes,1,opt,name=container_path,json=containerPath,proto3" json:"containerPath,omitempty"`
	// Path of the mount on the host. If the hostPath doesn't exist, then runtimes
	// should report error. If the hostpath is a symbolic link, runtimes should
	// follow the symlink and mount the real destination to container.
	HostPath string `protobuf:"bytes,2,opt,name=host_path,json=hostPath,proto3" json:"hostPath,omitempty"`
	// If set, the mount is read-only.
	Readonly bool `protobuf:"varint,3,opt,name=readonly,proto3,json=readOnly,proto3" json:"readOnly,omitempty"`
	// If set, the mount needs SELinux relabeling.
	SelinuxRelabel bool `protobuf:"varint,4,opt,name=selinux_relabel,json=selinuxRelabel,proto3" json:"selinuxRelabel,omitempty"`
	// Requested propagation mode.
	Propagation MountPropagation `protobuf:"varint,5,opt,name=propagation,proto3,enum=runtime.v1alpha2.MountPropagation" json:"propagation,omitempty"`
}

Mount specifies a host volume to mount into a container. This is a close copy of the upstream cri Mount type see: k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2 It additionally serializes the "propagation" field with the string enum names on disk as opposed to the int32 values, and the serlialzed field names have been made closer to core/v1 VolumeMount field names In yaml this looks like:

containerPath: /foo
hostPath: /bar
readOnly: true
selinuxRelabel: false
propagation: None

Propagation may be one of: None, HostToContainer, Bidirectional

func ParseMountString added in v1.13.0

func ParseMountString(spec string) (m Mount, err error)

ParseMountString parses a mount string of format: '[host-path:]container-path[:<options>]' The comma-delimited 'options' are [rw|ro], [Z], [srhared|rslave|rprivate].

type MountPropagation

type MountPropagation int32

MountPropagation represents an "enum" for mount propagation options, see also Mount.

const (
	// MountPropagationNone specifies that no mount propagation
	// ("private" in Linux terminology).
	MountPropagationNone MountPropagation = 0
	// MountPropagationHostToContainer specifies that mounts get propagated
	// from the host to the container ("rslave" in Linux).
	MountPropagationHostToContainer MountPropagation = 1
	// MountPropagationBidirectional specifies that mounts get propagated from
	// the host to the container and from the container to the host
	// ("rshared" in Linux).
	MountPropagationBidirectional MountPropagation = 2
)

type PortMapping

type PortMapping struct {
	// Port within the container.
	ContainerPort int32 `protobuf:"varint,1,opt,name=container_port,json=containerPort,proto3" json:"containerPort,omitempty"`
	// Port on the host.
	HostPort      int32  `protobuf:"varint,2,opt,name=host_path,json=hostPort,proto3" json:"hostPort,omitempty"`
	ListenAddress string `protobuf:"bytes,3,opt,name=listenAddress,json=hostPort,proto3" json:"listenAddress,omitempty"`
}

PortMapping specifies a host port mapped into a container port. In yaml this looks like:

containerPort: 80
hostPort: 8000
listenAddress: 127.0.0.1

type RunResult added in v1.10.0

type RunResult struct {
	Stdout   bytes.Buffer
	Stderr   bytes.Buffer
	ExitCode int
	Args     []string // the args that was passed to Runner
}

RunResult holds the results of a Runner

func (RunResult) Command added in v1.10.0

func (rr RunResult) Command() string

Command returns a human readable command string that does not induce eye fatigue

func (RunResult) Output added in v1.10.0

func (rr RunResult) Output() string

Output returns human-readable output for an execution result

type SysInfo added in v1.8.0

type SysInfo struct {
	CPUs          int      // CPUs is Number of CPUs
	TotalMemory   int64    // TotalMemory Total available ram
	OSType        string   // container's OsType (windows or linux)
	Swarm         bool     // Weather or not the docker swarm is active
	Rootless      bool     // Weather or not the docker is running on rootless mode
	StorageDriver string   // the storage driver for the daemon  (for example overlay2)
	Errors        []string // any server issues
}

SysInfo Info represents common system Information between docker and podman that minikube cares

func CachedDaemonInfo added in v1.12.2

func CachedDaemonInfo(ociBin string) (SysInfo, error)

CachedDaemonInfo will run and return a docker/podman info only once per minikube run time. to avoid performance

func DaemonInfo added in v1.8.0

func DaemonInfo(ociBin string) (SysInfo, error)

DaemonInfo returns common docker/podman daemon system info that minikube cares about

Jump to

Keyboard shortcuts

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