Skip to content

Commit

Permalink
[portobox] Check that volume have cocaine app label before vunlink at…
Browse files Browse the repository at this point in the history
… GC state. (#160)

* [portobox] Check that volume have cocaine app label before vunlink at GC state.
  • Loading branch information
dkarpukhin authored Nov 6, 2018
1 parent d514e98 commit 0a95037
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
46 changes: 26 additions & 20 deletions isolate/porto/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ type portoBoxConfig struct {
// Path to a journal file
Journal string `json:"journal"`

SpawnConcurrency uint `json:"concurrency"`
RegistryAuth map[string]string `json:"registryauth"`
DialRetries int `json:"dialretries"`
CleanupEnabled bool `json:"cleanupenabled"`
SetImgURI bool `json:"setimguri"`
WeakEnabled bool `json:"weakenabled"`
Gc bool `json:"gc"`
WaitLoopStepSec uint `json:"waitloopstepsec"`
DefaultUlimits string `json:"defaultulimits"`
VolumeBackend string `json:"volumebackend"`
DefaultResolvConf string `json:"defaultresolv_conf"`
SpawnConcurrency uint `json:"concurrency"`
RegistryAuth map[string]string `json:"registryauth"`
DialRetries int `json:"dialretries"`
CleanupEnabled bool `json:"cleanupenabled"`
SetImgURI bool `json:"setimguri"`
WeakEnabled bool `json:"weakenabled"`
Gc bool `json:"gc"`
WaitLoopStepSec uint `json:"waitloopstepsec"`
DefaultUlimits string `json:"defaultulimits"`
VolumeBackend string `json:"volumebackend"`
DefaultResolvConf string `json:"defaultresolv_conf"`
CocaineAppVolumeLabel string `json:"cocaineappvolumelabel"`
}

func (c *portoBoxConfig) String() string {
Expand Down Expand Up @@ -92,13 +93,14 @@ const defaultVolumeBackend = "overlay"
func NewBox(ctx context.Context, cfg isolate.BoxConfig, gstate isolate.GlobalState) (isolate.Box, error) {
log.G(ctx).Info("Porto Box Initiate")
var config = &portoBoxConfig{
SpawnConcurrency: 5,
DialRetries: 10,
WaitLoopStepSec: 10,
SpawnConcurrency: 5,
DialRetries: 10,
WaitLoopStepSec: 10,

CleanupEnabled: true,
WeakEnabled: false,
Gc: true,
CleanupEnabled: true,
WeakEnabled: false,
Gc: true,
CocaineAppVolumeLabel: "cocaine-app",
}
decoderConfig := mapstructure.DecoderConfig{
WeaklyTypedInput: true,
Expand Down Expand Up @@ -357,9 +359,12 @@ func (b *Box) waitLoop(ctx context.Context) {
volumes, errLv := portoConn.ListVolumes("", "")
if errLv != nil {
log.G(ctx).Debugf("At gc state for ListVolumes() we get that error: %s", errLv)
}
for _, volume := range volumes {
portoConn.UnlinkVolume(volume.Path, "***")
} else {
for _, volume := range volumes {
if volume.Properties["Private"] == b.config.CocaineAppVolumeLabel {
portoConn.UnlinkVolume(volume.Path, "***")
}
}
}
}

Expand Down Expand Up @@ -595,6 +600,7 @@ func (b *Box) Spawn(ctx context.Context, config isolate.SpawnConfig, output io.W
CleanupEnabled: b.config.CleanupEnabled,
SetImgURI: b.config.SetImgURI,
VolumeBackend: b.config.VolumeBackend,
VolumeLabel: b.config.CocaineAppVolumeLabel,
execInfo: execInfo{
Profile: profile,
name: config.Name,
Expand Down
2 changes: 2 additions & 0 deletions isolate/porto/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type container struct {
volume Volume
extraVolumes []Volume
output io.Writer
VolumeLabel string

mtn bool
netId string
Expand Down Expand Up @@ -67,6 +68,7 @@ func newContainer(ctx context.Context, portoConn porto.API, cfg containerConfig)
volume: volume,
extraVolumes: extravolumes,
output: ioutil.Discard,
VolumeLabel: cfg.VolumeLabel,

mtn: cfg.Mtn,
netId: cfg.Network["netid"],
Expand Down
3 changes: 2 additions & 1 deletion isolate/porto/container_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ type containerConfig struct {
VolumeBackend string
Mtn bool
MtnAllocationId string
VolumeLabel string
}

func (c *containerConfig) CreateRootVolume(ctx context.Context, portoConn porto.API) (Volume, error) {
properties := map[string]string{
"backend": c.VolumeBackend,
"layers": c.Layer,
"private": "cocaine-app",
"private": c.VolumeLabel,
}

logger := log.G(ctx).WithField("container", c.ID)
Expand Down

0 comments on commit 0a95037

Please sign in to comment.