aboutsummaryrefslogtreecommitdiff
path: root/pkg/driver/mounter.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-05-31 02:24:20 -0700
committerChris Lu <chris.lu@gmail.com>2020-05-31 02:24:20 -0700
commit5e19cfc577d447604d57f5a8c770ae4acaccfbcd (patch)
tree346309f201de066a11c1fac03e6a89f380bc3deb /pkg/driver/mounter.go
parentb21fb2e2b62dd9ec3cf13403e87687229424f1e0 (diff)
downloadseaweedfs-csi-driver-5e19cfc577d447604d57f5a8c770ae4acaccfbcd.tar.xz
seaweedfs-csi-driver-5e19cfc577d447604d57f5a8c770ae4acaccfbcd.zip
it can compile now!
Diffstat (limited to 'pkg/driver/mounter.go')
-rw-r--r--pkg/driver/mounter.go87
1 files changed, 87 insertions, 0 deletions
diff --git a/pkg/driver/mounter.go b/pkg/driver/mounter.go
new file mode 100644
index 0000000..e94544d
--- /dev/null
+++ b/pkg/driver/mounter.go
@@ -0,0 +1,87 @@
+package driver
+
+import (
+ "fmt"
+ "time"
+
+ "github.com/chrislusf/seaweedfs/weed/pb"
+ "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
+ "github.com/chrislusf/seaweedfs/weed/security"
+ "github.com/chrislusf/seaweedfs/weed/util"
+ "github.com/golang/glog"
+ "google.golang.org/grpc"
+ "os/exec"
+ "k8s.io/utils/mount"
+)
+
+// Config holds values to configure the driver
+type Config struct {
+ // Region string
+ Filer string
+}
+
+type Mounter interface {
+ Mount(target string) error
+}
+
+func newMounter(bucketName string, cfg *Config) (Mounter, error) {
+ return newSeaweedFsMounter(bucketName, cfg)
+}
+
+func fuseMount(path string, command string, args []string) error {
+ cmd := exec.Command(command, args...)
+ glog.V(3).Infof("Mounting fuse with command: %s and args: %s", command, args)
+
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ return fmt.Errorf("Error fuseMount command: %s\nargs: %s\noutput: %s", command, args, out)
+ }
+
+ return waitForMount(path, 10*time.Second)
+}
+
+func fuseUnmount(path string) error {
+ if err := mount.New("").Unmount(path); err != nil {
+ return err
+ }
+ // as fuse quits immediately, we will try to wait until the process is done
+ process, err := findFuseMountProcess(path)
+ if err != nil {
+ glog.Errorf("Error getting PID of fuse mount: %s", err)
+ return nil
+ }
+ if process == nil {
+ glog.Warningf("Unable to find PID of fuse mount %s, it must have finished already", path)
+ return nil
+ }
+ glog.Infof("Found fuse pid %v of mount %s, checking if it still runs", process.Pid, path)
+ return waitForProcess(process, 1)
+}
+
+func newConfigFromSecrets(secrets map[string]string) *Config {
+ t := &Config{
+ Filer: secrets["filer"],
+ }
+ return t
+}
+
+var _ = filer_pb.FilerClient(&Config{})
+
+func (cfg *Config) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
+
+ filerGrpcAddress, parseErr := pb.ParseServerToGrpcAddress(cfg.Filer)
+ if parseErr != nil {
+ return fmt.Errorf("failed to parse filer %v: %v", filerGrpcAddress, parseErr)
+ }
+
+ grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
+
+ return pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
+ client := filer_pb.NewSeaweedFilerClient(grpcConnection)
+ return fn(client)
+ }, filerGrpcAddress, grpcDialOption)
+
+}
+func (cfg *Config) AdjustedUrl(hostAndPort string) string {
+ return hostAndPort
+}