Remove explicit etcdUrl/etcdPrefix from volume parameters
parent
19e2d9d6fa
commit
037cf64a47
|
@ -12,9 +12,6 @@ parameters:
|
||||||
etcdVolumePrefix: ""
|
etcdVolumePrefix: ""
|
||||||
poolId: "1"
|
poolId: "1"
|
||||||
# you can choose other configuration file if you have it in the config map
|
# you can choose other configuration file if you have it in the config map
|
||||||
|
# different etcd URLs and prefixes should also be put in the config
|
||||||
#configPath: "/etc/vitastor/vitastor.conf"
|
#configPath: "/etc/vitastor/vitastor.conf"
|
||||||
# you can also specify etcdUrl here, maybe to connect to another Vitastor cluster
|
|
||||||
# multiple etcdUrls may be specified, delimited by comma
|
|
||||||
#etcdUrl: "http://192.168.7.2:2379"
|
|
||||||
#etcdPrefix: "/vitastor"
|
|
||||||
allowVolumeExpansion: true
|
allowVolumeExpansion: true
|
||||||
|
|
|
@ -62,7 +62,7 @@ func NewControllerServer(driver *Driver) *ControllerServer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConnectionParams(params map[string]string) (map[string]string, []string, string)
|
func GetConnectionParams(params map[string]string) (map[string]string, error)
|
||||||
{
|
{
|
||||||
ctxVars := make(map[string]string)
|
ctxVars := make(map[string]string)
|
||||||
configPath := params["configPath"]
|
configPath := params["configPath"]
|
||||||
|
@ -75,55 +75,38 @@ func GetConnectionParams(params map[string]string) (map[string]string, []string,
|
||||||
ctxVars["configPath"] = configPath
|
ctxVars["configPath"] = configPath
|
||||||
}
|
}
|
||||||
config := make(map[string]interface{})
|
config := make(map[string]interface{})
|
||||||
if configFD, err := os.Open(configPath); err == nil
|
configFD, err := os.Open(configPath)
|
||||||
|
if (err != nil)
|
||||||
{
|
{
|
||||||
defer configFD.Close()
|
return nil, err
|
||||||
data, _ := ioutil.ReadAll(configFD)
|
|
||||||
json.Unmarshal(data, &config)
|
|
||||||
}
|
}
|
||||||
// Try to load prefix & etcd URL from the config
|
defer configFD.Close()
|
||||||
|
data, _ := ioutil.ReadAll(configFD)
|
||||||
|
json.Unmarshal(data, &config)
|
||||||
|
// Check etcd URL in the config, but do not use the explicit etcdUrl
|
||||||
|
// parameter for CLI calls, otherwise users won't be able to later
|
||||||
|
// change them - storage class parameters are saved in volume IDs
|
||||||
var etcdUrl []string
|
var etcdUrl []string
|
||||||
if (params["etcdUrl"] != "")
|
switch config["etcd_address"].(type)
|
||||||
{
|
{
|
||||||
ctxVars["etcdUrl"] = params["etcdUrl"]
|
case string:
|
||||||
etcdUrl = strings.Split(params["etcdUrl"], ",")
|
url := strings.Trim(config["etcd_address"].(string), " \t\r\n")
|
||||||
|
if (url != "")
|
||||||
|
{
|
||||||
|
etcdUrl = strings.Split(url, ",")
|
||||||
|
}
|
||||||
|
case []string:
|
||||||
|
etcdUrl = config["etcd_address"].([]string)
|
||||||
}
|
}
|
||||||
if (len(etcdUrl) == 0)
|
if (len(etcdUrl) == 0)
|
||||||
{
|
{
|
||||||
switch config["etcd_address"].(type)
|
return nil, status.Error(codes.InvalidArgument, "etcd_address is missing in "+configPath)
|
||||||
{
|
|
||||||
case string:
|
|
||||||
etcdUrl = strings.Split(config["etcd_address"].(string), ",")
|
|
||||||
case []string:
|
|
||||||
etcdUrl = config["etcd_address"].([]string)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
etcdPrefix := params["etcdPrefix"]
|
return ctxVars, nil
|
||||||
if (etcdPrefix == "")
|
|
||||||
{
|
|
||||||
etcdPrefix, _ = config["etcd_prefix"].(string)
|
|
||||||
if (etcdPrefix == "")
|
|
||||||
{
|
|
||||||
etcdPrefix = "/vitastor"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ctxVars["etcdPrefix"] = etcdPrefix
|
|
||||||
}
|
|
||||||
return ctxVars, etcdUrl, etcdPrefix
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func invokeCLI(ctxVars map[string]string, args []string) ([]byte, error)
|
func invokeCLI(ctxVars map[string]string, args []string) ([]byte, error)
|
||||||
{
|
{
|
||||||
if (ctxVars["etcdUrl"] != "")
|
|
||||||
{
|
|
||||||
args = append(args, "--etcd_address", ctxVars["etcdUrl"])
|
|
||||||
}
|
|
||||||
if (ctxVars["etcdPrefix"] != "")
|
|
||||||
{
|
|
||||||
args = append(args, "--etcd_prefix", ctxVars["etcdPrefix"])
|
|
||||||
}
|
|
||||||
if (ctxVars["configPath"] != "")
|
if (ctxVars["configPath"] != "")
|
||||||
{
|
{
|
||||||
args = append(args, "--config_path", ctxVars["configPath"])
|
args = append(args, "--config_path", ctxVars["configPath"])
|
||||||
|
@ -174,10 +157,10 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
|
||||||
volSize = ((capRange.GetRequiredBytes() + MB - 1) / MB) * MB
|
volSize = ((capRange.GetRequiredBytes() + MB - 1) / MB) * MB
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxVars, etcdUrl, _ := GetConnectionParams(req.Parameters)
|
ctxVars, err := GetConnectionParams(req.Parameters)
|
||||||
if (len(etcdUrl) == 0)
|
if (err != nil)
|
||||||
{
|
{
|
||||||
return nil, status.Error(codes.InvalidArgument, "no etcdUrl in storage class configuration and no etcd_address in vitastor.conf")
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{ "create", volName, "-s", fmt.Sprintf("%v", volSize), "--pool", fmt.Sprintf("%v", poolId) }
|
args := []string{ "create", volName, "-s", fmt.Sprintf("%v", volSize), "--pool", fmt.Sprintf("%v", poolId) }
|
||||||
|
@ -207,7 +190,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create image using vitastor-cli
|
// Create image using vitastor-cli
|
||||||
_, err := invokeCLI(ctxVars, args)
|
_, err = invokeCLI(ctxVars, args)
|
||||||
if (err != nil)
|
if (err != nil)
|
||||||
{
|
{
|
||||||
if (strings.Index(err.Error(), "already exists") > 0)
|
if (strings.Index(err.Error(), "already exists") > 0)
|
||||||
|
@ -257,7 +240,11 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
|
||||||
}
|
}
|
||||||
volName := volVars["name"]
|
volName := volVars["name"]
|
||||||
|
|
||||||
ctxVars, _, _ := GetConnectionParams(volVars)
|
ctxVars, err := GetConnectionParams(volVars)
|
||||||
|
if (err != nil)
|
||||||
|
{
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
_, err = invokeCLI(ctxVars, []string{ "rm", volName })
|
_, err = invokeCLI(ctxVars, []string{ "rm", volName })
|
||||||
if (err != nil)
|
if (err != nil)
|
||||||
|
@ -469,7 +456,11 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
|
||||||
volName := volVars["name"]
|
volName := volVars["name"]
|
||||||
snapName := volVars["snapshot"]
|
snapName := volVars["snapshot"]
|
||||||
|
|
||||||
ctxVars, _, _ := GetConnectionParams(volVars)
|
ctxVars, err := GetConnectionParams(volVars)
|
||||||
|
if (err != nil)
|
||||||
|
{
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
_, err = invokeCLI(ctxVars, []string{ "rm", volName+"@"+snapName })
|
_, err = invokeCLI(ctxVars, []string{ "rm", volName+"@"+snapName })
|
||||||
if (err != nil)
|
if (err != nil)
|
||||||
|
@ -496,7 +487,11 @@ func (cs *ControllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
|
||||||
return nil, status.Error(codes.Internal, "volume ID not in JSON format")
|
return nil, status.Error(codes.Internal, "volume ID not in JSON format")
|
||||||
}
|
}
|
||||||
volName := volVars["name"]
|
volName := volVars["name"]
|
||||||
ctxVars, _, _ := GetConnectionParams(volVars)
|
ctxVars, err := GetConnectionParams(volVars)
|
||||||
|
if (err != nil)
|
||||||
|
{
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
inodeCfg, err := invokeList(ctxVars, volName+"@*", false)
|
inodeCfg, err := invokeList(ctxVars, volName+"@*", false)
|
||||||
if (err != nil)
|
if (err != nil)
|
||||||
|
@ -555,7 +550,11 @@ func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi
|
||||||
return nil, status.Error(codes.Internal, "volume ID not in JSON format")
|
return nil, status.Error(codes.Internal, "volume ID not in JSON format")
|
||||||
}
|
}
|
||||||
volName := volVars["name"]
|
volName := volVars["name"]
|
||||||
ctxVars, _, _ := GetConnectionParams(volVars)
|
ctxVars, err := GetConnectionParams(volVars)
|
||||||
|
if (err != nil)
|
||||||
|
{
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
inodeCfg, err := invokeList(ctxVars, volName, true)
|
inodeCfg, err := invokeList(ctxVars, volName, true)
|
||||||
if (err != nil)
|
if (err != nil)
|
||||||
|
|
|
@ -114,19 +114,17 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
|
||||||
}
|
}
|
||||||
volName := ctxVars["name"]
|
volName := ctxVars["name"]
|
||||||
|
|
||||||
_, etcdUrl, etcdPrefix := GetConnectionParams(ctxVars)
|
_, err = GetConnectionParams(ctxVars)
|
||||||
if (len(etcdUrl) == 0)
|
if (err != nil)
|
||||||
{
|
{
|
||||||
return nil, status.Error(codes.InvalidArgument, "no etcdUrl in storage class configuration and no etcd_address in vitastor.conf")
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map NBD device
|
// Map NBD device
|
||||||
// FIXME: Check if already mapped
|
// FIXME: Check if already mapped
|
||||||
args := []string{
|
args := []string{
|
||||||
"map", "--etcd_address", strings.Join(etcdUrl, ","),
|
"map", "--image", volName,
|
||||||
"--etcd_prefix", etcdPrefix,
|
}
|
||||||
"--image", volName,
|
|
||||||
};
|
|
||||||
if (ctxVars["configPath"] != "")
|
if (ctxVars["configPath"] != "")
|
||||||
{
|
{
|
||||||
args = append(args, "--config_path", ctxVars["configPath"])
|
args = append(args, "--config_path", ctxVars["configPath"])
|
||||||
|
|
Loading…
Reference in New Issue