Skip to content

Commit dd5bda9

Browse files
authored
Merge pull request #1224 from rudyfly/volume-alias
feature: add volume driver alias
2 parents f78d01d + ef921e3 commit dd5bda9

File tree

5 files changed

+42
-3
lines changed

5 files changed

+42
-3
lines changed

daemon/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Config struct {
2323
sync.Mutex
2424

2525
//Volume config
26-
VolumeConfig volume.Config
26+
VolumeConfig volume.Config `json:"volume-config"`
2727

2828
// Network config
2929
NetworkConfg network.Config

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ func setupFlags(cmd *cobra.Command) {
9595
flagSet.StringVar(&cfg.QuotaDriver, "quota-driver", "", "Set quota driver(grpquota/prjquota), if not set, it will set by kernel version")
9696
flagSet.StringVar(&cfg.ConfigFile, "config-file", "/etc/pouch/config.json", "Configuration file of pouchd")
9797

98+
// volume config
99+
flagSet.StringVar(&cfg.VolumeConfig.DriverAlias, "volume-driver-alias", "", "Set volume driver alias, <name=alias>[;name1=alias1]")
100+
98101
// cgroup-path flag is to set parent cgroup for all containers, default is "default" staying with containerd's configuration.
99102
flagSet.StringVar(&cfg.CgroupParent, "cgroup-parent", "default", "Set parent cgroup for all containers")
100103
flagSet.StringVar(&cfg.PluginPath, "plugin", "", "Set the path where plugin shared library file put")

storage/volume/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type Config struct {
99
ControlAddress string
1010
Timeout time.Duration // operation timeout.
1111
RemoveVolume bool
12-
DefaultBackend string
13-
VolumeMetaPath string
12+
DefaultBackend string `json:"volume-default-driver"`
13+
VolumeMetaPath string `json:"volume-meta-dir"`
14+
DriverAlias string `json:"volume-driver-alias"`
1415
}

storage/volume/core.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package volume
33
import (
44
"fmt"
55
"reflect"
6+
"strings"
67

78
metastore "github.com/alibaba/pouch/pkg/meta"
89
"github.com/alibaba/pouch/storage/controlserver/client"
@@ -33,6 +34,20 @@ func NewCore(cfg Config) (*Core, error) {
3334
c.EnableControl = false
3435
}
3536

37+
if cfg.DriverAlias != "" {
38+
parts := strings.Split(cfg.DriverAlias, ";")
39+
for _, p := range parts {
40+
alias := strings.Split(p, "=")
41+
if len(alias) != 2 {
42+
return nil, errors.Errorf("invalid driver alias: %s", p)
43+
}
44+
45+
if err := driver.Alias(alias[0], alias[1]); err != nil {
46+
return nil, errors.Wrapf(err, "failed to set driver alias: %s", p)
47+
}
48+
}
49+
}
50+
3651
volumeStore, err := metastore.NewStore(metastore.Config{
3752
Driver: "boltdb",
3853
BaseDir: cfg.VolumeMetaPath,

storage/volume/driver/driver.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,23 @@ func ListDriverOption(name string) map[string]types.Option {
182182
}
183183
return nil
184184
}
185+
186+
// Alias is used to add driver name's alias into exist driver.
187+
func Alias(name, alias string) error {
188+
d, exist := backendDrivers.Get(name)
189+
if !exist {
190+
return errors.Errorf("volume driver: %s is not exist", name)
191+
}
192+
193+
matched, err := regexp.MatchString(driverNameRegexp, alias)
194+
if err != nil {
195+
return err
196+
}
197+
if !matched {
198+
return errors.Errorf("Invalid driver name: %s, not match: %s", name, driverNameRegexp)
199+
}
200+
201+
backendDrivers.Add(alias, d)
202+
203+
return nil
204+
}

0 commit comments

Comments
 (0)