From 480f05489315de9ec1c0a0c1c322596eea4d9348 Mon Sep 17 00:00:00 2001 From: Eric Li Date: Fri, 18 May 2018 14:18:26 +0800 Subject: [PATCH] feature: add volume drivers info for system info feature: add volume drivers info for system info Signed-off-by: Eric Li --- apis/swagger.yml | 7 +++++++ apis/types/system_info.go | 20 ++++++++++++++++++++ cli/info.go | 1 + daemon/mgr/system.go | 3 +++ storage/volume/driver/driver.go | 7 +++++++ test/api_system_test.go | 6 ++++++ 6 files changed, 44 insertions(+) diff --git a/apis/swagger.yml b/apis/swagger.yml index 5aa316cb4..d170305c2 100644 --- a/apis/swagger.yml +++ b/apis/swagger.yml @@ -1283,6 +1283,13 @@ definitions: description: | The logging driver to use as a default for new containers. type: "string" + VolumeDrivers: + description: | + The list of volume drivers which the pouchd supports + type: "array" + items: + type: "string" + example: ["local", "tmpfs"] CgroupDriver: description: | The driver to use for managing cgroups. diff --git a/apis/types/system_info.go b/apis/types/system_info.go index 3c77e0def..5ab35819c 100644 --- a/apis/types/system_info.go +++ b/apis/types/system_info.go @@ -207,6 +207,10 @@ type SystemInfo struct { // Version string of the daemon. // ServerVersion string `json:"ServerVersion,omitempty"` + + // The list of volume drivers which the pouchd supports + // + VolumeDrivers []string `json:"VolumeDrivers"` } /* polymorph SystemInfo Architecture false */ @@ -279,6 +283,8 @@ type SystemInfo struct { /* polymorph SystemInfo ServerVersion false */ +/* polymorph SystemInfo VolumeDrivers false */ + // Validate validates this system info func (m *SystemInfo) Validate(formats strfmt.Registry) error { var res []error @@ -328,6 +334,11 @@ func (m *SystemInfo) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateVolumeDrivers(formats); err != nil { + // prop + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -481,6 +492,15 @@ func (m *SystemInfo) validateSecurityOptions(formats strfmt.Registry) error { return nil } +func (m *SystemInfo) validateVolumeDrivers(formats strfmt.Registry) error { + + if swag.IsZero(m.VolumeDrivers) { // not required + return nil + } + + return nil +} + // MarshalBinary interface implementation func (m *SystemInfo) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/cli/info.go b/cli/info.go index e3f7c9823..f5e1dfa96 100644 --- a/cli/info.go +++ b/cli/info.go @@ -66,6 +66,7 @@ func prettyPrintInfo(cli *Cli, info *types.SystemInfo) error { fmt.Fprintln(os.Stdout, "Storage Driver:", info.Driver) fmt.Fprintln(os.Stdout, "Driver Status:", info.DriverStatus) fmt.Fprintln(os.Stdout, "Logging Driver:", info.LoggingDriver) + fmt.Fprintln(os.Stdout, "Volume Drivers:", info.VolumeDrivers) fmt.Fprintln(os.Stdout, "Cgroup Driver:", info.CgroupDriver) if len(info.Runtimes) > 0 { fmt.Fprintln(os.Stdout, "Runtimes:") diff --git a/daemon/mgr/system.go b/daemon/mgr/system.go index be0942470..25e8d57ad 100644 --- a/daemon/mgr/system.go +++ b/daemon/mgr/system.go @@ -15,6 +15,7 @@ import ( "github.com/alibaba/pouch/pkg/meta" "github.com/alibaba/pouch/pkg/system" "github.com/alibaba/pouch/registry" + volumedriver "github.com/alibaba/pouch/storage/volume/driver" "github.com/alibaba/pouch/version" "github.com/pkg/errors" @@ -103,6 +104,7 @@ func (mgr *SystemManager) Info() (types.SystemInfo, error) { if err != nil { logrus.Warnf("failed to get image info: %v", err) } + volumeDrivers := volumedriver.AllDriversName() info := types.SystemInfo{ Architecture: runtime.GOARCH, @@ -128,6 +130,7 @@ func (mgr *SystemManager) Info() (types.SystemInfo, error) { Labels: mgr.config.Labels, LiveRestoreEnabled: true, LoggingDriver: mgr.config.DefaultLogConfig.LogDriver, + VolumeDrivers: volumeDrivers, LxcfsEnabled: mgr.config.IsLxcfsEnabled, MemTotal: totalMem, Name: hostname, diff --git a/storage/volume/driver/driver.go b/storage/volume/driver/driver.go index 953f3f4ee..e647080b1 100644 --- a/storage/volume/driver/driver.go +++ b/storage/volume/driver/driver.go @@ -3,6 +3,7 @@ package driver import ( "fmt" "regexp" + "sort" "sync" "github.com/alibaba/pouch/plugins" @@ -220,6 +221,9 @@ func Exist(name string) bool { // AllDriversName return all registered backend driver's name. func AllDriversName() []string { + // probing all volume plugins. + backendDrivers.GetAll() + backendDrivers.Lock() defer backendDrivers.Unlock() @@ -228,6 +232,9 @@ func AllDriversName() []string { names = append(names, n) } + // sort the names. + sort.Strings(names) + return names } diff --git a/test/api_system_test.go b/test/api_system_test.go index f7f4bed55..28a60fa1a 100644 --- a/test/api_system_test.go +++ b/test/api_system_test.go @@ -51,6 +51,12 @@ func (suite *APISystemSuite) TestInfo(c *check.C) { c.Assert(got.ServerVersion, check.Equals, version.Version) c.Assert(got.Driver, check.Equals, "overlayfs") c.Assert(got.NCPU, check.Equals, int64(runtime.NumCPU())) + + // Check the volume drivers + c.Assert(len(got.VolumeDrivers), check.Equals, 3) + c.Assert(got.VolumeDrivers[0], check.Equals, "ceph") + c.Assert(got.VolumeDrivers[1], check.Equals, "local") + c.Assert(got.VolumeDrivers[2], check.Equals, "tmpfs") } // TestVersion tests /version API.