Honor ReadOnly flag from persistent-volume plugin

This commit is contained in:
markturansky
2015-06-26 16:37:11 -04:00
parent 1367076d2e
commit 124bb22f92
8 changed files with 43 additions and 19 deletions

View File

@@ -40,6 +40,7 @@ type gcePersistentDiskPlugin struct {
}
var _ volume.VolumePlugin = &gcePersistentDiskPlugin{}
var _ volume.PersistentVolumePlugin = &gcePersistentDiskPlugin{}
const (
gcePersistentDiskPluginName = "kubernetes.io/gce-pd"
@@ -70,11 +71,17 @@ func (plugin *gcePersistentDiskPlugin) NewBuilder(spec *volume.Spec, pod *api.Po
}
func (plugin *gcePersistentDiskPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UID, manager pdManager, mounter mount.Interface) (volume.Builder, error) {
// GCEPDs used directly in a pod have a ReadOnly flag set by the pod author.
// GCEPDs used as a PersistentVolume gets the ReadOnly flag indirectly through the persistent-claim volume used to mount the PV
var readOnly bool
var gce *api.GCEPersistentDiskVolumeSource
if spec.VolumeSource.GCEPersistentDisk != nil {
gce = spec.VolumeSource.GCEPersistentDisk
readOnly = gce.ReadOnly
} else {
gce = spec.PersistentVolumeSource.GCEPersistentDisk
readOnly = spec.ReadOnly
}
pdName := gce.PDName
@@ -83,7 +90,6 @@ func (plugin *gcePersistentDiskPlugin) newBuilderInternal(spec *volume.Spec, pod
if gce.Partition != 0 {
partition = strconv.Itoa(gce.Partition)
}
readOnly := gce.ReadOnly
return &gcePersistentDiskBuilder{
gcePersistentDisk: &gcePersistentDisk{