Skip to content

Commit

Permalink
Merge branch 'refactor/volume' into 'master'
Browse files Browse the repository at this point in the history
[skip ci] [WIP] remove the notion of permdir

See merge request !151
  • Loading branch information
CMGS committed Sep 5, 2017
2 parents 1db5728 + 9f9c2bf commit f75ca09
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 12 deletions.
8 changes: 2 additions & 6 deletions cluster/calcium/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,19 @@ func trimLeftSlash(name string) string {
}

// make mount paths
// 使用volumes, 参数格式跟docker一样, 支持 $PERMDIR $APPDIR 的展开
// 使用volumes, 参数格式跟docker一样
// volumes:
// - "$PERMDIR/foo-data:$APPDIR/foodata:rw"
// - "/foo-data:$APPDIR/foodata:rw"
func makeMountPaths(specs types.Specs, config types.Config) ([]string, map[string]struct{}) {
binds := []string{}
volumes := make(map[string]struct{})

var expandENV = func(env string) string {
envMap := make(map[string]string)
if config.PermDir != "" {
envMap["PERMDIR"] = filepath.Join(config.PermDir, specs.Appname)
}
envMap["APPDIR"] = filepath.Join(config.AppDir, specs.Appname)
return envMap[env]
}

// volumes
for _, path := range specs.Volumes {
expanded := os.Expand(path, expandENV)
parts := strings.Split(expanded, ":")
Expand Down
6 changes: 3 additions & 3 deletions cluster/calcium/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

func TestMakeMountPaths(t *testing.T) {
config := types.Config{PermDir: "/mnt/mfs/permdirs", AppDir: "/home"}
specs := types.Specs{Appname: "foo", Volumes: []string{"$PERMDIR/foo-data:$APPDIR/foo-data"}}
config := types.Config{AppDir: "/home"}
specs := types.Specs{Appname: "foo", Volumes: []string{"/foo-data:$APPDIR/foo-data"}}
binds, volumes := makeMountPaths(specs, config)
assert.Equal(t, binds, []string{"/mnt/mfs/permdirs/foo/foo-data:/home/foo/foo-data:rw", "/proc/sys:/writable-proc/sys:rw", "/sys/kernel/mm/transparent_hugepage:/writable-sys/kernel/mm/transparent_hugepage:rw"}, "binds should be the same")
assert.Equal(t, binds, []string{"/foo-data:/home/foo/foo-data:rw", "/proc/sys:/writable-proc/sys:rw", "/sys/kernel/mm/transparent_hugepage:/writable-sys/kernel/mm/transparent_hugepage:rw"}, "binds should be the same")
assert.Equal(t, volumes, map[string]struct{}{"/home/foo/foo-data": struct{}{}, "/writable-proc/sys": struct{}{}, "/writable-sys/kernel/mm/transparent_hugepage": struct{}{}})
}
1 change: 0 additions & 1 deletion core.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ bind: ":5002"
agent_port: "12345"
appdir: "/home"
backupdir: "/data/backup"
permdir: "/mnt/mfs/permdirs"
etcd:
- "http://127.0.0.1:2379"
etcd_lock_prefix: "/eru-core/_lock"
Expand Down
1 change: 0 additions & 1 deletion rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func initConfig(mStore *mockstore.MockStore) (types.Config, *vibranium) {
config := types.Config{
Bind: ":5001", // HTTP API address
AppDir: "/tmp", // App directory inside container
PermDir: "/tmp", // Permanent dir on host
BackupDir: "/tmp", // Backup dir on host
EtcdMachines: []string{"MOCK"}, // etcd cluster addresses
EtcdLockPrefix: "/eru-core/_lock", // etcd lock prefix, all locks will be created under this dir
Expand Down
1 change: 0 additions & 1 deletion types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ type Config struct {
LogLevel string `yaml:"log_level"`
Bind string `yaml:"bind"` // HTTP API address
AppDir string `yaml:"appdir"` // App directory inside container
PermDir string `yaml:"permdir"` // Permanent dir on host
BackupDir string `yaml:"backupdir"` // Backup dir on host
EtcdMachines []string `yaml:"etcd"` // etcd cluster addresses
EtcdLockPrefix string `yaml:"etcd_lock_prefix"` // etcd lock prefix, all locks will be created under this dir
Expand Down

0 comments on commit f75ca09

Please sign in to comment.