Honor ReadOnly flag from persistent-volume plugin
This commit is contained in:
@@ -39,6 +39,7 @@ type rbdPlugin struct {
|
||||
}
|
||||
|
||||
var _ volume.VolumePlugin = &rbdPlugin{}
|
||||
var _ volume.PersistentVolumePlugin = &rbdPlugin{}
|
||||
|
||||
const (
|
||||
rbdPluginName = "kubernetes.io/rbd"
|
||||
@@ -74,7 +75,7 @@ func (plugin *rbdPlugin) GetAccessModes() []api.PersistentVolumeAccessMode {
|
||||
|
||||
func (plugin *rbdPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.VolumeOptions, mounter mount.Interface) (volume.Builder, error) {
|
||||
secret := ""
|
||||
source := plugin.getRBDVolumeSource(spec)
|
||||
source, _ := plugin.getRBDVolumeSource(spec)
|
||||
|
||||
if source.SecretRef != nil {
|
||||
kubeClient := plugin.host.GetKubeClient()
|
||||
@@ -97,16 +98,18 @@ func (plugin *rbdPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, _ volume.Vo
|
||||
return plugin.newBuilderInternal(spec, pod.UID, &RBDUtil{}, mounter, secret)
|
||||
}
|
||||
|
||||
func (plugin *rbdPlugin) getRBDVolumeSource(spec *volume.Spec) *api.RBDVolumeSource {
|
||||
func (plugin *rbdPlugin) getRBDVolumeSource(spec *volume.Spec) (*api.RBDVolumeSource, bool) {
|
||||
// rbd volumes used directly in a pod have a ReadOnly flag set by the pod author.
|
||||
// rbd volumes used as a PersistentVolume gets the ReadOnly flag indirectly through the persistent-claim volume used to mount the PV
|
||||
if spec.VolumeSource.RBD != nil {
|
||||
return spec.VolumeSource.RBD
|
||||
return spec.VolumeSource.RBD, spec.VolumeSource.RBD.ReadOnly
|
||||
} else {
|
||||
return spec.PersistentVolumeSource.RBD
|
||||
return spec.PersistentVolumeSource.RBD, spec.ReadOnly
|
||||
}
|
||||
}
|
||||
|
||||
func (plugin *rbdPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UID, manager diskManager, mounter mount.Interface, secret string) (volume.Builder, error) {
|
||||
source := plugin.getRBDVolumeSource(spec)
|
||||
source, readOnly := plugin.getRBDVolumeSource(spec)
|
||||
pool := source.RBDPool
|
||||
if pool == "" {
|
||||
pool = "rbd"
|
||||
@@ -126,7 +129,7 @@ func (plugin *rbdPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UID,
|
||||
volName: spec.Name,
|
||||
Image: source.RBDImage,
|
||||
Pool: pool,
|
||||
ReadOnly: source.ReadOnly,
|
||||
ReadOnly: readOnly,
|
||||
manager: manager,
|
||||
mounter: mounter,
|
||||
plugin: plugin,
|
||||
|
Reference in New Issue
Block a user