зеркало из https://github.com/microsoft/docker.git
#26639: Local NFS volumes do not resolve hostnames
Signed-off-by: dattatrayakumbhar04 <dattatraya.kumbhar@gslab.com>
This commit is contained in:
Родитель
69efb4652c
Коммит
668fa8aff2
|
@ -10,6 +10,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
@ -349,3 +350,15 @@ func validateOpts(opts map[string]string) error {
|
|||
func (v *localVolume) Status() map[string]interface{} {
|
||||
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"
|
||||
)
|
||||
|
||||
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) {
|
||||
// TODO Windows: Investigate why this test fails on Windows under CI
|
||||
// but passes locally.
|
||||
|
|
|
@ -7,6 +7,7 @@ package local
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
|
@ -71,6 +72,16 @@ func (v *localVolume) mount() error {
|
|||
if v.opts.MountDevice == "" {
|
||||
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)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче