Skip to content

Commit

Permalink
Stability improvements
Browse files Browse the repository at this point in the history
- Use stat Ino and Dev to determine when the mount is in place.
- Let Create actually mount (so that it fails if it can't).
- Add server polling so that peer drops are detected.

Signed-off-by: Thomas Hallgren <[email protected]>
  • Loading branch information
thallgren committed Feb 25, 2024
1 parent baa8a10 commit bdc394e
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 60 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ $ docker plugin install datawire/telemount:arm64 --alias telemount
Create an intercept. Use `--local-mount-port 1234` to set up a bridge instead of mounting, and `--detailed-ouput --output yaml` so that
the command outputs the environment in a readable form:
```console
$ telepresence intercept --local-mount-port 1234 --port 8080 --http-header who=me --detailed-output --output yaml echo-easy
$ telepresence connect
$ telepresence intercept --local-mount-port 1234 --port 8080 --detailed-output --output yaml echo-easy
...
TELEPRESENCE_CONTAINER: echo-easy
TELEPRESENCE_MOUNTS: /var/run/secrets/kubernetes.io
Expand All @@ -51,6 +52,21 @@ namespace
token
```

## Debugging

Start by building the plugin for debugging. This command both builds and enables the plugin:
```console
$ make debug
```

Figure out the ID of the plugin:
```console
$ PLUGIN_ID=`docker plugin inspect -f='{{json .Id}}' datawire/telemount:amd64 | xargs`
```
and start viewing what it prints on stderr. All logging goes to stderr:
```
$ sudo cat /run/docker/plugins/$PLUGIN_ID/$PLUGIN_ID-stderr
```
## Credits
To the [Rclone project](https://github.com/rclone/rclone) project and [PR 5668](https://github.com/rclone/rclone/pull/5668)
specifically for showing a good way to create multi-arch plugins.
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ module github.com/datawire/docker-volume-telemount

go 1.21

require github.com/docker/go-plugins-helpers v0.0.0-20211224144127-6eecb7beb651
require (
github.com/docker/go-plugins-helpers v0.0.0-20211224144127-6eecb7beb651
golang.org/x/sys v0.17.0
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/docker/go-connections v0.5.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/tools v0.17.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/tools v0.18.0 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-plugins-helpers v0.0.0-20211224144127-6eecb7beb651 h1:YcvzLmdrP/b8kLAGJ8GT7bdncgCAiWxJZIlt84D+RJg=
github.com/docker/go-plugins-helpers v0.0.0-20211224144127-6eecb7beb651/go.mod h1:LFyLie6XcDbyKGeVK6bHe+9aJTYCxWLBg5IrJZOaXKA=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
4 changes: 2 additions & 2 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func Fatal(v any) {
}

func Info(v any) {
_, _ = fmt.Fprintln(os.Stdout, v)
_, _ = fmt.Fprintln(os.Stderr, v)
}

func Infof(format string, args ...any) {
fprintfln(os.Stdout, format, args...)
fprintfln(os.Stderr, format, args...)
}

func Debug(v any) {
Expand Down
45 changes: 26 additions & 19 deletions pkg/sftp/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

type driver struct {
// All access to the driver is synchronized using this lock
sync.RWMutex
lock sync.RWMutex
volumePath string
remoteMounts map[string]*mount
}
Expand Down Expand Up @@ -86,9 +86,13 @@ func (d *driver) Create(r *volume.CreateRequest) (err error) {
} else {
dir = filepath.Join(container, strings.TrimPrefix(dir, "/"))
}
d.Lock()
d.getRemoteMount(host, port).addVolume(r.Name, dir)
d.Unlock()
d.lock.Lock()
defer d.lock.Unlock()
m, err := d.getRemoteMount(host, port)
if err != nil {
return err
}
m.addVolume(r.Name, dir)
return nil
}

Expand All @@ -97,8 +101,8 @@ func (d *driver) Remove(r *volume.RemoveRequest) (err error) {
defer func() {
logResponse(err, "Remove %s return", r.Name)
}()
d.Lock()
defer d.Unlock()
d.lock.Lock()
defer d.lock.Unlock()

var v *volumeDir
if v, err = d.getVolume(r.Name); err != nil {
Expand All @@ -118,8 +122,8 @@ func (d *driver) Mount(r *volume.MountRequest) (mr *volume.MountResponse, err er
defer func() {
logResponse(err, "Mount %s return %s", r.Name, mr.Mountpoint)
}()
d.Lock()
defer d.Unlock()
d.lock.Lock()
defer d.lock.Unlock()

var v *volumeDir
if v, err = d.getMountedVolume(r.Name); err != nil {
Expand All @@ -146,9 +150,9 @@ func (d *driver) Mount(r *volume.MountRequest) (mr *volume.MountResponse, err er

func (d *driver) Path(r *volume.PathRequest) (*volume.PathResponse, error) {
log.Debugf("Path %s", r.Name)
d.RLock()
d.lock.RLock()
v, err := d.getVolume(r.Name)
d.RUnlock()
d.lock.RUnlock()
pr := &volume.PathResponse{}
if err == nil {
pr.Mountpoint = v.logicalMountPoint()
Expand All @@ -162,8 +166,8 @@ func (d *driver) Unmount(r *volume.UnmountRequest) (err error) {
defer func() {
logResponse(err, "Unmount %s return", r.Name)
}()
d.Lock()
defer d.Unlock()
d.lock.Lock()
defer d.lock.Unlock()

var v *volumeDir
v, err = d.getVolume(r.Name)
Expand Down Expand Up @@ -199,24 +203,24 @@ func (d *driver) Unmount(r *volume.UnmountRequest) (err error) {
func (d *driver) Get(r *volume.GetRequest) (gr *volume.GetResponse, err error) {
log.Debugf("Get %s", r.Name)
gr = &volume.GetResponse{}
d.RLock()
d.lock.RLock()
v, err := d.getVolume(r.Name)
if err == nil {
gr.Volume = v.asVolume(r.Name)
}
d.RUnlock()
d.lock.RUnlock()
logResponse(err, "Get %s return %v", r.Name, gr.Volume)
return gr, err
}

func (d *driver) List() (*volume.ListResponse, error) {
log.Debug("List")
d.RLock()
d.lock.RLock()
var vols = make([]*volume.Volume, 0, 32)
for _, m := range d.remoteMounts {
vols = m.appendVolumes(vols)
}
d.RUnlock()
d.lock.RUnlock()
sort.Slice(vols, func(i, j int) bool {
return vols[i].Name < vols[j].Name
})
Expand All @@ -228,15 +232,18 @@ func (d *driver) Capabilities() *volume.CapabilitiesResponse {
return &volume.CapabilitiesResponse{Capabilities: volume.Capability{Scope: "local"}}
}

func (d *driver) getRemoteMount(host string, port uint16) *mount {
func (d *driver) getRemoteMount(host string, port uint16) (*mount, error) {
ps := strconv.Itoa(int(port))
key := net.JoinHostPort(host, ps)
if m, ok := d.remoteMounts[key]; ok {
return m
return m, nil
}
m := newMount(filepath.Join(d.volumePath, host, ps), host, port)
if err := m.mountVolume(); err != nil {
return nil, err
}
d.remoteMounts[key] = m
return m
return m, nil
}

func (d *driver) getVolume(n string) (*volumeDir, error) {
Expand Down
Loading

0 comments on commit bdc394e

Please sign in to comment.