diff --git a/pkg/volume/nfs/nfs.go b/pkg/volume/nfs/nfs.go index db906a7b799..cb64855a68b 100644 --- a/pkg/volume/nfs/nfs.go +++ b/pkg/volume/nfs/nfs.go @@ -18,6 +18,7 @@ package nfs import ( "fmt" + "net" "os" "runtime" "time" @@ -121,7 +122,10 @@ func (plugin *nfsPlugin) newMounterInternal(spec *volume.Spec, pod *v1.Pod, moun if err != nil { return nil, err } - + // wrap ipv6 into `[ ]` + if net.ParseIP(source.Server).To16() != nil { + source.Server = fmt.Sprintf("[%s]", source.Server) + } return &nfsMounter{ nfs: &nfs{ volName: spec.Name(), diff --git a/pkg/volume/nfs/nfs_test.go b/pkg/volume/nfs/nfs_test.go index a53855ca9e6..a6fcd166277 100644 --- a/pkg/volume/nfs/nfs_test.go +++ b/pkg/volume/nfs/nfs_test.go @@ -181,6 +181,14 @@ func TestPluginVolume(t *testing.T) { doTestPlugin(t, volume.NewSpecFromVolume(vol)) } +func TestIPV6VolumeSource(t *testing.T) { + vol := &v1.Volume{ + Name: "vol1", + VolumeSource: v1.VolumeSource{NFS: &v1.NFSVolumeSource{Server: "0:0:0:0:0:0:0:1", Path: "/somepath", ReadOnly: false}}, + } + doTestPlugin(t, volume.NewSpecFromVolume(vol)) +} + func TestPluginPersistentVolume(t *testing.T) { vol := &v1.PersistentVolume{ ObjectMeta: metav1.ObjectMeta{