mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #27329 from dattatrayakumbhar04/26639_nfs_volume_with_hostname
#26639: Local NFS volumes do not resolve hostnames
This commit is contained in:
commit
5020905e9d
3 changed files with 41 additions and 1 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -349,3 +350,15 @@ func validateOpts(opts map[string]string) error {
|
||||||
func (v *localVolume) Status() map[string]interface{} {
|
func (v *localVolume) Status() map[string]interface{} {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getAddress finds out address/hostname from options
|
||||||
|
func getAddress(opts string) string {
|
||||||
|
optsList := strings.Split(opts, ",")
|
||||||
|
for i := 0; i < len(optsList); i++ {
|
||||||
|
if strings.HasPrefix(optsList[i], "addr=") {
|
||||||
|
addr := (strings.SplitN(optsList[i], "=", 2)[1])
|
||||||
|
return addr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
|
@ -12,6 +12,22 @@ import (
|
||||||
"github.com/docker/docker/pkg/mount"
|
"github.com/docker/docker/pkg/mount"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestGetAddress(t *testing.T) {
|
||||||
|
cases := map[string]string{
|
||||||
|
"addr=11.11.11.1": "11.11.11.1",
|
||||||
|
" ": "",
|
||||||
|
"addr=": "",
|
||||||
|
"addr=2001:db8::68": "2001:db8::68",
|
||||||
|
}
|
||||||
|
for name, success := range cases {
|
||||||
|
v := getAddress(name)
|
||||||
|
if v != success {
|
||||||
|
t.Errorf("Test case failed for %s actual: %s expected : %s", name, v, success)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestRemove(t *testing.T) {
|
func TestRemove(t *testing.T) {
|
||||||
// TODO Windows: Investigate why this test fails on Windows under CI
|
// TODO Windows: Investigate why this test fails on Windows under CI
|
||||||
// but passes locally.
|
// but passes locally.
|
||||||
|
|
|
@ -7,6 +7,7 @@ package local
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -71,6 +72,16 @@ func (v *localVolume) mount() error {
|
||||||
if v.opts.MountDevice == "" {
|
if v.opts.MountDevice == "" {
|
||||||
return fmt.Errorf("missing device in volume options")
|
return fmt.Errorf("missing device in volume options")
|
||||||
}
|
}
|
||||||
err := mount.Mount(v.opts.MountDevice, v.path, v.opts.MountType, v.opts.MountOpts)
|
mountOpts := v.opts.MountOpts
|
||||||
|
if v.opts.MountType == "nfs" {
|
||||||
|
if addrValue := getAddress(v.opts.MountOpts); addrValue != "" && net.ParseIP(addrValue).To4() == nil {
|
||||||
|
ipAddr, err := net.ResolveIPAddr("ip", addrValue)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "error resolving passed in nfs address")
|
||||||
|
}
|
||||||
|
mountOpts = strings.Replace(mountOpts, "addr="+addrValue, "addr="+ipAddr.String(), 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err := mount.Mount(v.opts.MountDevice, v.path, v.opts.MountType, mountOpts)
|
||||||
return errors.Wrapf(err, "error while mounting volume with options: %s", v.opts)
|
return errors.Wrapf(err, "error while mounting volume with options: %s", v.opts)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue