mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Added unit tests for each PV using IsReadOnly
This commit is contained in:
		@@ -196,13 +196,13 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
 | 
			
		||||
	plugMgr := volume.VolumePluginMgr{}
 | 
			
		||||
	plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
 | 
			
		||||
	plug, _ := plugMgr.FindPluginByName(awsElasticBlockStorePluginName)
 | 
			
		||||
	spec := volume.NewSpecFromPersistentVolume(pv, false)
 | 
			
		||||
 | 
			
		||||
	// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
 | 
			
		||||
	spec := volume.NewSpecFromPersistentVolume(pv, true)
 | 
			
		||||
	pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
 | 
			
		||||
	builder, _ := plug.NewBuilder(spec, pod, volume.VolumeOptions{}, nil)
 | 
			
		||||
 | 
			
		||||
	if builder.IsReadOnly() {
 | 
			
		||||
		t.Errorf("Expected false for builder.IsReadOnly")
 | 
			
		||||
	if !builder.IsReadOnly() {
 | 
			
		||||
		t.Errorf("Expected true for builder.IsReadOnly")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,8 @@ import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
 | 
			
		||||
@@ -171,3 +173,50 @@ func TestPlugin(t *testing.T) {
 | 
			
		||||
		t.Errorf("Detach watch not called")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
 | 
			
		||||
	pv := &api.PersistentVolume{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name: "pvA",
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PersistentVolumeSpec{
 | 
			
		||||
			PersistentVolumeSource: api.PersistentVolumeSource{
 | 
			
		||||
				GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{},
 | 
			
		||||
			},
 | 
			
		||||
			ClaimRef: &api.ObjectReference{
 | 
			
		||||
				Name: "claimA",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	claim := &api.PersistentVolumeClaim{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name:      "claimA",
 | 
			
		||||
			Namespace: "nsA",
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PersistentVolumeClaimSpec{
 | 
			
		||||
			VolumeName: "pvA",
 | 
			
		||||
		},
 | 
			
		||||
		Status: api.PersistentVolumeClaimStatus{
 | 
			
		||||
			Phase: api.ClaimBound,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	o := testclient.NewObjects(api.Scheme, api.Scheme)
 | 
			
		||||
	o.Add(pv)
 | 
			
		||||
	o.Add(claim)
 | 
			
		||||
	client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, latest.RESTMapper)}
 | 
			
		||||
 | 
			
		||||
	plugMgr := volume.VolumePluginMgr{}
 | 
			
		||||
	plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
 | 
			
		||||
	plug, _ := plugMgr.FindPluginByName(gcePersistentDiskPluginName)
 | 
			
		||||
 | 
			
		||||
	// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
 | 
			
		||||
	spec := volume.NewSpecFromPersistentVolume(pv, true)
 | 
			
		||||
	pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
 | 
			
		||||
	builder, _ := plug.NewBuilder(spec, pod, volume.VolumeOptions{}, nil)
 | 
			
		||||
 | 
			
		||||
	if !builder.IsReadOnly() {
 | 
			
		||||
		t.Errorf("Expected true for builder.IsReadOnly")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,8 @@ import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
			
		||||
@@ -153,5 +155,63 @@ func TestPluginPersistentVolume(t *testing.T) {
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol))
 | 
			
		||||
	doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol, false))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
 | 
			
		||||
	pv := &api.PersistentVolume{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name: "pvA",
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PersistentVolumeSpec{
 | 
			
		||||
			PersistentVolumeSource: api.PersistentVolumeSource{
 | 
			
		||||
				Glusterfs: &api.GlusterfsVolumeSource{"ep", "vol", false},
 | 
			
		||||
			},
 | 
			
		||||
			ClaimRef: &api.ObjectReference{
 | 
			
		||||
				Name: "claimA",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	claim := &api.PersistentVolumeClaim{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name:      "claimA",
 | 
			
		||||
			Namespace: "nsA",
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PersistentVolumeClaimSpec{
 | 
			
		||||
			VolumeName: "pvA",
 | 
			
		||||
		},
 | 
			
		||||
		Status: api.PersistentVolumeClaimStatus{
 | 
			
		||||
			Phase: api.ClaimBound,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ep := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name: "ep",
 | 
			
		||||
		},
 | 
			
		||||
		Subsets: []api.EndpointSubset{{
 | 
			
		||||
			Addresses: []api.EndpointAddress{{IP: "127.0.0.1"}},
 | 
			
		||||
			Ports:     []api.EndpointPort{{"foo", 80, api.ProtocolTCP}},
 | 
			
		||||
		}},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	o := testclient.NewObjects(api.Scheme, api.Scheme)
 | 
			
		||||
	o.Add(pv)
 | 
			
		||||
	o.Add(claim)
 | 
			
		||||
	o.Add(ep)
 | 
			
		||||
	client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, latest.RESTMapper)}
 | 
			
		||||
 | 
			
		||||
	plugMgr := volume.VolumePluginMgr{}
 | 
			
		||||
	plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
 | 
			
		||||
	plug, _ := plugMgr.FindPluginByName(glusterfsPluginName)
 | 
			
		||||
 | 
			
		||||
	// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
 | 
			
		||||
	spec := volume.NewSpecFromPersistentVolume(pv, true)
 | 
			
		||||
	pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
 | 
			
		||||
	builder, _ := plug.NewBuilder(spec, pod, volume.VolumeOptions{}, nil)
 | 
			
		||||
 | 
			
		||||
	if !builder.IsReadOnly() {
 | 
			
		||||
		t.Errorf("Expected true for builder.IsReadOnly")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -71,9 +71,15 @@ func (plugin *hostPathPlugin) GetAccessModes() []api.PersistentVolumeAccessMode
 | 
			
		||||
 | 
			
		||||
func (plugin *hostPathPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.VolumeOptions, _ mount.Interface) (volume.Builder, error) {
 | 
			
		||||
	if spec.VolumeSource.HostPath != nil {
 | 
			
		||||
		return &hostPathBuilder{&hostPath{spec.VolumeSource.HostPath.Path}}, nil
 | 
			
		||||
		return &hostPathBuilder{
 | 
			
		||||
			hostPath:     spec.VolumeSource.HostPath,
 | 
			
		||||
			readOnly: false,
 | 
			
		||||
		}, nil
 | 
			
		||||
	} else {
 | 
			
		||||
		return &hostPathBuilder{&hostPath{spec.PersistentVolumeSource.HostPath.Path}}, nil
 | 
			
		||||
		return &hostPathBuilder{
 | 
			
		||||
			hostPath:     spec.PersistentVolumeSource.HostPath,
 | 
			
		||||
			readOnly: spec.ReadOnly,
 | 
			
		||||
		}, nil
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -105,6 +111,7 @@ func (hp *hostPath) GetPath() string {
 | 
			
		||||
 | 
			
		||||
type hostPathBuilder struct {
 | 
			
		||||
	*hostPath
 | 
			
		||||
	readOnly bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var _ volume.Builder = &hostPathBuilder{}
 | 
			
		||||
@@ -120,7 +127,7 @@ func (b *hostPathBuilder) SetUpAt(dir string) error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (b *hostPathBuilder) IsReadOnly() bool {
 | 
			
		||||
	return false
 | 
			
		||||
	return b.readOnly
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (b *hostPathBuilder) GetPath() string {
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,8 @@ import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
 | 
			
		||||
)
 | 
			
		||||
@@ -142,3 +144,50 @@ func TestPlugin(t *testing.T) {
 | 
			
		||||
		t.Errorf("Expected success, got: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
 | 
			
		||||
	pv := &api.PersistentVolume{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name: "pvA",
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PersistentVolumeSpec{
 | 
			
		||||
			PersistentVolumeSource: api.PersistentVolumeSource{
 | 
			
		||||
				HostPath: &api.HostPathVolumeSource{"foo"},
 | 
			
		||||
			},
 | 
			
		||||
			ClaimRef: &api.ObjectReference{
 | 
			
		||||
				Name: "claimA",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	claim := &api.PersistentVolumeClaim{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name:      "claimA",
 | 
			
		||||
			Namespace: "nsA",
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PersistentVolumeClaimSpec{
 | 
			
		||||
			VolumeName: "pvA",
 | 
			
		||||
		},
 | 
			
		||||
		Status: api.PersistentVolumeClaimStatus{
 | 
			
		||||
			Phase: api.ClaimBound,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	o := testclient.NewObjects(api.Scheme, api.Scheme)
 | 
			
		||||
	o.Add(pv)
 | 
			
		||||
	o.Add(claim)
 | 
			
		||||
	client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, latest.RESTMapper)}
 | 
			
		||||
 | 
			
		||||
	plugMgr := volume.VolumePluginMgr{}
 | 
			
		||||
	plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
 | 
			
		||||
	plug, _ := plugMgr.FindPluginByName(hostPathPluginName)
 | 
			
		||||
 | 
			
		||||
	// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
 | 
			
		||||
	spec := volume.NewSpecFromPersistentVolume(pv, true)
 | 
			
		||||
	pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
 | 
			
		||||
	builder, _ := plug.NewBuilder(spec, pod, volume.VolumeOptions{}, nil)
 | 
			
		||||
 | 
			
		||||
	if !builder.IsReadOnly() {
 | 
			
		||||
		t.Errorf("Expected true for builder.IsReadOnly")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,8 @@ import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
 | 
			
		||||
@@ -193,5 +195,57 @@ func TestPluginPersistentVolume(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol))
 | 
			
		||||
	doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol, false))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
 | 
			
		||||
	pv := &api.PersistentVolume{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name: "pvA",
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PersistentVolumeSpec{
 | 
			
		||||
			PersistentVolumeSource: api.PersistentVolumeSource{
 | 
			
		||||
				ISCSI: &api.ISCSIVolumeSource{
 | 
			
		||||
					TargetPortal: "127.0.0.1:3260",
 | 
			
		||||
					IQN:          "iqn.2014-12.server:storage.target01",
 | 
			
		||||
					FSType:       "ext4",
 | 
			
		||||
					Lun:          0,
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			ClaimRef: &api.ObjectReference{
 | 
			
		||||
				Name: "claimA",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	claim := &api.PersistentVolumeClaim{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name:      "claimA",
 | 
			
		||||
			Namespace: "nsA",
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PersistentVolumeClaimSpec{
 | 
			
		||||
			VolumeName: "pvA",
 | 
			
		||||
		},
 | 
			
		||||
		Status: api.PersistentVolumeClaimStatus{
 | 
			
		||||
			Phase: api.ClaimBound,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	o := testclient.NewObjects(api.Scheme, api.Scheme)
 | 
			
		||||
	o.Add(pv)
 | 
			
		||||
	o.Add(claim)
 | 
			
		||||
	client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, latest.RESTMapper)}
 | 
			
		||||
 | 
			
		||||
	plugMgr := volume.VolumePluginMgr{}
 | 
			
		||||
	plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
 | 
			
		||||
	plug, _ := plugMgr.FindPluginByName(iscsiPluginName)
 | 
			
		||||
 | 
			
		||||
	// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
 | 
			
		||||
	spec := volume.NewSpecFromPersistentVolume(pv, true)
 | 
			
		||||
	pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
 | 
			
		||||
	builder, _ := plug.NewBuilder(spec, pod, volume.VolumeOptions{}, nil)
 | 
			
		||||
 | 
			
		||||
	if !builder.IsReadOnly() {
 | 
			
		||||
		t.Errorf("Expected true for builder.IsReadOnly")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -76,11 +76,13 @@ func (plugin *nfsPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.Vo
 | 
			
		||||
 | 
			
		||||
func (plugin *nfsPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod, mounter mount.Interface) (volume.Builder, error) {
 | 
			
		||||
	var source *api.NFSVolumeSource
 | 
			
		||||
 | 
			
		||||
	var readOnly bool
 | 
			
		||||
	if spec.VolumeSource.NFS != nil {
 | 
			
		||||
		source = spec.VolumeSource.NFS
 | 
			
		||||
		readOnly = spec.VolumeSource.NFS.ReadOnly
 | 
			
		||||
	} else {
 | 
			
		||||
		source = spec.PersistentVolumeSource.NFS
 | 
			
		||||
		readOnly = spec.ReadOnly
 | 
			
		||||
	}
 | 
			
		||||
	return &nfsBuilder{
 | 
			
		||||
		nfs: &nfs{
 | 
			
		||||
@@ -91,7 +93,8 @@ func (plugin *nfsPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod, mou
 | 
			
		||||
		},
 | 
			
		||||
		server:     source.Server,
 | 
			
		||||
		exportPath: source.Path,
 | 
			
		||||
		readOnly:   source.ReadOnly}, nil
 | 
			
		||||
		readOnly:   readOnly,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (plugin *nfsPlugin) NewCleaner(volName string, podUID types.UID, mounter mount.Interface) (volume.Cleaner, error) {
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,8 @@ import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
 | 
			
		||||
@@ -199,5 +201,52 @@ func TestPluginPersistentVolume(t *testing.T) {
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol))
 | 
			
		||||
	doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol, false))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
 | 
			
		||||
	pv := &api.PersistentVolume{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name: "pvA",
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PersistentVolumeSpec{
 | 
			
		||||
			PersistentVolumeSource: api.PersistentVolumeSource{
 | 
			
		||||
				NFS: &api.NFSVolumeSource{},
 | 
			
		||||
			},
 | 
			
		||||
			ClaimRef: &api.ObjectReference{
 | 
			
		||||
				Name: "claimA",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	claim := &api.PersistentVolumeClaim{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name:      "claimA",
 | 
			
		||||
			Namespace: "nsA",
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PersistentVolumeClaimSpec{
 | 
			
		||||
			VolumeName: "pvA",
 | 
			
		||||
		},
 | 
			
		||||
		Status: api.PersistentVolumeClaimStatus{
 | 
			
		||||
			Phase: api.ClaimBound,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	o := testclient.NewObjects(api.Scheme, api.Scheme)
 | 
			
		||||
	o.Add(pv)
 | 
			
		||||
	o.Add(claim)
 | 
			
		||||
	client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, latest.RESTMapper)}
 | 
			
		||||
 | 
			
		||||
	plugMgr := volume.VolumePluginMgr{}
 | 
			
		||||
	plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
 | 
			
		||||
	plug, _ := plugMgr.FindPluginByName(nfsPluginName)
 | 
			
		||||
 | 
			
		||||
	// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
 | 
			
		||||
	spec := volume.NewSpecFromPersistentVolume(pv, true)
 | 
			
		||||
	pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
 | 
			
		||||
	builder, _ := plug.NewBuilder(spec, pod, volume.VolumeOptions{}, nil)
 | 
			
		||||
 | 
			
		||||
	if !builder.IsReadOnly() {
 | 
			
		||||
		t.Errorf("Expected true for builder.IsReadOnly")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -53,7 +53,6 @@ func (plugin *persistentClaimPlugin) CanSupport(spec *volume.Spec) bool {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (plugin *persistentClaimPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, opts volume.VolumeOptions, mounter mount.Interface) (volume.Builder, error) {
 | 
			
		||||
	plugin.readOnly = spec.ReadOnly
 | 
			
		||||
	claim, err := plugin.host.GetKubeClient().PersistentVolumeClaims(pod.Namespace).Get(spec.VolumeSource.PersistentVolumeClaim.ClaimName)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		glog.Errorf("Error finding claim: %+v\n", spec.VolumeSource.PersistentVolumeClaim.ClaimName)
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,8 @@ import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
			
		||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
 | 
			
		||||
@@ -151,5 +153,56 @@ func TestPluginPersistentVolume(t *testing.T) {
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol))
 | 
			
		||||
	doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol, false))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
 | 
			
		||||
	pv := &api.PersistentVolume{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name: "pvA",
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PersistentVolumeSpec{
 | 
			
		||||
			PersistentVolumeSource: api.PersistentVolumeSource{
 | 
			
		||||
				RBD: &api.RBDVolumeSource{
 | 
			
		||||
					CephMonitors: []string{"a", "b"},
 | 
			
		||||
					RBDImage:     "bar",
 | 
			
		||||
					FSType:       "ext4",
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			ClaimRef: &api.ObjectReference{
 | 
			
		||||
				Name: "claimA",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	claim := &api.PersistentVolumeClaim{
 | 
			
		||||
		ObjectMeta: api.ObjectMeta{
 | 
			
		||||
			Name:      "claimA",
 | 
			
		||||
			Namespace: "nsA",
 | 
			
		||||
		},
 | 
			
		||||
		Spec: api.PersistentVolumeClaimSpec{
 | 
			
		||||
			VolumeName: "pvA",
 | 
			
		||||
		},
 | 
			
		||||
		Status: api.PersistentVolumeClaimStatus{
 | 
			
		||||
			Phase: api.ClaimBound,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	o := testclient.NewObjects(api.Scheme, api.Scheme)
 | 
			
		||||
	o.Add(pv)
 | 
			
		||||
	o.Add(claim)
 | 
			
		||||
	client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, latest.RESTMapper)}
 | 
			
		||||
 | 
			
		||||
	plugMgr := volume.VolumePluginMgr{}
 | 
			
		||||
	plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
 | 
			
		||||
	plug, _ := plugMgr.FindPluginByName(rbdPluginName)
 | 
			
		||||
 | 
			
		||||
	// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
 | 
			
		||||
	spec := volume.NewSpecFromPersistentVolume(pv, true)
 | 
			
		||||
	pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
 | 
			
		||||
	builder, _ := plug.NewBuilder(spec, pod, volume.VolumeOptions{}, nil)
 | 
			
		||||
 | 
			
		||||
	if !builder.IsReadOnly() {
 | 
			
		||||
		t.Errorf("Expected true for builder.IsReadOnly")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user