ScaleIO: Use VolumeHost.GetExec() to execute utilities

This prepares volume plugins to run things in containers instead of running
them on the host.

As consequence, a mount.Exec interface needs to be passed from VolumeHost
down to SioClient.
This commit is contained in:
Jan Safranek 2017-08-22 13:27:59 +02:00
parent dbaf41e92a
commit 158017cef7
4 changed files with 21 additions and 13 deletions

View File

@ -21,7 +21,6 @@ import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
@ -30,6 +29,8 @@ import (
"sync"
"time"
"k8s.io/kubernetes/pkg/util/mount"
sio "github.com/codedellemc/goscaleio"
siotypes "github.com/codedellemc/goscaleio/types/v1"
"github.com/golang/glog"
@ -77,13 +78,15 @@ type sioClient struct {
inited bool
diskRegex *regexp.Regexp
mtx sync.Mutex
exec mount.Exec
}
func newSioClient(gateway, username, password string, sslEnabled bool) (*sioClient, error) {
func newSioClient(gateway, username, password string, sslEnabled bool, exec mount.Exec) (*sioClient, error) {
client := new(sioClient)
client.gateway = gateway
client.username = username
client.password = password
client.exec = exec
if sslEnabled {
client.insecure = false
client.certsEnabled = true
@ -296,7 +299,7 @@ func (c *sioClient) IID() (string, error) {
if c.instanceID == "" {
cmd := c.getSdcCmd()
output, err := exec.Command(cmd, "--query_guid").Output()
output, err := c.exec.Run(cmd, "--query_guid")
if err != nil {
glog.Error(log("drv_cfg --query_guid failed: %v", err))
return "", err
@ -355,7 +358,7 @@ func (c *sioClient) Devs() (map[string]string, error) {
volumeMap := make(map[string]string)
// grab the sdc tool output
out, err := exec.Command(c.getSdcCmd(), "--query_vols").Output()
out, err := c.exec.Run(c.getSdcCmd(), "--query_vols")
if err != nil {
glog.Error(log("sdc --query_vols failed: %v", err))
return nil, err

View File

@ -20,6 +20,8 @@ import (
"errors"
"strconv"
"k8s.io/kubernetes/pkg/util/mount"
"github.com/golang/glog"
siotypes "github.com/codedellemc/goscaleio/types/v1"
@ -36,9 +38,10 @@ type storageInterface interface {
type sioMgr struct {
client sioInterface
configData map[string]string
exec mount.Exec
}
func newSioMgr(configs map[string]string) (*sioMgr, error) {
func newSioMgr(configs map[string]string, exec mount.Exec) (*sioMgr, error) {
if configs == nil {
return nil, errors.New("missing configuration data")
}
@ -47,7 +50,7 @@ func newSioMgr(configs map[string]string) (*sioMgr, error) {
configs[confKey.sdcRootPath] = defaultString(configs[confKey.sdcRootPath], sdcRootPath)
configs[confKey.storageMode] = defaultString(configs[confKey.storageMode], "ThinProvisioned")
mgr := &sioMgr{configData: configs}
mgr := &sioMgr{configData: configs, exec: exec}
return mgr, nil
}
@ -67,7 +70,7 @@ func (m *sioMgr) getClient() (sioInterface, error) {
certsEnabled := b
glog.V(4).Info(log("creating new client for gateway %s", gateway))
client, err := newSioClient(gateway, username, password, certsEnabled)
client, err := newSioClient(gateway, username, password, certsEnabled, m.exec)
if err != nil {
glog.Error(log("failed to create scaleio client: %v", err))
return nil, err

View File

@ -21,6 +21,8 @@ import (
"testing"
"time"
"k8s.io/kubernetes/pkg/util/mount"
siotypes "github.com/codedellemc/goscaleio/types/v1"
)
@ -42,7 +44,7 @@ var (
)
func newTestMgr(t *testing.T) *sioMgr {
mgr, err := newSioMgr(fakeConfig)
mgr, err := newSioMgr(fakeConfig, mount.NewFakeExec(nil))
if err != nil {
t.Error(err)
}
@ -51,7 +53,7 @@ func newTestMgr(t *testing.T) *sioMgr {
}
func TestMgrNew(t *testing.T) {
mgr, err := newSioMgr(fakeConfig)
mgr, err := newSioMgr(fakeConfig, mount.NewFakeExec(nil))
if err != nil {
t.Fatal(err)
}

View File

@ -386,7 +386,7 @@ func (v *sioVolume) setSioMgr() error {
return err
}
mgr, err := newSioMgr(configData)
mgr, err := newSioMgr(configData, v.plugin.host.GetExec(v.plugin.GetPluginName()))
if err != nil {
glog.Error(log("failed to reset sio manager: %v", err))
return err
@ -418,7 +418,7 @@ func (v *sioVolume) resetSioMgr() error {
return err
}
mgr, err := newSioMgr(configData)
mgr, err := newSioMgr(configData, v.plugin.host.GetExec(v.plugin.GetPluginName()))
if err != nil {
glog.Error(log("failed to reset scaleio mgr: %v", err))
return err
@ -452,7 +452,7 @@ func (v *sioVolume) setSioMgrFromConfig() error {
return err
}
mgr, err := newSioMgr(data)
mgr, err := newSioMgr(data, v.plugin.host.GetExec(v.plugin.GetPluginName()))
if err != nil {
glog.Error(log("failed while setting scaleio mgr from config: %v", err))
return err
@ -481,7 +481,7 @@ func (v *sioVolume) setSioMgrFromSpec() error {
return err
}
mgr, err := newSioMgr(configData)
mgr, err := newSioMgr(configData, v.plugin.host.GetExec(v.plugin.GetPluginName()))
if err != nil {
glog.Error(log("failed to reset sio manager: %v", err))
return err