container

package
v1.29.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package container xxx

Index

Constants

View Source
const (
	// ContainerStatus_PAUSED xxx
	ContainerStatus_PAUSED = "paused"
	// ContainerStatus_RESTARTING xxx
	ContainerStatus_RESTARTING = "restarting"
	// ContainerStatus_RUNNING xxx
	ContainerStatus_RUNNING = "running"
	// ContainerStatus_DEAD xxx
	ContainerStatus_DEAD = "dead"
	// ContainerStatus_CREATED xxx
	ContainerStatus_CREATED = "created"
	// ContainerStatus_EXITED xxx
	ContainerStatus_EXITED = "exited"
)
View Source
const (
	// StopContainerGraceTime executor default gracetime
	StopContainerGraceTime = 10
	// DefaultDockerCPUPeriod default cpu period for executor
	DefaultDockerCPUPeriod = 100000
)

Variables

This section is empty.

Functions

func EnvOperCopy

func EnvOperCopy(task *BcsContainerTask)

EnvOperCopy environment $ operation support

Types

type BcsContainerInfo

type BcsContainerInfo struct {
	ID                      string                 `json:"ID,omitempty"`          // container ID
	Name                    string                 `json:"Name,omitempty"`        // container name
	Pid                     int                    `json:"Pid,omitempty"`         // container pid
	StartAt                 time.Time              `json:"StartAt,omitempty"`     // startting time
	FinishAt                time.Time              `json:"FinishAt,omitempty"`    // Exit time
	Status                  string                 `json:"Status,omitempty"`      // status string, paused, restarting, running, dead, created, exited
	Healthy                 bool                   `json:"Healthy,omitempty"`     // Container healthy
	IsChecked               bool                   `json:",omitempty"`            // is health check
	ConsecutiveFailureTimes int                    `json:",omitempty"`            // consecutive failure times
	ExitCode                int                    `json:"ExitCode,omitempty"`    // container exit code
	Hostname                string                 `json:"Hostname,omitempty"`    // container host name
	NetworkMode             string                 `json:"NetworkMode,omitempty"` // Network mode for container
	IPAddress               string                 `json:"IPAddress,omitempty"`   // Contaienr IP address
	NodeAddress             string                 `json:"NodeAddress,omitempty"` // node host address
	Ports                   []BcsPort              `json:"Ports,omitempty"`       // ports info for report
	Message                 string                 `json:"Message,omitempty"`     // status message for container
	Resource                *schedTypes.Resource   `json:"Resource,omitempty"`
	BcsMessage              *schedTypes.BcsMessage `json:",omitempty"`
	OOMKilled               bool                   `json:"OOMKilled,omitempty"` // container exited, whether oom
}

BcsContainerInfo only for BcsExecutor

func (*BcsContainerInfo) Update

func (info *BcsContainerInfo) Update(other *BcsContainerInfo)

Update data from other info

type BcsContainerTask

type BcsContainerTask struct {
	Name              string                       // container name
	Image             string                       // container image
	HostName          string                       // container hostname
	Hosts             []string                     // host:ip pair for /etc/hosts in container
	Command           string                       // container command
	Args              []string                     // args for command
	Env               []BcsKV                      // environments
	Volums            []BcsVolume                  // host path mount
	NetworkName       string                       // container network name
	NetworkIPAddr     string                       // container ip address request
	ForcePullImage    bool                         // pull image every time
	OOMKillDisabled   bool                         // OOM kill feature, default is true
	AutoRemove        bool                         // remove container when exit, default false
	Ulimits           []BcsKV                      // ulimit for docker parameter
	ShmSize           int64                        // docker hostconfig shm size, 1 = 1B
	Privileged        bool                         // setting container privileged
	PublishAllPorts   bool                         // publish all ports in container
	PortBindings      map[string]BcsPort           // port for container reflection, only useful for docker bridge
	Labels            []BcsKV                      // label for container
	Resource          *bcstypes.Resource           // container resource request
	LimitResource     *bcstypes.Resource           // container resource limit
	ExtendedResources []*comtypes.ExtendedResource // extended resources
	BcsMessages       []*bcstypes.BcsMessage       // bcs define message
	RuntimeConf       *BcsContainerInfo            // container runtime info
	HealthCheck       healthcheck.Checker          // for health check
	KillPolicy        int                          // kill policy timeout, unit is seconds
	// container network flow limit args
	NetLimit *comtypes.NetLimit
	TaskId   string

	Ipc string // IPC namespace to use

}

