|
@@ -2,7 +2,6 @@ package volumedrivers
|
|
|
|
|
|
import (
|
|
import (
|
|
"errors"
|
|
"errors"
|
|
- "path/filepath"
|
|
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
@@ -16,7 +15,7 @@ var (
|
|
|
|
|
|
type volumeDriverAdapter struct {
|
|
type volumeDriverAdapter struct {
|
|
name string
|
|
name string
|
|
- baseHostPath string
|
|
|
|
|
|
+ scopePath func(s string) string
|
|
capabilities *volume.Capability
|
|
capabilities *volume.Capability
|
|
proxy *volumeDriverProxy
|
|
proxy *volumeDriverProxy
|
|
}
|
|
}
|
|
@@ -30,10 +29,10 @@ func (a *volumeDriverAdapter) Create(name string, opts map[string]string) (volum
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
return &volumeAdapter{
|
|
return &volumeAdapter{
|
|
- proxy: a.proxy,
|
|
|
|
- name: name,
|
|
|
|
- driverName: a.name,
|
|
|
|
- baseHostPath: a.baseHostPath,
|
|
|
|
|
|
+ proxy: a.proxy,
|
|
|
|
+ name: name,
|
|
|
|
+ driverName: a.name,
|
|
|
|
+ scopePath: a.scopePath,
|
|
}, nil
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -41,13 +40,6 @@ func (a *volumeDriverAdapter) Remove(v volume.Volume) error {
|
|
return a.proxy.Remove(v.Name())
|
|
return a.proxy.Remove(v.Name())
|
|
}
|
|
}
|
|
|
|
|
|
-func hostPath(baseHostPath, path string) string {
|
|
|
|
- if baseHostPath != "" {
|
|
|
|
- path = filepath.Join(baseHostPath, path)
|
|
|
|
- }
|
|
|
|
- return path
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func (a *volumeDriverAdapter) List() ([]volume.Volume, error) {
|
|
func (a *volumeDriverAdapter) List() ([]volume.Volume, error) {
|
|
ls, err := a.proxy.List()
|
|
ls, err := a.proxy.List()
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -57,11 +49,11 @@ func (a *volumeDriverAdapter) List() ([]volume.Volume, error) {
|
|
var out []volume.Volume
|
|
var out []volume.Volume
|
|
for _, vp := range ls {
|
|
for _, vp := range ls {
|
|
out = append(out, &volumeAdapter{
|
|
out = append(out, &volumeAdapter{
|
|
- proxy: a.proxy,
|
|
|
|
- name: vp.Name,
|
|
|
|
- baseHostPath: a.baseHostPath,
|
|
|
|
- driverName: a.name,
|
|
|
|
- eMount: hostPath(a.baseHostPath, vp.Mountpoint),
|
|
|
|
|
|
+ proxy: a.proxy,
|
|
|
|
+ name: vp.Name,
|
|
|
|
+ scopePath: a.scopePath,
|
|
|
|
+ driverName: a.name,
|
|
|
|
+ eMount: a.scopePath(vp.Mountpoint),
|
|
})
|
|
})
|
|
}
|
|
}
|
|
return out, nil
|
|
return out, nil
|
|
@@ -79,13 +71,13 @@ func (a *volumeDriverAdapter) Get(name string) (volume.Volume, error) {
|
|
}
|
|
}
|
|
|
|
|
|
return &volumeAdapter{
|
|
return &volumeAdapter{
|
|
- proxy: a.proxy,
|
|
|
|
- name: v.Name,
|
|
|
|
- driverName: a.Name(),
|
|
|
|
- eMount: v.Mountpoint,
|
|
|
|
- createdAt: v.CreatedAt,
|
|
|
|
- status: v.Status,
|
|
|
|
- baseHostPath: a.baseHostPath,
|
|
|
|
|
|
+ proxy: a.proxy,
|
|
|
|
+ name: v.Name,
|
|
|
|
+ driverName: a.Name(),
|
|
|
|
+ eMount: v.Mountpoint,
|
|
|
|
+ createdAt: v.CreatedAt,
|
|
|
|
+ status: v.Status,
|
|
|
|
+ scopePath: a.scopePath,
|
|
}, nil
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -122,13 +114,13 @@ func (a *volumeDriverAdapter) getCapabilities() volume.Capability {
|
|
}
|
|
}
|
|
|
|
|
|
type volumeAdapter struct {
|
|
type volumeAdapter struct {
|
|
- proxy *volumeDriverProxy
|
|
|
|
- name string
|
|
|
|
- baseHostPath string
|
|
|
|
- driverName string
|
|
|
|
- eMount string // ephemeral host volume path
|
|
|
|
- createdAt time.Time // time the directory was created
|
|
|
|
- status map[string]interface{}
|
|
|
|
|
|
+ proxy *volumeDriverProxy
|
|
|
|
+ name string
|
|
|
|
+ scopePath func(string) string
|
|
|
|
+ driverName string
|
|
|
|
+ eMount string // ephemeral host volume path
|
|
|
|
+ createdAt time.Time // time the directory was created
|
|
|
|
+ status map[string]interface{}
|
|
}
|
|
}
|
|
|
|
|
|
type proxyVolume struct {
|
|
type proxyVolume struct {
|
|
@@ -149,7 +141,7 @@ func (a *volumeAdapter) DriverName() string {
|
|
func (a *volumeAdapter) Path() string {
|
|
func (a *volumeAdapter) Path() string {
|
|
if len(a.eMount) == 0 {
|
|
if len(a.eMount) == 0 {
|
|
mountpoint, _ := a.proxy.Path(a.name)
|
|
mountpoint, _ := a.proxy.Path(a.name)
|
|
- a.eMount = hostPath(a.baseHostPath, mountpoint)
|
|
|
|
|
|
+ a.eMount = a.scopePath(mountpoint)
|
|
}
|
|
}
|
|
return a.eMount
|
|
return a.eMount
|
|
}
|
|
}
|
|
@@ -160,7 +152,7 @@ func (a *volumeAdapter) CachedPath() string {
|
|
|
|
|
|
func (a *volumeAdapter) Mount(id string) (string, error) {
|
|
func (a *volumeAdapter) Mount(id string) (string, error) {
|
|
mountpoint, err := a.proxy.Mount(a.name, id)
|
|
mountpoint, err := a.proxy.Mount(a.name, id)
|
|
- a.eMount = hostPath(a.baseHostPath, mountpoint)
|
|
|
|
|
|
+ a.eMount = a.scopePath(mountpoint)
|
|
return a.eMount, err
|
|
return a.eMount, err
|
|
}
|
|
}
|
|
|
|
|