containers

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: Apache-2.0 Imports: 7 Imported by: 10

Documentation

Index

Constants

View Source
const (
	RuntimeNameDocker     string = "docker"
	RuntimeNameContainerd string = "containerd"
	RuntimeNameCRIO       string = "cri-o"
	RuntimeNameGarden     string = "garden"
)

Known container runtimes

View Source
const (
	ContainerUnknownState    string = "unknown"
	ContainerCreatedState           = "created"
	ContainerRunningState           = "running"
	ContainerRestartingState        = "restarting"
	ContainerPausedState            = "paused"
	ContainerExitedState            = "exited"
	ContainerDeadState              = "dead"
	ContainerActiveState            = "active"
)

Supported container states

View Source
const (
	ContainerUnknownHealth  string = "unknown"
	ContainerStartingHealth        = "starting"
	ContainerHealthy               = "healthy"
	ContainerUnhealthy             = "unhealthy"
)

Supported container health

View Source
const (
	DefaultNetworkMode string = "default" // bridge
	HostNetworkMode           = "host"
	BridgeNetworkMode         = "bridge"
	NoneNetworkMode           = "none"
	AwsvpcNetworkMode         = "awsvpc"
	UnknownNetworkMode        = "unknown"
)

Container network modes

View Source
const (
	DefaultUTSMode UTSMode = ""
	HostUTSMode            = "host"
	UnknownUTSMode         = "unknown"
)

UTSMode is container UTS modes

View Source
const ContainerEntityName = "container_id"

ContainerEntityName is the entity name applied to all containers

View Source
const ContainerEntityPrefix = ContainerEntityName + EntitySeparator

ContainerEntityPrefix is the prefix that any entity corresponding to a container must have It replaces any prior prefix like <runtime>:// in a pod container status.

View Source
const EntitySeparator = "://"

EntitySeparator is used to separate the entity name from its ID

Variables

View Source
var (
	// ErrEmptyImage is returned when image name argument is empty
	ErrEmptyImage = errors.New("empty image name")
	// ErrImageIsSha256 is returned when image name argument is a sha256
	ErrImageIsSha256 = errors.New("invalid image name (is a sha256)")
)

Functions

func BuildEntityName

func BuildEntityName(runtime, id string) string

BuildEntityName builds a valid entity name for a given container runtime and cid.

func BuildTaggerEntityName

func BuildTaggerEntityName(id string) string

BuildTaggerEntityName builds a valid tagger entity name for a given cid.

func ContainerIDForEntity

func ContainerIDForEntity(name string) string

ContainerIDForEntity extracts the container ID portion of a container entity name

func IsEntityName

func IsEntityName(name string) bool

IsEntityName tests whether a given entity name is valid

func ResetSharedFilter

func ResetSharedFilter()

ResetSharedFilter is only to be used in unit tests: it resets the global filter instance to force re-parsing of the configuration.

func SplitEntityName

func SplitEntityName(name string) (string, string)

SplitEntityName returns the prefix and container cid parts of a valid entity name

func SplitImageName

func SplitImageName(image string) (string, string, string, error)

SplitImageName splits a valid image name (from ResolveImageName) and returns:

  • the "long image name" with registry and prefix, without tag
  • the "short image name", without registry, prefix nor tag
  • the image tag if present
  • an error if parsing failed

Types

type Container

type Container struct {
	Type        string
	ID          string
	EntityID    string
	Name        string
	Image       string
	ImageID     string
	Created     int64
	State       string
	Health      string
	Pids        []int32
	Excluded    bool
	AddressList []NetworkAddress
	StartedAt   int64

	metrics.ContainerMetrics
	Limits  metrics.ContainerLimits
	Network metrics.ContainerNetStats
}

Container represents a single container on a machine and includes system-level statistics about the container.

func (*Container) SetLimits

func (ctn *Container) SetLimits(ctnLimits *metrics.ContainerLimits)

SetLimits stores results from a ContainerLimits to a Container

func (*Container) SetMetrics

func (ctn *Container) SetMetrics(ctnMetrics *metrics.ContainerMetrics)

SetMetrics stores results from a ContainerMetrics to the embedded struct inside Container

type ContainerImplementation

type ContainerImplementation interface {
	// Asks provider to fetch data from system APIs in bulk
	// It's required to call it before any other function
	Prefetch() error

	ContainerExists(containerID string) bool
	GetContainerStartTime(containerID string) (int64, error)
	DetectNetworkDestinations(pid int) ([]NetworkDestination, error)
	GetAgentCID() (string, error)
	GetPIDs(containerID string) ([]int32, error)
	ContainerIDForPID(pid int) (string, error)
	GetDefaultGateway() (net.IP, error)
	GetDefaultHostIPs() ([]string, error)

	metrics.ContainerMetricsProvider
}

ContainerImplementation is a generic interface that defines a common interface across different container implementation (Linux cgroup, windows containers, etc.)

type Filter

type Filter struct {
	Enabled            bool
	ImageWhitelist     []*regexp.Regexp
	NameWhitelist      []*regexp.Regexp
	NamespaceWhitelist []*regexp.Regexp
	ImageBlacklist     []*regexp.Regexp
	NameBlacklist      []*regexp.Regexp
	NamespaceBlacklist []*regexp.Regexp
}

Filter holds the state for the container filtering logic

func GetSharedFilter

func GetSharedFilter() (*Filter, error)

GetSharedFilter allows to share the result of NewFilterFromConfig for several user classes

func NewAutodiscoveryFilter

func NewAutodiscoveryFilter(filter FilterType) (*Filter, error)

NewAutodiscoveryFilter creates a new container filter for Autodiscovery It sources patterns from the pkg/config options but ignores the exclude_pause_container options It allows to filter metrics and logs separately For use in autodiscovery.

func NewFilter

func NewFilter(whitelist, blacklist []string) (*Filter, error)

NewFilter creates a new container filter from a two slices of regexp patterns for a whitelist and blacklist. Each pattern should have the following format: "field:pattern" where field can be: [image, name]. An error is returned if any of the expression don't compile.

func NewFilterFromConfig

func NewFilterFromConfig() (*Filter, error)

NewFilterFromConfig creates a new container filter, sourcing patterns from the pkg/config options

func (Filter) IsExcluded

func (cf Filter) IsExcluded(containerName, containerImage, podNamespace string) bool

IsExcluded returns a bool indicating if the container should be excluded based on the filters in the containerFilter instance.

type FilterType

type FilterType string

FilterType indicates the container filter type

const GlobalFilter FilterType = "GlobalFilter"

GlobalFilter is used to cover both MetricsFilter and LogsFilter filter types

const LogsFilter FilterType = "LogsFilter"

LogsFilter refers to the Logs filter type

const MetricsFilter FilterType = "MetricsFilter"

MetricsFilter refers to the Metrics filter type

type NetworkAddress

type NetworkAddress struct {
	IP       net.IP
	Port     int
	Protocol string
}

NetworkAddress represents a tuple IP/Port/Protocol

type NetworkDestination

type NetworkDestination struct {
	Interface string
	Subnet    uint64
	Mask      uint64
}

NetworkDestination holds one network destination subnet and it's linked interface name

type UTSMode

type UTSMode string

UTSMode is container UTS modes

Directories

Path Synopsis
windows
Package windows We need a file in this package as it's referenced by a file built on windows
Package windows We need a file in this package as it's referenced by a file built on windows

Jump to

Keyboard shortcuts

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