mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +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 := volume.VolumePluginMgr{}
 | 
				
			||||||
	plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
 | 
						plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
 | 
				
			||||||
	plug, _ := plugMgr.FindPluginByName(awsElasticBlockStorePluginName)
 | 
						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")}}
 | 
						pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: types.UID("poduid")}}
 | 
				
			||||||
	builder, _ := plug.NewBuilder(spec, pod, volume.VolumeOptions{}, nil)
 | 
						builder, _ := plug.NewBuilder(spec, pod, volume.VolumeOptions{}, nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if builder.IsReadOnly() {
 | 
						if !builder.IsReadOnly() {
 | 
				
			||||||
		t.Errorf("Expected false for builder.IsReadOnly")
 | 
							t.Errorf("Expected true for builder.IsReadOnly")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,8 @@ import (
 | 
				
			|||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
						"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/types"
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
						"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
 | 
						"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
 | 
				
			||||||
@@ -171,3 +173,50 @@ func TestPlugin(t *testing.T) {
 | 
				
			|||||||
		t.Errorf("Detach watch not called")
 | 
							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"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
						"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/types"
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
 | 
						"github.com/GoogleCloudPlatform/kubernetes/pkg/util/exec"
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
						"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) {
 | 
					func (plugin *hostPathPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.VolumeOptions, _ mount.Interface) (volume.Builder, error) {
 | 
				
			||||||
	if spec.VolumeSource.HostPath != nil {
 | 
						if spec.VolumeSource.HostPath != nil {
 | 
				
			||||||
		return &hostPathBuilder{&hostPath{spec.VolumeSource.HostPath.Path}}, nil
 | 
							return &hostPathBuilder{
 | 
				
			||||||
 | 
								hostPath:     spec.VolumeSource.HostPath,
 | 
				
			||||||
 | 
								readOnly: false,
 | 
				
			||||||
 | 
							}, nil
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return &hostPathBuilder{&hostPath{spec.PersistentVolumeSource.HostPath.Path}}, nil
 | 
							return &hostPathBuilder{
 | 
				
			||||||
 | 
								hostPath:     spec.PersistentVolumeSource.HostPath,
 | 
				
			||||||
 | 
								readOnly: spec.ReadOnly,
 | 
				
			||||||
 | 
							}, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -96,7 +102,7 @@ func newRecycler(spec *volume.Spec, host volume.VolumeHost) (volume.Recycler, er
 | 
				
			|||||||
// HostPath volumes represent a bare host file or directory mount.
 | 
					// HostPath volumes represent a bare host file or directory mount.
 | 
				
			||||||
// The direct at the specified path will be directly exposed to the container.
 | 
					// The direct at the specified path will be directly exposed to the container.
 | 
				
			||||||
type hostPath struct {
 | 
					type hostPath struct {
 | 
				
			||||||
	path string
 | 
						path     string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (hp *hostPath) GetPath() string {
 | 
					func (hp *hostPath) GetPath() string {
 | 
				
			||||||
@@ -105,6 +111,7 @@ func (hp *hostPath) GetPath() string {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type hostPathBuilder struct {
 | 
					type hostPathBuilder struct {
 | 
				
			||||||
	*hostPath
 | 
						*hostPath
 | 
				
			||||||
 | 
						readOnly bool
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var _ volume.Builder = &hostPathBuilder{}
 | 
					var _ volume.Builder = &hostPathBuilder{}
 | 
				
			||||||
@@ -120,7 +127,7 @@ func (b *hostPathBuilder) SetUpAt(dir string) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (b *hostPathBuilder) IsReadOnly() bool {
 | 
					func (b *hostPathBuilder) IsReadOnly() bool {
 | 
				
			||||||
	return false
 | 
						return b.readOnly
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (b *hostPathBuilder) GetPath() string {
 | 
					func (b *hostPathBuilder) GetPath() string {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,6 +20,8 @@ import (
 | 
				
			|||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
						"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/types"
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
 | 
						"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -142,3 +144,50 @@ func TestPlugin(t *testing.T) {
 | 
				
			|||||||
		t.Errorf("Expected success, got: %v", err)
 | 
							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"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
						"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/types"
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
						"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
 | 
						"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) {
 | 
					func (plugin *nfsPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod, mounter mount.Interface) (volume.Builder, error) {
 | 
				
			||||||
	var source *api.NFSVolumeSource
 | 
						var source *api.NFSVolumeSource
 | 
				
			||||||
 | 
						var readOnly bool
 | 
				
			||||||
	if spec.VolumeSource.NFS != nil {
 | 
						if spec.VolumeSource.NFS != nil {
 | 
				
			||||||
		source = spec.VolumeSource.NFS
 | 
							source = spec.VolumeSource.NFS
 | 
				
			||||||
 | 
							readOnly = spec.VolumeSource.NFS.ReadOnly
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		source = spec.PersistentVolumeSource.NFS
 | 
							source = spec.PersistentVolumeSource.NFS
 | 
				
			||||||
 | 
							readOnly = spec.ReadOnly
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return &nfsBuilder{
 | 
						return &nfsBuilder{
 | 
				
			||||||
		nfs: &nfs{
 | 
							nfs: &nfs{
 | 
				
			||||||
@@ -91,7 +93,8 @@ func (plugin *nfsPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod, mou
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		server:     source.Server,
 | 
							server:     source.Server,
 | 
				
			||||||
		exportPath: source.Path,
 | 
							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) {
 | 
					func (plugin *nfsPlugin) NewCleaner(volName string, podUID types.UID, mounter mount.Interface) (volume.Cleaner, error) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,8 @@ import (
 | 
				
			|||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
						"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/types"
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
						"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
 | 
						"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) {
 | 
					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)
 | 
						claim, err := plugin.host.GetKubeClient().PersistentVolumeClaims(pod.Namespace).Get(spec.VolumeSource.PersistentVolumeClaim.ClaimName)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		glog.Errorf("Error finding claim: %+v\n", spec.VolumeSource.PersistentVolumeClaim.ClaimName)
 | 
							glog.Errorf("Error finding claim: %+v\n", spec.VolumeSource.PersistentVolumeClaim.ClaimName)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,8 @@ import (
 | 
				
			|||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
 | 
						"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/types"
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
						"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
 | 
				
			||||||
	"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
 | 
						"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