mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #101067 from Elbehery/fix-nfs-storage-ipv6_add_square_brackets
Fix mounting NFS resources in IPv6 bare-metal environment #101066
This commit is contained in:
commit
dfc91819b7
@ -18,6 +18,7 @@ package nfs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
netutil "k8s.io/utils/net"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
@ -121,7 +122,6 @@ func (plugin *nfsPlugin) newMounterInternal(spec *volume.Spec, pod *v1.Pod, moun
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &nfsMounter{
|
return &nfsMounter{
|
||||||
nfs: &nfs{
|
nfs: &nfs{
|
||||||
volName: spec.Name(),
|
volName: spec.Name(),
|
||||||
@ -130,7 +130,7 @@ func (plugin *nfsPlugin) newMounterInternal(spec *volume.Spec, pod *v1.Pod, moun
|
|||||||
plugin: plugin,
|
plugin: plugin,
|
||||||
MetricsProvider: volume.NewMetricsStatFS(getPath(pod.UID, spec.Name(), plugin.host)),
|
MetricsProvider: volume.NewMetricsStatFS(getPath(pod.UID, spec.Name(), plugin.host)),
|
||||||
},
|
},
|
||||||
server: source.Server,
|
server: getServerFromSource(source),
|
||||||
exportPath: source.Path,
|
exportPath: source.Path,
|
||||||
readOnly: readOnly,
|
readOnly: readOnly,
|
||||||
mountOptions: util.MountOptionFromSpec(spec),
|
mountOptions: util.MountOptionFromSpec(spec),
|
||||||
@ -322,3 +322,10 @@ func getVolumeSource(spec *volume.Spec) (*v1.NFSVolumeSource, bool, error) {
|
|||||||
|
|
||||||
return nil, false, fmt.Errorf("Spec does not reference a NFS volume type")
|
return nil, false, fmt.Errorf("Spec does not reference a NFS volume type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getServerFromSource(source *v1.NFSVolumeSource) string {
|
||||||
|
if netutil.IsIPv6String(source.Server) {
|
||||||
|
return fmt.Sprintf("[%s]", source.Server)
|
||||||
|
}
|
||||||
|
return source.Server
|
||||||
|
}
|
||||||
|
@ -96,7 +96,7 @@ func TestRecycler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
func doTestPlugin(t *testing.T, spec *volume.Spec, expectedDevice string) {
|
||||||
tmpDir, err := utiltesting.MkTmpdir("nfs_test")
|
tmpDir, err := utiltesting.MkTmpdir("nfs_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating temp dir: %v", err)
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
@ -136,6 +136,20 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
|||||||
if mounter.(*nfsMounter).readOnly {
|
if mounter.(*nfsMounter).readOnly {
|
||||||
t.Errorf("The volume source should not be read-only and it is.")
|
t.Errorf("The volume source should not be read-only and it is.")
|
||||||
}
|
}
|
||||||
|
mntDevs, err := fake.List()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("fakeMounter.List() failed: %v", err)
|
||||||
|
}
|
||||||
|
if len(mntDevs) != 1 {
|
||||||
|
t.Errorf("unexpected number of mounted devices. expected: %v, got %v", 1, len(mntDevs))
|
||||||
|
} else {
|
||||||
|
if mntDevs[0].Type != "nfs" {
|
||||||
|
t.Errorf("unexpected type of mounted devices. expected: %v, got %v", "nfs", mntDevs[0].Type)
|
||||||
|
}
|
||||||
|
if mntDevs[0].Device != expectedDevice {
|
||||||
|
t.Errorf("unexpected nfs device, expected %q, got: %q", expectedDevice, mntDevs[0].Device)
|
||||||
|
}
|
||||||
|
}
|
||||||
log := fake.GetLog()
|
log := fake.GetLog()
|
||||||
if len(log) != 1 {
|
if len(log) != 1 {
|
||||||
t.Errorf("Mount was not called exactly one time. It was called %d times.", len(log))
|
t.Errorf("Mount was not called exactly one time. It was called %d times.", len(log))
|
||||||
@ -178,7 +192,23 @@ func TestPluginVolume(t *testing.T) {
|
|||||||
Name: "vol1",
|
Name: "vol1",
|
||||||
VolumeSource: v1.VolumeSource{NFS: &v1.NFSVolumeSource{Server: "localhost", Path: "/somepath", ReadOnly: false}},
|
VolumeSource: v1.VolumeSource{NFS: &v1.NFSVolumeSource{Server: "localhost", Path: "/somepath", ReadOnly: false}},
|
||||||
}
|
}
|
||||||
doTestPlugin(t, volume.NewSpecFromVolume(vol))
|
doTestPlugin(t, volume.NewSpecFromVolume(vol), "localhost:/somepath")
|
||||||
|
}
|
||||||
|
|
||||||
|
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), "[0:0:0:0:0:0:0:1]:/somepath")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIPV4VolumeSource(t *testing.T) {
|
||||||
|
vol := &v1.Volume{
|
||||||
|
Name: "vol1",
|
||||||
|
VolumeSource: v1.VolumeSource{NFS: &v1.NFSVolumeSource{Server: "127.0.0.1", Path: "/somepath", ReadOnly: false}},
|
||||||
|
}
|
||||||
|
doTestPlugin(t, volume.NewSpecFromVolume(vol), "127.0.0.1:/somepath")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPluginPersistentVolume(t *testing.T) {
|
func TestPluginPersistentVolume(t *testing.T) {
|
||||||
@ -193,7 +223,7 @@ func TestPluginPersistentVolume(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol, false))
|
doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol, false), "localhost:/somepath")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user