util

package
v0.1.0-M4 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: Apache-2.0, EPL-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsNamedMap

func AsNamedMap(containersList []*types.Container) map[string]*types.Container

AsNamedMap returns a map of containers where key is the container's name

func CalculateCPUPercent

func CalculateCPUPercent(cpu *types.CPUStats, previousCPU *types.CPUStats) (float64, error)

CalculateCPUPercent calculates the CPU percentage in range [0-100]. Returns error if there is missing data needed for the calculation.

func CalculateMemoryPercent

func CalculateMemoryPercent(memory *types.MemoryStats) (float64, error)

CalculateMemoryPercent calculates the memory percentage. Returns error if there is missing data needed for the calculation.

func CalculateParallelLimit

func CalculateParallelLimit(n int, limit int) int

CalculateParallelLimit calculates the limit for starting parallel jobs

func CalculateUptime

func CalculateUptime(container *types.Container) time.Duration

CalculateUptime calculates the uptime of a container instance

func Copy

func Copy(sourcePath string, destPath string, bufferSize int) error

Copy copies the resources from a given source path to the given destination path

func CopyContainer

func CopyContainer(source *types.Container) types.Container

CopyContainer creates a new container instance from the provided parameter

func DeviceMappingToString

func DeviceMappingToString(deviceMapping *types.DeviceMapping) string

DeviceMappingToString returns the string representation of the given device mapping. The string representation format for a device mapping is defined with ParseDeviceMapping function.

func FileNotExistEmptyOrDir

func FileNotExistEmptyOrDir(filename string) error

FileNotExistEmptyOrDir validates whether the provided filename refers to an existing non-empty file

func FillDefaults

func FillDefaults(container *types.Container) bool

FillDefaults sets all default configurations which are not required as an input but are required for processing the container's configuration

func FillMemorySwap

func FillMemorySwap(container *types.Container)

FillMemorySwap sets the swap memory of a container. Memory swap should be filled only once during creation.

func GetActionMessage

func GetActionMessage(actionType ActionType) string

GetActionMessage returns a text message describing the given action type

func GetDirChildrenNames

func GetDirChildrenNames(dirPath string) ([]string, error)

GetDirChildrenNames returns all child directories of the provided one

func GetImageHost

func GetImageHost(imageRef string) string

GetImageHost retrieves the host name of the container imager registry for the provided image

func GetMemoryLimit

func GetMemoryLimit(limit uint64) uint64

GetMemoryLimit takes a limit in bytes. If the machine memory is read successfully and is lower than the provided limit, returns the machine memory in bytes. Otherwise, returns the provided limit.

func GetSystemCPUUsage

func GetSystemCPUUsage() (uint64, error)

GetSystemCPUUsage returns the system CPU usage as nanoseconds the CPU has spent performing different work. Returns error if cpu times could not be read.

func IsContainerCreated

func IsContainerCreated(c *types.Container) bool

IsContainerCreated returns if container is in the created state or not

func IsContainerDead

func IsContainerDead(c *types.Container) bool

IsContainerDead returns whether the container is in Dead state

func IsContainerNetworkBridge

func IsContainerNetworkBridge(container *types.Container) bool

IsContainerNetworkBridge returns true if the network mode is bridge

func IsContainerNetworkHost

func IsContainerNetworkHost(container *types.Container) bool

IsContainerNetworkHost returns true if the network mode is host

func IsContainerRunningOrPaused

func IsContainerRunningOrPaused(c *types.Container) bool

IsContainerRunningOrPaused returns true if the container is running or paused

func IsDirectory

func IsDirectory(path string) (bool, error)

IsDirectory returns true if the given path is a directory

func IsFile

func IsFile(path string) (bool, error)

IsFile returns true if the given path is a file

func IsRestartPolicyAlways

func IsRestartPolicyAlways(policy *types.RestartPolicy) bool

IsRestartPolicyAlways checks if the restart policy type is set to always

func IsRestartPolicyNone

func IsRestartPolicyNone(policy *types.RestartPolicy) bool

IsRestartPolicyNone checks if the restart policy type is set to no

func IsRestartPolicyOnFailure

func IsRestartPolicyOnFailure(policy *types.RestartPolicy) bool

IsRestartPolicyOnFailure checks if the restart policy is set to on-failure

func IsRestartPolicyUnlessStopped

func IsRestartPolicyUnlessStopped(policy *types.RestartPolicy) bool

