-
-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add build flag to link the go-fuseftp implementation.
This build-flag is not enabled by default, but can be used when there is a desire to build a telepresence client that links the fuseftp implementation instead of using a remote process via gRPC. Signed-off-by: Thomas Hallgren <[email protected]>
- Loading branch information
Showing
12 changed files
with
141 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//go:build !docker | ||
//go:build !docker && !linked_fuseftp | ||
|
||
package remotefs | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,35 @@ | ||
//go:build docker | ||
// +build docker | ||
|
||
package remotefs | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"sync" | ||
|
||
"github.com/telepresenceio/go-fuseftp/rpc" | ||
) | ||
|
||
// NewFTPMounter returns nil. It's here to satisfy the linker. | ||
func NewFTPMounter(rpc.FuseFTPClient, *sync.WaitGroup) Mounter { | ||
return nil | ||
} | ||
|
||
type fuseFtpMgr struct{} | ||
|
||
type FuseFTPManager interface { | ||
DeferInit(ctx context.Context) error | ||
GetFuseFTPClient(ctx context.Context) rpc.FuseFTPClient | ||
DeferInit(context.Context) error | ||
GetFuseFTPClient(context.Context) rpc.FuseFTPClient | ||
} | ||
|
||
func NewFuseFTPManager() FuseFTPManager { | ||
return &fuseFtpMgr{} | ||
} | ||
|
||
func (s *fuseFtpMgr) DeferInit(ctx context.Context) error { | ||
func (s *fuseFtpMgr) DeferInit(context.Context) error { | ||
return errors.New("fuseftp client is not available") | ||
} | ||
|
||
func (s *fuseFtpMgr) GetFuseFTPClient(ctx context.Context) rpc.FuseFTPClient { | ||
func (s *fuseFtpMgr) GetFuseFTPClient(context.Context) rpc.FuseFTPClient { | ||
return nil | ||
} |
2 changes: 1 addition & 1 deletion
2
pkg/client/remotefs/fuseftpembed.go → pkg/client/remotefs/fuseftp_embedded.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//go:build embed_fuseftp && !docker | ||
//go:build !(docker || external_fuseftp || linked_fuseftp) | ||
|
||
package remotefs | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
pkg/client/remotefs/fuseftpextern.go → pkg/client/remotefs/fuseftp_external.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//go:build !embed_fuseftp && !docker | ||
//go:build external_fuseftp && !docker | ||
|
||
package remotefs | ||
|
||
|
2 changes: 2 additions & 0 deletions
2
pkg/client/remotefs/ftp.go → pkg/client/remotefs/fuseftp_grpc.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !(linked_fuseftp || docker) | ||
|
||
package remotefs | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//go:build linked_fuseftp && !docker | ||
|
||
package remotefs | ||
|
||
import ( | ||
"context" | ||
"net/netip" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/datawire/dlib/dlog" | ||
"github.com/telepresenceio/go-fuseftp/pkg/fs" | ||
"github.com/telepresenceio/go-fuseftp/rpc" | ||
"github.com/telepresenceio/telepresence/v2/pkg/agentconfig" | ||
"github.com/telepresenceio/telepresence/v2/pkg/client" | ||
) | ||
|
||
type ftpMounter struct { | ||
mountPoint string | ||
cancel context.CancelFunc | ||
ftpClient fs.FTPClient | ||
iceptWG *sync.WaitGroup | ||
} | ||
|
||
type fuseFtpMgr struct{} | ||
|
||
type FuseFTPManager interface { | ||
DeferInit(ctx context.Context) error | ||
GetFuseFTPClient(ctx context.Context) rpc.FuseFTPClient | ||
} | ||
|
||
func NewFuseFTPManager() FuseFTPManager { | ||
return &fuseFtpMgr{} | ||
} | ||
|
||
func (s *fuseFtpMgr) DeferInit(_ context.Context) error { | ||
return nil | ||
} | ||
|
||
func (s *fuseFtpMgr) GetFuseFTPClient(_ context.Context) rpc.FuseFTPClient { | ||
return rpc.NewFuseFTPClient(nil) | ||
} | ||
|
||
func NewFTPMounter(_ rpc.FuseFTPClient, iceptWG *sync.WaitGroup) Mounter { | ||
// The FTPClient uses the global logrus logger. It's very verbose on DebugLevel. | ||
logrus.SetLevel(logrus.InfoLevel) | ||
return &ftpMounter{iceptWG: iceptWG} | ||
} | ||
|
||
func (m *ftpMounter) Start(ctx context.Context, workload, container, clientMountPoint, mountPoint string, podAddrPort netip.AddrPort, ro bool) error { | ||
roTxt := "" | ||
if ro { | ||
roTxt = " read-only" | ||
} | ||
if m.ftpClient == nil { | ||
cfg := client.GetConfig(ctx) | ||
dlog.Infof(ctx, "Mounting FTP file system for container %s[%s] (address %s)%s at %q", workload, container, podAddrPort, roTxt, clientMountPoint) | ||
// FTPs remote mount is already relative to the agentconfig.ExportsMountPoint | ||
rmp := strings.TrimPrefix(mountPoint, agentconfig.ExportsMountPoint) | ||
ftpClient, err := fs.NewFTPClient(ctx, podAddrPort, rmp, ro, cfg.Timeouts().Get(client.TimeoutFtpReadWrite)) | ||
if err != nil { | ||
return err | ||
} | ||
host := fs.NewHost(ftpClient, clientMountPoint) | ||
if err = host.Start(ctx, 5*time.Second); err != nil { | ||
return err | ||
} | ||
|
||
m.ftpClient = ftpClient | ||
// Ensure unmount when intercept context is cancelled | ||
m.iceptWG.Add(1) | ||
go func() { | ||
defer m.iceptWG.Done() | ||
<-ctx.Done() | ||
dlog.Debugf(ctx, "Unmounting FTP file system for container %s[%s] (address %s) at %q", workload, container, podAddrPort, clientMountPoint) | ||
}() | ||
dlog.Infof(ctx, "File system for container %s[%s] (address %s) successfully mounted%s at %q", workload, container, podAddrPort, roTxt, clientMountPoint) | ||
return nil | ||
} | ||
|
||
// Assign a new address to the FTP client. This kills any open connections but leaves the FUSE driver intact | ||
dlog.Infof(ctx, "Switching remote address to %s for FTP file system for workload container %s[%s] at %q", podAddrPort, workload, container, clientMountPoint) | ||
return m.ftpClient.SetAddress(podAddrPort) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters