Skip to content

Commit

Permalink
Merge pull request #1224 from rudyfly/volume-alias
Browse files Browse the repository at this point in the history
feature: add volume driver alias
  • Loading branch information
HusterWan authored Apr 26, 2018
2 parents f78d01d + ef921e3 commit dd5bda9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion daemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Config struct {
sync.Mutex

//Volume config
VolumeConfig volume.Config
VolumeConfig volume.Config `json:"volume-config"`

// Network config
NetworkConfg network.Config
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ func setupFlags(cmd *cobra.Command) {
flagSet.StringVar(&cfg.QuotaDriver, "quota-driver", "", "Set quota driver(grpquota/prjquota), if not set, it will set by kernel version")
flagSet.StringVar(&cfg.ConfigFile, "config-file", "/etc/pouch/config.json", "Configuration file of pouchd")

// volume config
flagSet.StringVar(&cfg.VolumeConfig.DriverAlias, "volume-driver-alias", "", "Set volume driver alias, <name=alias>[;name1=alias1]")

// cgroup-path flag is to set parent cgroup for all containers, default is "default" staying with containerd's configuration.
flagSet.StringVar(&cfg.CgroupParent, "cgroup-parent", "default", "Set parent cgroup for all containers")
flagSet.StringVar(&cfg.PluginPath, "plugin", "", "Set the path where plugin shared library file put")
Expand Down
5 changes: 3 additions & 2 deletions storage/volume/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Config struct {
ControlAddress string
Timeout time.Duration // operation timeout.
RemoveVolume bool
DefaultBackend string
VolumeMetaPath string
DefaultBackend string `json:"volume-default-driver"`
VolumeMetaPath string `json:"volume-meta-dir"`
DriverAlias string `json:"volume-driver-alias"`
}
15 changes: 15 additions & 0 deletions storage/volume/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package volume
import (
"fmt"
"reflect"
"strings"

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

if cfg.DriverAlias != "" {
parts := strings.Split(cfg.DriverAlias, ";")
for _, p := range parts {
alias := strings.Split(p, "=")
if len(alias) != 2 {
return nil, errors.Errorf("invalid driver alias: %s", p)
}

if err := driver.Alias(alias[0], alias[1]); err != nil {
return nil, errors.Wrapf(err, "failed to set driver alias: %s", p)
}
}
}

volumeStore, err := metastore.NewStore(metastore.Config{
Driver: "boltdb",
BaseDir: cfg.VolumeMetaPath,
Expand Down
20 changes: 20 additions & 0 deletions storage/volume/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,23 @@ func ListDriverOption(name string) map[string]types.Option {
}
return nil
}

// Alias is used to add driver name's alias into exist driver.
func Alias(name, alias string) error {
d, exist := backendDrivers.Get(name)
if !exist {
return errors.Errorf("volume driver: %s is not exist", name)
}

matched, err := regexp.MatchString(driverNameRegexp, alias)
if err != nil {
return err
}
if !matched {
return errors.Errorf("Invalid driver name: %s, not match: %s", name, driverNameRegexp)
}

backendDrivers.Add(alias, d)

return nil
}

0 comments on commit dd5bda9

Please sign in to comment.