-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathrunpea.go
63 lines (51 loc) · 1.86 KB
/
runpea.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package runcontainerd
import (
"io"
"code.cloudfoundry.org/garden"
"code.cloudfoundry.org/guardian/rundmc/goci"
"code.cloudfoundry.org/lager"
)
//go:generate counterfeiter . PeaManager
type PeaManager interface {
Create(log lager.Logger, id string, bundle goci.Bndl, io garden.ProcessIO) error
Delete(log lager.Logger, containerID string) error
RemoveBundle(log lager.Logger, containerID string) error
}
//go:generate counterfeiter . Volumizer
type Volumizer interface {
Destroy(log lager.Logger, handle string) error
}
type RunContainerPea struct {
peaManager PeaManager
processManager ProcessManager
volumizer Volumizer
cleanupProcessDirsOnWait bool
}
func NewRunContainerPea(peaManager PeaManager, processManager ProcessManager, volumizer Volumizer, cleanupProcessDirsOnWait bool) *RunContainerPea {
return &RunContainerPea{
peaManager: peaManager,
processManager: processManager,
volumizer: volumizer,
cleanupProcessDirsOnWait: cleanupProcessDirsOnWait,
}
}
func (r *RunContainerPea) RunPea(
log lager.Logger, processID string, processBundle goci.Bndl, sandboxHandle string,
pio garden.ProcessIO, tty bool, procJSON io.Reader, extraCleanup func() error,
) (garden.Process, error) {
if processBundle.Spec.Annotations == nil {
processBundle.Spec.Annotations = make(map[string]string)
}
processBundle.Spec.Annotations["container-type"] = "pea"
processBundle.Spec.Annotations["sandbox-container"] = sandboxHandle
log.Info("using runcontainerd.RunPea")
if err := r.peaManager.Create(log, processID, processBundle, pio); err != nil {
return &Process{}, err
}
process, err := r.processManager.GetTask(log, processID)
if err != nil {
return nil, err
}
proc := NewProcess(log, process, r.cleanupProcessDirsOnWait)
return NewPeaProcess(log, *proc, r.peaManager, r.volumizer), nil
}