Documentation ¶
Index ¶
- func AsNamedMap(containersList []*types.Container) map[string]*types.Container
- func CalculateCPUPercent(cpu *types.CPUStats, previousCPU *types.CPUStats) (float64, error)
- func CalculateMemoryPercent(memory *types.MemoryStats) (float64, error)
- func CalculateParallelLimit(n int, limit int) int
- func CalculateUptime(container *types.Container) time.Duration
- func Copy(sourcePath string, destPath string, bufferSize int) error
- func CopyContainer(source *types.Container) types.Container
- func DeviceMappingToString(deviceMapping *types.DeviceMapping) string
- func FileNotExistEmptyOrDir(filename string) error
- func FillDefaults(container *types.Container) bool
- func FillMemorySwap(container *types.Container)
- func GetActionMessage(actionType ActionType) string
- func GetDirChildrenNames(dirPath string) ([]string, error)
- func GetImageHost(imageRef string) string
- func GetMemoryLimit(limit uint64) uint64
- func GetSystemCPUUsage() (uint64, error)
- func IsContainerCreated(c *types.Container) bool
- func IsContainerDead(c *types.Container) bool
- func IsContainerNetworkBridge(container *types.Container) bool
- func IsContainerNetworkHost(container *types.Container) bool
- func IsContainerRunningOrPaused(c *types.Container) bool
- func IsDirectory(path string) (bool, error)
- func IsFile(path string) (bool, error)
- func IsRestartPolicyAlways(policy *types.RestartPolicy) bool
- func IsRestartPolicyNone(policy *types.RestartPolicy) bool
- func IsRestartPolicyOnFailure(policy *types.RestartPolicy) bool
- func IsRestartPolicyUnlessStopped(policy *types.RestartPolicy) bool
- func IsRunningSystemd() bool
- func MkDir(dirname string) error
- func MkDirs(dirNames ...string) error
- func MountPointToString(mountPoint *types.MountPoint) string
- func ParseDeviceMapping(device string) (*types.DeviceMapping, error)
- func ParseDeviceMappings(devices []string) ([]types.DeviceMapping, error)
- func ParseMountPoint(mp string) (*types.MountPoint, error)
- func ParseMountPoints(mps []string) ([]types.MountPoint, error)
- func ParsePortMapping(mapping string) (*types.PortMapping, error)
- func ParsePortMappings(mappings []string) ([]types.PortMapping, error)
- func PortMappingToString(portMapping *types.PortMapping) string
- func ReadContainer(path string) (*types.Container, error)
- func RemoveChildren(dirPath string) ([]string, error)
- func SetContainerStatusCreated(c *types.Container)
- func SetContainerStatusDead(c *types.Container)
- func SetContainerStatusExited(c *types.Container, exitCode int64, errMsg string, oomKilled bool)
- func SetContainerStatusPaused(c *types.Container)
- func SetContainerStatusRunning(c *types.Container, pid int64)
- func SetContainerStatusStopped(c *types.Container, exitCode int64, errMsg string)
- func SetContainerStatusUnpaused(c *types.Container)
- func SizeRecalculate(sizeStr string, eval func(float64) float64) (string, error)
- func SizeToBytes(sizeStr string) (int64, error)
- func ToSignal(signal string) syscall.Signal
- func ValidateConfig(config *types.ContainerConfiguration) error
- func ValidateContainer(container *types.Container) error
- func ValidateDeviceMapping(devMapping types.DeviceMapping) error
- func ValidateDeviceMappings(devMappings []types.DeviceMapping) error
- func ValidateHostConfig(hostConfig *types.HostConfig) error
- func ValidateImage(img types.Image) error
- func ValidateLogConfig(logCfg *types.LogConfiguration) error
- func ValidateMountPoint(mp types.MountPoint) error
- func ValidateMounts(mounts []types.MountPoint) error
- func ValidateName(name string) error
- func ValidateNetworking(hostConfig *types.HostConfig) error
- func ValidatePrivileged(hostConfig *types.HostConfig) error
- func ValidateResources(resources *types.Resources) error
- func ValidateRestartPolicy(rsPolicy *types.RestartPolicy) error
- func ValidateStopOpts(opts *types.StopOpts) error
- type ActionType
- type LocksCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsNamedMap ¶
AsNamedMap returns a map of containers where key is the container's name
func CalculateCPUPercent ¶
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 ¶
CalculateParallelLimit calculates the limit for starting parallel jobs
func CalculateUptime ¶
CalculateUptime calculates the uptime of a container instance
func CopyContainer ¶
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 ¶
FileNotExistEmptyOrDir validates whether the provided filename refers to an existing non-empty file
func FillDefaults ¶
FillDefaults sets all default configurations which are not required as an input but are required for processing the container's configuration
func FillMemorySwap ¶
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 ¶
GetDirChildrenNames returns all child directories of the provided one
func GetImageHost ¶
GetImageHost retrieves the host name of the container imager registry for the provided image
func GetMemoryLimit ¶
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 ¶
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 ¶
IsContainerCreated returns if container is in the created state or not
func IsContainerDead ¶
IsContainerDead returns whether the container is in Dead state
func IsContainerNetworkBridge ¶
IsContainerNetworkBridge returns true if the network mode is bridge
func IsContainerNetworkHost ¶
IsContainerNetworkHost returns true if the network mode is host
func IsContainerRunningOrPaused ¶
IsContainerRunningOrPaused returns true if the container is running or paused
func IsDirectory ¶
IsDirectory returns true if the given path is a directory
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 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 ¶
ReadContainer reads container from file
func RemoveChildren ¶
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 ¶
SetContainerStatusCreated sets the container state to created updating all required fields and flags
func SetContainerStatusDead ¶
SetContainerStatusDead sets the container state to dead updating all required fields and flags
func SetContainerStatusExited ¶
SetContainerStatusExited sets the container state to exited updating all required fields and flags
func SetContainerStatusPaused ¶
SetContainerStatusPaused sets the container state to paused updating all required fields and flags
func SetContainerStatusRunning ¶
SetContainerStatusRunning sets the container state to running updating all required fields and flags
func SetContainerStatusStopped ¶
SetContainerStatusStopped sets the container state to stopped updating all required fields and flags
func SetContainerStatusUnpaused ¶
SetContainerStatusUnpaused is added for completion as the container's state is actually running
func SizeRecalculate ¶
SizeRecalculate takes size string representation and returns a new recalculated size string representation
func SizeToBytes ¶
SizeToBytes converts size string representation to a number
func ToSignal ¶
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 ¶
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 ¶
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 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 ¶
ValidateResources validates the container resources limitations
func ValidateRestartPolicy ¶
func ValidateRestartPolicy(rsPolicy *types.RestartPolicy) error
ValidateRestartPolicy validates the container restart policy
func ValidateStopOpts ¶
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 (*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