server

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PIPE_UNIT_STDOUT = "unit-stdout"
	PIPE_UNIT_STDERR = "unit-stderr"
)
View Source
const (
	MULTIPART_PACKAGE = "package"
	ITZO_DIR          = "/tmp/itzo"
	CERTS_DIR         = ITZO_DIR
	DEFAULT_ROOTDIR   = ITZO_DIR + "/units"
	ITZO_VERSION      = "1.0"
	FILE_BYTES_LIMIT  = 4096
)
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
	MAX_HOSTNAME_LEN                     = 63
	MaxContainerTerminationMessageLength = 1024 * 4
)

Variables

View Source
var (
	KubeRouterProg                 = "kube-router"
	KubeRouterURL                  = "https://milpa-builds.s3.amazonaws.com/kube-router"
	KubeRouterMinimumVersion       = "v0.3.1"
	MaxBufferSize            int64 = 1024 * 1024 * 10 // 10MB
	NVIDIA_CONTAINER_CLI_PRG       = "nvidia-container-cli"
	NVIDIA_SMI_PRG                 = "nvidia-smi"
)

Functions

func DeployPackage

func DeployPackage(filename, rootdir, pkgname string) (err error)

func DiffUnits

func DiffUnits(spec []api.Unit, status []api.Unit, allModifiedVolumes sets.String) ([]api.Unit, []api.Unit)

func DiffVolumes

func DiffVolumes(spec []api.Volume, status []api.Volume) (map[string]api.Volume, map[string]api.Volume, sets.String)

func IsUnitExist

func IsUnitExist(rootdir, name string) bool

func MergeSecretsIntoSpec

func MergeSecretsIntoSpec(secrets map[string]map[string][]byte, units []api.Unit)

Modifies the PodSpec and inserts secrets into the spec

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 EnvStore

type EnvStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

A 2d map protected by a mutex.

func (*EnvStore) Add

func (e *EnvStore) Add(unit, key, value string)

func (*EnvStore) Delete

func (e *EnvStore) Delete(unit, key string)

func (*EnvStore) Get

func (e *EnvStore) Get(unit, key string) (value string, exists bool)

func (*EnvStore) Items

func (e *EnvStore) Items(unit string) [][2]string

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 ImagePuller

type ImagePuller struct {
}

func (*ImagePuller) PullImage

func (ip *ImagePuller) PullImage(rootdir, name, image, server, username, password string) error
type Link struct {
	// contains filtered or unexported fields
}

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 MiniUnit

type MiniUnit struct {
	Name         string
	Image        string
	Command      []string
	Args         []string
	VolumeMounts []api.VolumeMount
	Env          []api.EnvVar
}

Only diff the parts of the unit we care about

type Mounter

type Mounter interface {
	CreateMount(*api.Volume) error
	DeleteMount(*api.Volume) error
	AttachMount(unitname, src, dst string) error
	DetachMount(unitname, dst string) error
}

type ParameterError

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

Some kind of invalid input from the user. Useful here to decide when to return a 4xx vs a 5xx.

func (*ParameterError) Error

func (pe *ParameterError) Error() string

type PodController

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

I know how to do one thing: Make Controllers. A ton of controllers...

func NewPodController

func NewPodController(rootdir string, mounter Mounter, unitMgr UnitRunner) *PodController

func (*PodController) GetStatus

func (pc *PodController) GetStatus() ([]api.UnitStatus, []api.UnitStatus, error)

func (*PodController) GetUnitName

func (pc *PodController) GetUnitName(unitName string) (string, error)

func (*PodController) SetPodNetwork

func (pc *PodController) SetPodNetwork(netNS, podIP string)

func (*PodController) Start

func (pc *PodController) Start()

func (*PodController) SyncPodUnits

func (pc *PodController) SyncPodUnits(spec *api.PodSpec, status *api.PodSpec, allCreds map[string]api.RegistryCredentials)

func (*PodController) UpdatePod

func (pc *PodController) UpdatePod(params *api.PodParameters) error

type Puller

type Puller interface {
	PullImage(rootdir, name, image, server, username, password string) error
}

type Server

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

func New

func New(rootdir string) *Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string, disableTLS bool)

func (*Server) RunLogTailer

func (s *Server) RunLogTailer(w http.ResponseWriter, r *http.Request, unitName string, withMetadata bool, logBuffer *logbuf.LogBuffer)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

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) 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) 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) 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
}

type UnitManager

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

func NewUnitManager

func NewUnitManager(rootDir string) *UnitManager

func (*UnitManager) CaptureLogs

func (um *UnitManager) CaptureLogs(name string, unit *Unit)

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

type UnitRunner

type UnitRunner interface {
	StartUnit(string, string, string, string, string, []string, []string, []string, api.RestartPolicy) error
	StopUnit(string) error
	RemoveUnit(string) error
}

Too bad there isn't a word for a creator AND destroyer Coulda gone with Shiva(er) but that's a bit imprecise...

Jump to

Keyboard shortcuts

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