github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/client/userd/trafficmgr/mount.go (about) 1 package trafficmgr 2 3 import ( 4 "context" 5 "sync" 6 7 "github.com/datawire/dlib/dlog" 8 "github.com/datawire/go-fuseftp/rpc" 9 "github.com/telepresenceio/telepresence/v2/pkg/client" 10 "github.com/telepresenceio/telepresence/v2/pkg/client/remotefs" 11 "github.com/telepresenceio/telepresence/v2/pkg/client/userd" 12 "github.com/telepresenceio/telepresence/v2/pkg/iputil" 13 ) 14 15 func (ic *intercept) shouldMount() bool { 16 return (ic.FtpPort > 0 || ic.SftpPort > 0) && (ic.localMountPort > 0 || ic.ClientMountPoint != "") 17 } 18 19 // startMount starts the mount for the given podInterceptKey. 20 // It assumes that the user has called shouldMount and is sure that something will be started. 21 func (ic *intercept) startMount(ctx context.Context, iceptWG, podWG *sync.WaitGroup) { 22 var fuseftp rpc.FuseFTPClient 23 useFtp := client.GetConfig(ctx).Intercept().UseFtp 24 var port int32 25 mountCtx := ctx 26 if useFtp { 27 if ic.FtpPort == 0 { 28 dlog.Errorf(ctx, "Client is configured to perform remote mounts using FTP, but only SFTP is provided by the traffic-agent") 29 return 30 } 31 if ic.localMountPort > 0 { 32 dlog.Errorf(ctx, "Client is configured to perform remote mounts using FTP, but only SFTP can be used with --local-mount-port") 33 return 34 } 35 // The FTP mounter survives multiple starts for the same intercept. It just resets the address 36 mountCtx = ic.ctx 37 if fuseftp = userd.GetService(ctx).FuseFTPMgr().GetFuseFTPClient(ctx); fuseftp == nil { 38 dlog.Errorf(ctx, "Client is configured to perform remote mounts using FTP, but the fuseftp server was unable to start") 39 return 40 } 41 port = ic.FtpPort 42 } else { 43 if ic.SftpPort == 0 { 44 dlog.Errorf(ctx, "Client is configured to perform remote mounts using SFTP, but only FTP is provided by the traffic-agent") 45 return 46 } 47 port = ic.SftpPort 48 } 49 50 m := ic.Mounter 51 if m == nil { 52 switch { 53 case ic.localMountPort != 0: 54 session := userd.GetSession(ctx) 55 m = remotefs.NewBridgeMounter(session.SessionInfo().SessionId, session.ManagerClient(), uint16(ic.localMountPort)) 56 case useFtp: 57 m = remotefs.NewFTPMounter(fuseftp, iceptWG) 58 default: 59 m = remotefs.NewSFTPMounter(iceptWG, podWG) 60 } 61 ic.Mounter = m 62 } 63 err := m.Start(mountCtx, ic.Id, ic.ClientMountPoint, ic.MountPoint, iputil.Parse(ic.PodIp), uint16(port)) 64 if err != nil && ctx.Err() == nil { 65 dlog.Error(ctx, err) 66 } 67 }