IsRestartPolicyUnlessStopped checks if the restart policy is set to unless-stopped

func IsRunningSystemd

func IsRunningSystemd() bool

IsRunningSystemd checks whether the host was booted with systemd as its init system. This functions similarly to systemd's `sd_booted(3)`: internally, it checks whether /run/systemd/system/ exists and is a directory. http://www.freedesktop.org/software/systemd/man/sd_booted.html

Package name changed also removed not needed logic and added custom code to handle the specific use case, Eclipse Kanto contributors, 2022

func MkDir

func MkDir(dirname string) error

MkDir creates a directory with the provided name

func MkDirs

func MkDirs(dirNames ...string) error

MkDirs creates directories for the given directory names

func MountPointToString

func MountPointToString(mountPoint *types.MountPoint) string

MountPointToString returns the string representation of the given mount point. The string representation format for a mount point is defined with ParseMountPoint function.

func ParseDeviceMapping

func ParseDeviceMapping(device string) (*types.DeviceMapping, error)

ParseDeviceMapping converts a single string representation of a container's device mapping to a structured DeviceMapping instance. Format: <host_device>:<container_device>[:propagation_mode]. Both path on host and in container must be set. The string representation may contain optional cgroups permissions configuration. Possible cgroup permissions options are “r” (read), “w” (write), “m” (mknod) and all combinations of the three are possible. If not set, “rwm” is default device configuration. Example: /dev/ttyACM0:/dev/ttyUSB0[:rwm].

func ParseDeviceMappings

func ParseDeviceMappings(devices []string) ([]types.DeviceMapping, error)

ParseDeviceMappings converts string representations of container's device mappings to structured DeviceMapping instances. The string representation format for a device mapping is defined with ParseDeviceMapping function.

func ParseMountPoint

func ParseMountPoint(mp string) (*types.MountPoint, error)

ParseMountPoint converts a single string representation of a container's mount to a structured MountPoint instance. Format: source:destination[:propagation_mode]. If the propagation mode parameter is omitted, rprivate will be set by default. Available propagation modes are: rprivate, private, rshared, shared, rslave, slave.

func ParseMountPoints

func ParseMountPoints(mps []string) ([]types.MountPoint, error)

ParseMountPoints converts string representations of container's mounts to structured MountPoint instances. The string representation format for a mount point is defined with ParseMountPoint function.

func ParsePortMapping

func ParsePortMapping(mapping string) (*types.PortMapping, error)

ParsePortMapping converts a single string representation of container's port mapping to a structured PortMapping instance. Format: [<host-ip>:]<host-port>[-<range>]:<container-port>[/<proto>]. Most common use-case: 80:80 Mapping the container’s 80 port to a host port in the 5000-6000 range: 5000-6000:80/udp Specifying port protocol (default is tcp): 80:80/udp By default the port mapping will set on all network interfaces, but this is also manageable: 0.0.0.0:80-100:80/udp

func ParsePortMappings

func ParsePortMappings(mappings []string) ([]types.PortMapping, error)

ParsePortMappings converts string representations of container's port mappings to structured PortMapping instances. The string representation format for a port mapping is defined with ParsePortMapping function.

func PortMappingToString

func PortMappingToString(portMapping *types.PortMapping) string

PortMappingToString returns the string representation of the given port mapping. The string representation format for a port mapping is defined with ParsePortMapping function.

func ReadContainer

func ReadContainer(path string) (*types.Container, error)

ReadContainer reads container from file

func RemoveChildren

func RemoveChildren(dirPath string) ([]string, error)

RemoveChildren removes all children of a given directory

Returns [], nil if everything went OK Returns nil, error if the error happened before or during the retrieval of the children. For example the path did not exist was locked or something else similar. If an error occurs on some or all of the children it will return a []string, error where the list contains the children that where not deleted

func SetContainerStatusCreated

func SetContainerStatusCreated(c *types.Container)

SetContainerStatusCreated sets the container state to created updating all required fields and flags

func SetContainerStatusDead

func SetContainerStatusDead(c *types.Container)

SetContainerStatusDead sets the container state to dead updating all required fields and flags

func SetContainerStatusExited

func SetContainerStatusExited(c *types.Container, exitCode int64, errMsg string, oomKilled bool)

SetContainerStatusExited sets the container state to exited updating all required fields and flags

func SetContainerStatusPaused

func SetContainerStatusPaused(c *types.Container)

SetContainerStatusPaused sets the container state to paused updating all required fields and flags

func SetContainerStatusRunning

