Merge pull request #10424 from markturansky/readonly_fix

Auto commit by PR queue bot
This commit is contained in:
Brendan Burns
2015-07-29 14:25:44 -07:00
25 changed files with 495 additions and 36 deletions

View File

@@ -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: &hostPath{path: spec.VolumeSource.HostPath.Path},
readOnly: false,
}, nil
} else {
return &hostPathBuilder{&hostPath{spec.PersistentVolumeSource.HostPath.Path}}, nil
return &hostPathBuilder{
hostPath: &hostPath{path: spec.PersistentVolumeSource.HostPath.Path},
readOnly: spec.ReadOnly,
}, nil
}
}
@@ -104,6 +110,7 @@ func (hp *hostPath) GetPath() string {
type hostPathBuilder struct {
*hostPath
readOnly bool
}
var _ volume.Builder = &hostPathBuilder{}
@@ -118,6 +125,14 @@ func (b *hostPathBuilder) SetUpAt(dir string) error {
return fmt.Errorf("SetUpAt() does not make sense for host paths")
}
func (b *hostPathBuilder) IsReadOnly() bool {
return b.readOnly
}
func (b *hostPathBuilder) GetPath() string {
return b.path
}
type hostPathCleaner struct {
*hostPath
}

View File

@@ -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")
}
}