mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-22 21:10:22 +00:00
cephfs/volume: fixed arguments for ceph-fuse; assume volume root and cephx user already exist
This commit is contained in:
parent
43c2fb8e26
commit
436bb54262
@ -17,50 +17,17 @@ limitations under the License.
|
||||
package cephfs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
const (
|
||||
// from https://github.com/kubernetes-incubator/external-storage/tree/master/ceph/cephfs/cephfs_provisioner
|
||||
provisionerCmd = "/cephfs_provisioner.py"
|
||||
userPrefix = "user-"
|
||||
)
|
||||
|
||||
type volume struct {
|
||||
Root string `json:"path"`
|
||||
User string `json:"user"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
func newVolume(volId *volumeIdentifier, volOpts *volumeOptions) (*volume, error) {
|
||||
cmd := exec.Command(provisionerCmd, "-n", volId.id, "-u", userPrefix+volId.id)
|
||||
cmd.Env = []string{
|
||||
"CEPH_CLUSTER_NAME=" + volOpts.ClusterName,
|
||||
"CEPH_MON=" + volOpts.Monitor,
|
||||
"CEPH_AUTH_ID=" + volOpts.AdminId,
|
||||
"CEPH_AUTH_KEY=" + volOpts.AdminSecret,
|
||||
}
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cephfs: an error occurred while creating the volume: %v\ncephfs: %s", err, out)
|
||||
}
|
||||
|
||||
fmt.Printf("\t\tcephfs_provisioner.py: %s\n", out)
|
||||
|
||||
vol := &volume{}
|
||||
if err = json.Unmarshal(out, vol); err != nil {
|
||||
return nil, fmt.Errorf("cephfs: malformed json output: %s", err)
|
||||
}
|
||||
|
||||
return vol, nil
|
||||
RootPath string
|
||||
User string
|
||||
}
|
||||
|
||||
func (vol *volume) mount(mountPoint string) error {
|
||||
out, err := execCommand("ceph-fuse", mountPoint, "-n", vol.User, "-r", vol.Root)
|
||||
out, err := execCommand("ceph-fuse", mountPoint, "-n", "client."+vol.User, "-r", vol.RootPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cephfs: ceph-fuse failed with following error: %s\ncephfs: cephf-fuse output: %s", err, out)
|
||||
}
|
||||
@ -69,7 +36,7 @@ func (vol *volume) mount(mountPoint string) error {
|
||||
}
|
||||
|
||||
func (vol *volume) unmount() error {
|
||||
out, err := execCommand("fusermount", "-u", vol.Root)
|
||||
out, err := execCommand("fusermount", "-u", vol.RootPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cephfs: fusermount failed with following error: %v\ncephfs: fusermount output: %s", err, out)
|
||||
}
|
||||
@ -77,13 +44,6 @@ func (vol *volume) unmount() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vol *volume) makeMap() map[string]string {
|
||||
return map[string]string{
|
||||
"path": vol.Root,
|
||||
"user": vol.User,
|
||||
}
|
||||
}
|
||||
|
||||
func unmountVolume(root string) error {
|
||||
out, err := execCommand("fusermount", "-u", root)
|
||||
if err != nil {
|
||||
@ -93,15 +53,6 @@ func unmountVolume(root string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteVolume(volId, user string) error {
|
||||
out, err := execCommand(provisionerCmd, "--remove", "-n", volId, "-u", user)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cephfs: failed to delete volume %s following error: %v\ncephfs: output: %s", volId, err, out)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func createMountPoint(root string) error {
|
||||
return os.MkdirAll(root, 0750)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user