BcsContainerTask task info for running container

type BcsImage

type BcsImage struct {
	ID         string   // image id
	Repository []string // repository, including tag
	Created    int64    // create time
	Size       int64    // image size
}

BcsImage image info from hub

type BcsKV

type BcsKV struct {
	Key   string
	Value string
}

BcsKV key/value structure for anywhere necessary

type BcsPort

type BcsPort struct {
	Name          string `json:"name,omitempty"`
	ContainerPort string `json:"containerPort,omitempty"`
	HostPort      string `json:"hostPort,omitempty"`
	Protocol      string `json:"protocol,omitempty"`
	HostIP        string `json:"hostIP,omitempty"` // use for host has multiple ip address
}

BcsPort port service for container port reflection

type BcsVolume

type BcsVolume struct {
	ReadOnly      bool
	HostPath      string
	ContainerPath string
}

BcsVolume volume info from mesos to container

type ConEventCB

type ConEventCB func(*BcsContainerTask) error

ConEventCB callback for every container status changed

type Container

type Container interface {
	// RunCommand running command in Container
	RunCommand(containerID string, command []string) error
	// UploadToContainer upload file from host to Container
	UploadToContainer(containerID string, source, dest string) error
	// ListContainer list all running containner info
	ListContainer()
	// CreateContainer create Container with info, after container created,
	// return container id & container name in BcsContainerInfo. if we need conntainer
	// running, StartContainer must be call with container id
	CreateContainer(containerName string, containerTask *BcsContainerTask) (*BcsContainerInfo, error)
	// StartContainer starting container with container id return by CreateContainer
	StartContainer(containerID string) error
	// StopContainer with container name. container will be killed when timeout
	StopContainer(containerName string, timeout int) error
	// RemoveContainer remove container by name
	RemoveContainer(containerName string, force bool) error
	// KillContainer kill container by name with designate signal
	KillContainer(containerName string, signal int) error
	// InspectContainer inspect container by name
	InspectContainer(containerName string) (*BcsContainerInfo, error)
	// PullImage pull image from hub
	PullImage(image string) error
	// ListImage list all image from local
	ListImage(filter string) ([]*BcsImage, error)
	// UpdateResources xxx
	// update container resources limit
	// para1: container id
	// para2: resources,cpu mem
	UpdateResources(string, *schedTypes.TaskResources) error
	// CommitImage xxx
	// commit image
	// para1: container id
	// para2: image name
	CommitImage(string, string) error

	// RunCommandV2 xxx
	// exec command
	RunCommandV2(ops *schedTypes.RequestCommandTask) (*schedTypes.ResponseCommandTask, error)
}

Container define interface for operating containers

func NewDockerContainer

func NewDockerContainer(endpoint, user, passwd string) Container

NewDockerContainer create DockerContainer manager tool endpoint can be http, https, tcp, or unix domain sock

type DockerContainer

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

DockerContainer implement container interface to handle all operator with docker command line.

func (*DockerContainer) CommitImage

func (docker *DockerContainer) CommitImage(id, image string) error

CommitImage create image from running container

func (*DockerContainer) CreateContainer

func (docker *DockerContainer) CreateContainer(containerName string, containerTask *BcsContainerTask) (
	*BcsContainerInfo, error)

CreateContainer Start Container with docker client.

func (*DockerContainer) InspectContainer

func (docker *DockerContainer) InspectContainer(containerName string) (*BcsContainerInfo, error)

InspectContainer inspect container by name

func (*DockerContainer) KillContainer

func (docker *DockerContainer) KillContainer(containerName string, signal int) error

KillContainer kill container by name with designate signal

func (*DockerContainer) ListContainer

func (docker *DockerContainer) ListContainer()

ListContainer list all running containner info

func (*DockerContainer) ListImage

func (docker *DockerContainer) ListImage(filter string) ([]*BcsImage, error)

ListImage list all image from local

func (*DockerContainer) PullImage

func (docker *DockerContainer) PullImage(image string) error

