fix-nfs-storage-ipv6_add_square_brackets

This commit is contained in:
elbehery 2021-04-12 14:55:15 +02:00
parent e6b4fa3811
commit 5b52146614
2 changed files with 13 additions and 1 deletions

View File

@ -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(),

View File

@ -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{