util

package
v1.19.9 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: Apache-2.0 Imports: 22 Imported by: 51

Documentation

Index

Constants

View Source
const (
	// Deprecated: Default runtime should come from containers.conf
	DefaultRuntime = "runc"
	// DefaultCNIPluginPath is the default location of CNI plugin helpers.
	DefaultCNIPluginPath = "/usr/libexec/cni:/opt/cni/bin"
	// DefaultCNIConfigDir is the default location of CNI configuration files.
	DefaultCNIConfigDir = "/etc/cni/net.d"
)
View Source
const (

	// DefaultTransport is a prefix that we apply to an image name if we
	// can't find one in the local Store, in order to generate a source
	// reference for the image that we can then copy to the local Store.
	DefaultTransport = "docker://"
)

Variables

View Source
var (
	// DefaultCapabilities is the list of capabilities which we grant by
	// default to containers which are running under UID 0.
	DefaultCapabilities = []string{
		"CAP_AUDIT_WRITE",
		"CAP_CHOWN",
		"CAP_DAC_OVERRIDE",
		"CAP_FOWNER",
		"CAP_FSETID",
		"CAP_KILL",
		"CAP_MKNOD",
		"CAP_NET_BIND_SERVICE",
		"CAP_SETFCAP",
		"CAP_SETGID",
		"CAP_SETPCAP",
		"CAP_SETUID",
		"CAP_SYS_CHROOT",
	}
	// DefaultNetworkSysctl is the list of Kernel parameters which we
	// grant by default to containers which are running under UID 0.
	DefaultNetworkSysctl = map[string]string{
		"net.ipv4.ping_group_range": "0 0",
	}
)
View Source
var (
	// RegistryDefaultPathPrefix contains a per-registry listing of default prefixes
	// to prepend to image names that only contain a single path component.
	RegistryDefaultPathPrefix = map[string]string{
		"index.docker.io": "library",
		"docker.io":       "library",
	}
)

Functions

func AddImageNames

func AddImageNames(store storage.Store, firstRegistry string, systemContext *types.SystemContext, image *storage.Image, addNames []string) error

AddImageNames adds the specified names to the specified image.

func ExpandNames

func ExpandNames(names []string, firstRegistry string, systemContext *types.SystemContext, store storage.Store) ([]string, error)

ExpandNames takes unqualified names, parses them as image names, and returns the fully expanded result, including a tag. Names which don't include a registry name will be marked for the most-preferred registry (i.e., the first one in our configuration).

func FindImage

func FindImage(store storage.Store, firstRegistry string, systemContext *types.SystemContext, image string) (types.ImageReference, *storage.Image, error)

FindImage locates the locally-stored image which corresponds to a given name.

func FindLocalRuntime added in v1.14.1

func FindLocalRuntime(runtime string) string

FindLocalRuntime find the local runtime of the system searching through the config file for possible locations.

func GID added in v1.14.3

func GID(st os.FileInfo) int

func GetContainerIDs added in v1.8.4

func GetContainerIDs(uidmap, gidmap []specs.LinuxIDMapping, uid, gid uint32) (uint32, uint32, error)

GetContainerIDs uses ID mappings to compute the container-level IDs that will correspond to a UID/GID pair on the host.

func GetFailureCause

func GetFailureCause(err, defaultError error) error

GetFailureCause checks the type of the error "err" and returns a new error message that reflects the reason of the failure. In case err type is not a familiar one the error "defaultError" is returned.

func GetHostIDs added in v1.7.1

func GetHostIDs(uidmap, gidmap []specs.LinuxIDMapping, uid, gid uint32) (uint32, uint32, error)

GetHostIDs uses ID mappings to compute the host-level IDs that will correspond to a UID/GID pair in the container.

func GetHostRootIDs added in v1.7.1

func GetHostRootIDs(spec *specs.Spec) (uint32, uint32, error)

GetHostRootIDs uses ID mappings in spec to compute the host-level IDs that will correspond to UID/GID 0/0 in the container.

func GetPolicyContext added in v1.7.1

func GetPolicyContext(ctx *types.SystemContext) (*signature.PolicyContext, error)

GetPolicyContext sets up, initializes and returns a new context for the specified policy

func IsCgroup2UnifiedMode added in v1.13.2

func IsCgroup2UnifiedMode() (bool, error)

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

func LogIfNotRetryable added in v1.7.1

func LogIfNotRetryable(err error, what string) (retry bool)

LogIfNotRetryable logs "what" if err is set and is not an EINTR or EAGAIN syscall.Errno. Returns "true" if we can continue.

func LogIfUnexpectedWhileDraining added in v1.7.1

func LogIfUnexpectedWhileDraining(err error, what string)

LogIfUnexpectedWhileDraining logs "what" if err is set and is not an EINTR or EAGAIN or EIO syscall.Errno.

func MergeEnv added in v1.16.0

func MergeEnv(defaults, overrides []string) []string

MergeEnv merges two lists of environment variables, avoiding duplicates.

func ResolveName

func ResolveName(name string, firstRegistry string, sc *types.SystemContext, store storage.Store) ([]string, string, bool, error)

ResolveName checks if name is a valid image name, and if that name doesn't include a domain portion, returns a list of the names which it might correspond to in the set of configured registries, the transport used to pull the image, and a boolean which is true iff 1) the list of search registries was used, and 2) it was empty.

The returned image names never include a transport: prefix, and if transport != "", (transport, image) should be a valid input to alltransports.ParseImageName. transport == "" indicates that image that already exists in a local storage, and the name is valid for store.Image() / storage.Transport.ParseStoreReference().

NOTE: The "list of search registries is empty" check does not count blocked registries, and neither the implied "localhost" nor a possible firstRegistry are counted

func ResolveNameToReferences added in v1.14.1

func ResolveNameToReferences(
	store storage.Store,
	systemContext *types.SystemContext,
	image string,
) (refs []types.ImageReference, err error)

ResolveNameToReferences tries to create a list of possible references (including their transports) from the provided image name.

func Runtime added in v1.7.1

func Runtime() string

Runtime is the default command to use to run the container.

func StartsWithValidTransport added in v1.15.0

func StartsWithValidTransport(name string) bool

StartsWithValidTransport validates the name starts with Buildah supported transport to avoid the corner case image name same as the transport name

func StringInSlice added in v1.7.1

func StringInSlice(s string, slice []string) bool

StringInSlice returns a boolean indicating if the exact value s is present in the slice slice.

func TruncateString added in v1.11.1

func TruncateString(str string, to int) string

TruncateString trims the given string to the provided maximum amount of characters and shortens it with `...`.

func UID added in v1.14.3

func UID(st os.FileInfo) int

func WriteError added in v1.7.1

func WriteError(w io.Writer, err error, lastError error) error

WriteError writes `lastError` into `w` if not nil and return the next error `err`

Types

type HardlinkChecker added in v1.11.0

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

func (*HardlinkChecker) Add added in v1.11.0

func (h *HardlinkChecker) Add(fi os.FileInfo, name string)

func (*HardlinkChecker) Check added in v1.11.0

func (h *HardlinkChecker) Check(fi os.FileInfo) string

Jump to

Keyboard shortcuts

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