func SetContainerStatusRunning(c *types.Container, pid int64)

SetContainerStatusRunning sets the container state to running updating all required fields and flags

func SetContainerStatusStopped

func SetContainerStatusStopped(c *types.Container, exitCode int64, errMsg string)

SetContainerStatusStopped sets the container state to stopped updating all required fields and flags

func SetContainerStatusUnpaused

func SetContainerStatusUnpaused(c *types.Container)

SetContainerStatusUnpaused is added for completion as the container's state is actually running

func SizeRecalculate

func SizeRecalculate(sizeStr string, eval func(float64) float64) (string, error)

SizeRecalculate takes size string representation and returns a new recalculated size string representation

func SizeToBytes

func SizeToBytes(sizeStr string) (int64, error)

SizeToBytes converts size string representation to a number

func ToSignal

func ToSignal(signal string) syscall.Signal

ToSignal parses a string to syscall.Signal. Signals are accepted as both number and name: SIGKILL or 9. Returns the syscall.Signal for the provided number or name. Returns 0 if a signal with the provided name is not found.

func ValidateConfig

func ValidateConfig(config *types.ContainerConfiguration) error

ValidateConfig validates the container config

func ValidateContainer

func ValidateContainer(container *types.Container) error

ValidateContainer validats all container properties

func ValidateDeviceMapping

func ValidateDeviceMapping(devMapping types.DeviceMapping) error

ValidateDeviceMapping validates the mapping between the path on the host and the path in the container and checks if the cgroup permissions are set

func ValidateDeviceMappings

func ValidateDeviceMappings(devMappings []types.DeviceMapping) error

ValidateDeviceMappings validates all device mappings

func ValidateHostConfig

func ValidateHostConfig(hostConfig *types.HostConfig) error

ValidateHostConfig validates the container host configuration

func ValidateImage

func ValidateImage(img types.Image) error

ValidateImage validates the container image

func ValidateLogConfig

func ValidateLogConfig(logCfg *types.LogConfiguration) error

ValidateLogConfig validates the log configuration

func ValidateMountPoint

func ValidateMountPoint(mp types.MountPoint) error

ValidateMountPoint validates the cointainer mount configuration

func ValidateMounts

func ValidateMounts(mounts []types.MountPoint) error

ValidateMounts validates all the cointainer mount points

func ValidateName

func ValidateName(name string) error

ValidateName validates the container name

func ValidateNetworking

func ValidateNetworking(hostConfig *types.HostConfig) error

ValidateNetworking validates the container networking

func ValidatePrivileged

func ValidatePrivileged(hostConfig *types.HostConfig) error

ValidatePrivileged validates that the container privileged configuration does not overlap with other configurations

func ValidateResources

func ValidateResources(resources *types.Resources) error

ValidateResources validates the container resources limitations

func ValidateRestartPolicy

func ValidateRestartPolicy(rsPolicy *types.RestartPolicy) error

ValidateRestartPolicy validates the container restart policy

func ValidateStopOpts

func ValidateStopOpts(opts *types.StopOpts) error

ValidateStopOpts validates stop options. Returns error if timeout is negative or signal is invalid.

Types

type ActionType

type ActionType int

ActionType defines a type for an action to achieve desired container

const (
	// ActionCheck denotes that current container already has the desired configuration, it shall be checked only if the container is running
	ActionCheck ActionType = iota
	// ActionCreate denotes that a new container with desired configurtion shall be created and started
	ActionCreate
	// ActionRecreate denotes that the existing container shall be replaced by a new container with desired configurtion
	ActionRecreate
	// ActionUpdate denotes that the existing container shall be runtime updated with desired configurtion
	ActionUpdate
	// ActionDestroy denotes that the existing container shall be destroyed
	ActionDestroy
)

func DetermineUpdateAction

func DetermineUpdateAction(current *types.Container, desired *types.Container) ActionType

DetermineUpdateAction compares the current container with the desired one and determines what action shall be done to achieve desired state

type LocksCache

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

LocksCache provides cache management for identifiable *sync.RWMutex instances.

func NewLocksCache

func NewLocksCache() LocksCache

NewLocksCache creates a new LockCache

func (*LocksCache) GetLock

func (cache *LocksCache) GetLock(key string) *sync.RWMutex

GetLock returns the lock by provided key

func (*LocksCache) RemoveLock

func (cache *LocksCache) RemoveLock(key string)

RemoveLock removes the lock by provided key

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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