add pointer mutation review
This commit is contained in:
parent
e05a8403c8
commit
f9befb90a4
@ -18,7 +18,7 @@ package nfs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
netutil "k8s.io/utils/net"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
@ -122,10 +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
|
||||||
}
|
}
|
||||||
// wrap ipv6 into `[ ]`
|
|
||||||
if net.ParseIP(source.Server).To16() != nil {
|
|
||||||
source.Server = fmt.Sprintf("[%s]", source.Server)
|
|
||||||
}
|
|
||||||
return &nfsMounter{
|
return &nfsMounter{
|
||||||
nfs: &nfs{
|
nfs: &nfs{
|
||||||
volName: spec.Name(),
|
volName: spec.Name(),
|
||||||
@ -134,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),
|
||||||
@ -326,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
|
||||||
|
}
|
||||||
|
@ -18,7 +18,6 @@ package nfs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -119,18 +118,6 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
|||||||
if mounter == nil {
|
if mounter == nil {
|
||||||
t.Errorf("Got a nil Mounter")
|
t.Errorf("Got a nil Mounter")
|
||||||
}
|
}
|
||||||
if nfsm, ok := mounter.(*nfsMounter); ok {
|
|
||||||
srvr := nfsm.server
|
|
||||||
vol, _, _ := getVolumeSource(spec)
|
|
||||||
expectedSrvr := vol.Server
|
|
||||||
// check cluster IP version
|
|
||||||
if net.ParseIP(expectedSrvr).To16() != nil {
|
|
||||||
expectedSrvr = fmt.Sprintf("[%s]", expectedSrvr)
|
|
||||||
}
|
|
||||||
if srvr != expectedSrvr {
|
|
||||||
t.Errorf("Unexpected nfs server, expected %q, got: %q", expectedSrvr, srvr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
volumePath := mounter.GetPath()
|
volumePath := mounter.GetPath()
|
||||||
expectedPath := fmt.Sprintf("%s/pods/poduid/volumes/kubernetes.io~nfs/vol1", tmpDir)
|
expectedPath := fmt.Sprintf("%s/pods/poduid/volumes/kubernetes.io~nfs/vol1", tmpDir)
|
||||||
if volumePath != expectedPath {
|
if volumePath != expectedPath {
|
||||||
@ -149,6 +136,23 @@ 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)
|
||||||
|
}
|
||||||
|
src, _, _ := getVolumeSource(spec)
|
||||||
|
srvr := getServerFromSource(src)
|
||||||
|
expectedDevice := fmt.Sprintf("%s:%s", srvr, src.Path)
|
||||||
|
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))
|
||||||
|
Loading…
Reference in New Issue
Block a user