unit

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PIPE_UNIT_STDOUT = "unit-stdout"
	PIPE_UNIT_STDERR = "unit-stderr"
)
View Source
const (
	MAX_BACKOFF_TIME                     = 5 * time.Minute
	BACKOFF_RESET_TIME                   = 10 * time.Minute
	CHILD_OOM_SCORE                      = 15 // chosen arbitrarily... kernel will adjust this value
	MaxContainerTerminationMessageLength = 1024 * 4
)

Variables

View Source
var (
	// The kubelet stores container logfiles in this directory. To make it
	// easier to configure logging agents on cells, we use the same directory.
	ContainerLogDir = "/var/log/containers"
	// Sleep length to allow log pipe to drain before closing
	LOG_PIPE_FINISH_READ_SLEEP = time.Second * 3
)

Functions

func IsUnitExist

func IsUnitExist(rootdir, name string) bool

func StartUnit

func StartUnit(rootdir, podname, hostname, unitname, workingdir, netns string, command []string, policy api.RestartPolicy) error

Types

type Config

type Config struct {
	Hostname        string
	Domainname      string
	User            string
	AttachStdin     bool
	AttachStdout    bool
	AttachStderr    bool
	ExposedPorts    map[string]struct{} `json:",omitempty"`
	Tty             bool
	OpenStdin       bool
	StdinOnce       bool
	Env             []string
	Cmd             []string
	Healthcheck     *HealthConfig `json:",omitempty"`
	ArgsEscaped     bool          `json:",omitempty"`
	Image           string
	Volumes         map[string]struct{}
	WorkingDir      string
	Entrypoint      []string
	NetworkDisabled bool   `json:",omitempty"`
	MacAddress      string `json:",omitempty"`
	OnBuild         []string
	Labels          map[string]string
	StopSignal      string   `json:",omitempty"`
	StopTimeout     *int     `json:",omitempty"`
	Shell           []string `json:",omitempty"`
}

This is the main config struct for docker images.

type HealthConfig

type HealthConfig struct {
	Test        []string      `json:",omitempty"`
	Interval    time.Duration `json:",omitempty"`
	Timeout     time.Duration `json:",omitempty"`
	StartPeriod time.Duration `json:",omitempty"`
	Retries     int           `json:",omitempty"`
}

This is part of the config of docker images.

type LogPipe

type LogPipe struct {
	Unitdir string
	Pipes   map[string]*os.File
}

func NewLogPipe

func NewLogPipe(dir string) (*LogPipe, error)

func (*LogPipe) Chown

func (l *LogPipe) Chown(uid, gid int) error

func (*LogPipe) OpenWriter

func (l *LogPipe) OpenWriter(name string) (fp *os.File, err error)

func (*LogPipe) Remove

func (l *LogPipe) Remove()

func (*LogPipe) StartAllReaders

func (l *LogPipe) StartAllReaders(cb func(string))

func (*LogPipe) StartReader

func (l *LogPipe) StartReader(name string, cb func(string))

type Unit

type Unit struct {
	*LogPipe
	Directory string
	Name      string
	Image     string
	// contains filtered or unexported fields
}

func OpenUnit

func OpenUnit(rootdir, name string) (*Unit, error)

func (*Unit) CreateCommand

func (u *Unit) CreateCommand(command []string, args []string) []string

func (*Unit) Destroy

func (u *Unit) Destroy() error

func (*Unit) GetEnv

func (u *Unit) GetEnv() []string

func (*Unit) GetRootfs

func (u *Unit) GetRootfs() string

func (*Unit) GetStatus

func (u *Unit) GetStatus() (*api.UnitStatus, error)

func (*Unit) GetUser

func (u *Unit) GetUser(lookup util.UserLookup) (uid, gid uint32, groups []uint32, homedir string, err error)

func (*Unit) GetWorkingDir

func (u *Unit) GetWorkingDir() string

func (*Unit) OpenStdinReader

func (u *Unit) OpenStdinReader() (io.ReadCloser, error)

This is only used internally to pass in an io.Reader to the process as its stdin. We also start a writer so that opening the pipe for reading won't block. This writer will be stopped via closeStdin().

func (*Unit) OpenStdinWriter

func (u *Unit) OpenStdinWriter() (io.WriteCloser, error)

func (*Unit) PullAndExtractImage

func (u *Unit) PullAndExtractImage(image, server, username, password string) error

func (*Unit) Run

func (u *Unit) Run(podname, hostname string, command []string, workingdir string, policy api.RestartPolicy, mounter mount.Mounter) error

func (*Unit) RunUnitLoop

func (u *Unit) RunUnitLoop(command, caplist []string, uid, gid uint32, groups []uint32, unitin io.Reader, unitout, uniterr io.Writer, policy api.RestartPolicy) (err error)

func (*Unit) SaveUnitConfig

func (u *Unit) SaveUnitConfig(unitConfig UnitConfig) error

func (*Unit) SetImage

func (u *Unit) SetImage(image string) error

func (*Unit) SetState

func (u *Unit) SetState(state api.UnitState, restarts *int) error

func (*Unit) SetStatus

func (u *Unit) SetStatus(status *api.UnitStatus) error

func (*Unit) SetUnitConfigOverlayfs

func (u *Unit) SetUnitConfigOverlayfs(useOverlayfs bool)

func (*Unit) UpdateStatusAttr

func (u *Unit) UpdateStatusAttr(ready, started *bool) error

type UnitConfig

type UnitConfig struct {
	api.PodSecurityContext   `json:"podSecurityContext"`
	api.SecurityContext      `json:"securityContext"`
	StartupProbe             *api.Probe `json:",omitempty"`
	ReadinessProbe           *api.Probe `json:",omitempty"`
	LivenessProbe            *api.Probe `json:",omitempty"`
	TerminationMessagePolicy api.TerminationMessagePolicy
	TerminationMessagePath   string
	PodIP                    string
	UseOverlayfs             bool
}

type UnitManager

type UnitManager struct {
	RunningUnits *conmap.StringOsProcess
	LogBuf       *conmap.StringLogbufLogBuffer
	// contains filtered or unexported fields
}

func NewUnitManager

func NewUnitManager(rootDir string) *UnitManager

func (*UnitManager) CaptureLogs

func (um *UnitManager) CaptureLogs(podName, unitName string, lp *LogPipe)

func (*UnitManager) GetLogBuffer

func (um *UnitManager) GetLogBuffer(unit string) (*logbuf.LogBuffer, error)

func (*UnitManager) GetPid

func (um *UnitManager) GetPid(unitName string) (int, bool)

func (*UnitManager) ReadLogBuffer

func (um *UnitManager) ReadLogBuffer(unit string, n int) ([]logbuf.LogEntry, error)

func (*UnitManager) RemoveUnit

func (um *UnitManager) RemoveUnit(name string) error

This removes the unit and its files/directories from the filesystem.

func (*UnitManager) StartUnit

func (um *UnitManager) StartUnit(podname, hostname, unitname, workingdir, netns string, command, args, appenv []string, policy api.RestartPolicy) error

This is a bit tricky in Go, since we are not supposed to use fork(). Instead, call the daemon with command line flags indicating that it is only used as a helper to start a new unit in a new filesystem namespace.

func (*UnitManager) StopUnit

func (um *UnitManager) StopUnit(name string) error

It's possible we need to set up some communication with the waiting process that it doesn't need to clean up everything. Lets see how the logging works out...

func (*UnitManager) UnitRunning

func (um *UnitManager) UnitRunning(unit string) bool

Jump to

Keyboard shortcuts

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