mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	Merge pull request #16752 from markturansky/remove_nfs_cansupport_binary_check
Auto commit by PR queue bot
This commit is contained in:
		@@ -19,12 +19,10 @@ package nfs
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"runtime"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api"
 | 
						"k8s.io/kubernetes/pkg/api"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/types"
 | 
						"k8s.io/kubernetes/pkg/types"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/util"
 | 
						"k8s.io/kubernetes/pkg/util"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/util/exec"
 | 
					 | 
				
			||||||
	"k8s.io/kubernetes/pkg/util/mount"
 | 
						"k8s.io/kubernetes/pkg/util/mount"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/volume"
 | 
						"k8s.io/kubernetes/pkg/volume"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -68,29 +66,9 @@ func (plugin *nfsPlugin) Name() string {
 | 
				
			|||||||
	return nfsPluginName
 | 
						return nfsPluginName
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func hasNFSMount() bool {
 | 
					 | 
				
			||||||
	exe := exec.New()
 | 
					 | 
				
			||||||
	switch runtime.GOOS {
 | 
					 | 
				
			||||||
	case "linux":
 | 
					 | 
				
			||||||
		cmd1 := exe.Command("/bin/ls", "/sbin/mount.nfs")
 | 
					 | 
				
			||||||
		_, err1 := cmd1.CombinedOutput()
 | 
					 | 
				
			||||||
		cmd2 := exe.Command("/bin/ls", "/sbin/mount.nfs4")
 | 
					 | 
				
			||||||
		_, err2 := cmd2.CombinedOutput()
 | 
					 | 
				
			||||||
		return (err1 == nil || err2 == nil)
 | 
					 | 
				
			||||||
	case "darwin":
 | 
					 | 
				
			||||||
		cmd := exe.Command("/bin/ls", "/sbin/mount_nfs")
 | 
					 | 
				
			||||||
		_, err := cmd.CombinedOutput()
 | 
					 | 
				
			||||||
		return err == nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return false
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (plugin *nfsPlugin) CanSupport(spec *volume.Spec) bool {
 | 
					func (plugin *nfsPlugin) CanSupport(spec *volume.Spec) bool {
 | 
				
			||||||
	if (spec.Volume != nil && spec.Volume.NFS == nil) || (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.NFS == nil) {
 | 
						return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.NFS != nil) ||
 | 
				
			||||||
		return false
 | 
							(spec.Volume != nil && spec.Volume.NFS != nil)
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// see if /sbin/mount.nfs* is there
 | 
					 | 
				
			||||||
	return hasNFSMount()
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (plugin *nfsPlugin) GetAccessModes() []api.PersistentVolumeAccessMode {
 | 
					func (plugin *nfsPlugin) GetAccessModes() []api.PersistentVolumeAccessMode {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,16 +38,12 @@ func TestCanSupport(t *testing.T) {
 | 
				
			|||||||
	if plug.Name() != "kubernetes.io/nfs" {
 | 
						if plug.Name() != "kubernetes.io/nfs" {
 | 
				
			||||||
		t.Errorf("Wrong name: %s", plug.Name())
 | 
							t.Errorf("Wrong name: %s", plug.Name())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	foundMount := hasNFSMount()
 | 
						if !plug.CanSupport(&volume.Spec{Volume: &api.Volume{VolumeSource: api.VolumeSource{NFS: &api.NFSVolumeSource{}}}}) {
 | 
				
			||||||
	if plug.CanSupport(&volume.Spec{Volume: &api.Volume{VolumeSource: api.VolumeSource{NFS: &api.NFSVolumeSource{}}}}) != foundMount {
 | 
					 | 
				
			||||||
		t.Errorf("Expected true")
 | 
							t.Errorf("Expected true")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if plug.CanSupport(&volume.Spec{PersistentVolume: &api.PersistentVolume{Spec: api.PersistentVolumeSpec{PersistentVolumeSource: api.PersistentVolumeSource{NFS: &api.NFSVolumeSource{}}}}}) != foundMount {
 | 
						if !plug.CanSupport(&volume.Spec{PersistentVolume: &api.PersistentVolume{Spec: api.PersistentVolumeSpec{PersistentVolumeSource: api.PersistentVolumeSource{NFS: &api.NFSVolumeSource{}}}}}) {
 | 
				
			||||||
		t.Errorf("Expected true")
 | 
							t.Errorf("Expected true")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if plug.CanSupport(&volume.Spec{PersistentVolume: &api.PersistentVolume{Spec: api.PersistentVolumeSpec{PersistentVolumeSource: api.PersistentVolumeSource{}}}}) {
 | 
					 | 
				
			||||||
		t.Errorf("Expected false")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if plug.CanSupport(&volume.Spec{Volume: &api.Volume{VolumeSource: api.VolumeSource{}}}) {
 | 
						if plug.CanSupport(&volume.Spec{Volume: &api.Volume{VolumeSource: api.VolumeSource{}}}) {
 | 
				
			||||||
		t.Errorf("Expected false")
 | 
							t.Errorf("Expected false")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -67,10 +63,6 @@ func TestGetAccessModes(t *testing.T) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestRecycler(t *testing.T) {
 | 
					func TestRecycler(t *testing.T) {
 | 
				
			||||||
	if foundMount := hasNFSMount(); !foundMount {
 | 
					 | 
				
			||||||
		// FindRecyclablePluginBySpec will test CanSupport() but mount helper is absent
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	plugMgr := volume.VolumePluginMgr{}
 | 
						plugMgr := volume.VolumePluginMgr{}
 | 
				
			||||||
	plugMgr.InitPlugins([]volume.VolumePlugin{&nfsPlugin{nil, newMockRecycler, volume.VolumeConfig{}}}, volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
 | 
						plugMgr.InitPlugins([]volume.VolumePlugin{&nfsPlugin{nil, newMockRecycler, volume.VolumeConfig{}}}, volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user