PullImage pull image from hub

func (*DockerContainer) RemoveContainer

func (docker *DockerContainer) RemoveContainer(containerName string, force bool) error

RemoveContainer remove container by name

func (*DockerContainer) RunCommand

func (docker *DockerContainer) RunCommand(containerID string, command []string) error

RunCommand running command in Container

func (*DockerContainer) RunCommandV2

RunCommandV2 v2 version run command

func (*DockerContainer) StartContainer

func (docker *DockerContainer) StartContainer(containerID string) error

StartContainer starting container with container id return by CreateContainer

func (*DockerContainer) StopContainer

func (docker *DockerContainer) StopContainer(containerName string, timeout int) error

StopContainer with container name. container will be killed when timeout

func (*DockerContainer) UpdateResources

func (docker *DockerContainer) UpdateResources(id string, resource *schedTypes.TaskResources) error

UpdateResources update container resource in runtime

func (*DockerContainer) UploadToContainer

func (docker *DockerContainer) UploadToContainer(containerID string, source, dest string) error

UploadToContainer upload file from host to Container

type Pod

type Pod interface {
	IsHealthy() bool                                  // check pod is healthy
	Injection() bool                                  // check ip address is injected
	SetIPAddr(ip string)                              // set Pod ip address
	GetIPAddr() string                                // get pod ip address if exist
	SetPodID(ID string)                               // set pod id if needed
	GetNamespace() string                             // get namespace, not used now
	GetNetns() string                                 // get netns path string
	GetNetworkName() string                           // get container network name
	GetNetArgs() [][2]string                          // get cni plugin args
	GetPid() int                                      // get network infrastructure container pid
	GetContainerID() string                           // get network infrastructure container id
	GetPodID() string                                 // get pod id
	GetNetStatus() string                             // get network ip address information
	GetPodStatus() PodStatus                          // pod status, see @PodStatus
	GetMessage() string                               // Get status message
	Init() error                                      // init pod, start network container
	Finit() error                                     // finit pod, release pod resource
	Start() error                                     // start all container
	Stop(graceExit int)                               // stop all container, graceExit
	UploadFile(name, source, dest string) error       // upload source file to container(name)
	Execute(name string, command []string) error      // execute command in container(name)
	GetContainers() []*BcsContainerInfo               // Get all containers info
	GetContainerByName(name string) *BcsContainerInfo // Get container by ID
	// UpdateResources TODO
	// update container resources limit
	// para1: container id
	// para2: resources,cpu mem
	UpdateResources(string, *schedTypes.TaskResources) error
	// CommitImage TODO
	// commit image
	// para1: container id
	// para2: image name
	CommitImage(string, string) error
	GetContainerTasks() map[string]*BcsContainerTask
}

Pod interface for bcs

type PodEventCB

type PodEventCB func(Pod) error

PodEventCB pod event callback

type PodEventHandler

type PodEventHandler struct {
	PreStart  ConEventCB // call before container start
	PostStart ConEventCB // call after container start success
	PreStop   ConEventCB // call before container stop, not including failed stop
	PostStop  ConEventCB // call after container stopped, not including failed stop
}

PodEventHandler callback collection for pod status changed

type PodStatus

type PodStatus string

PodStatus for imply container status in pod

const (
	// PodStatus_UNKNOWN TODO
	PodStatus_UNKNOWN PodStatus = "unknown" // init status code
	// PodStatus_INIT TODO
	PodStatus_INIT PodStatus = "init" // INIT pod, network infrastructure
	// PodStatus_STARTING TODO
	PodStatus_STARTING PodStatus = "starting" // pulling images, starting all containers
	// PodStatus_RUNNING TODO
	PodStatus_RUNNING PodStatus = "running" // all containers are running
	// PodStatus_FAILED TODO
	PodStatus_FAILED PodStatus = "failed" // one container failed
	// PodStatus_KILLING TODO
	PodStatus_KILLING PodStatus = "killing" // get kill command, killing all container
	// PodStatus_KILLED TODO
	PodStatus_KILLED PodStatus = "killed" // all container killed
	// PodStatus_FINISH TODO
	PodStatus_FINISH PodStatus = "finish" // get shutdown command, close all container
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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