From 4a3bdbecf96566308aea99faf177b26c1461398a Mon Sep 17 00:00:00 2001 From: mlmhl Date: Sun, 11 Mar 2018 10:35:37 +0800 Subject: [PATCH] set readOnly for CSI mounter --- pkg/volume/csi/csi_plugin.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/volume/csi/csi_plugin.go b/pkg/volume/csi/csi_plugin.go index 14dd8a9b369..d63296877d0 100644 --- a/pkg/volume/csi/csi_plugin.go +++ b/pkg/volume/csi/csi_plugin.go @@ -98,6 +98,10 @@ func (p *csiPlugin) NewMounter( if err != nil { return nil, err } + readOnly, err := getReadOnlyFromSpec(spec) + if err != nil { + return nil, err + } // before it is used in any paths such as socket etc addr := fmt.Sprintf(csiAddrTemplate, pvSource.Driver) @@ -120,6 +124,7 @@ func (p *csiPlugin) NewMounter( volumeID: pvSource.VolumeHandle, specVolumeID: spec.Name(), csiClient: client, + readOnly: readOnly, } return mounter, nil } @@ -217,6 +222,15 @@ func getCSISourceFromSpec(spec *volume.Spec) (*api.CSIPersistentVolumeSource, er return nil, fmt.Errorf("CSIPersistentVolumeSource not defined in spec") } +func getReadOnlyFromSpec(spec *volume.Spec) (bool, error) { + if spec.PersistentVolume != nil && + spec.PersistentVolume.Spec.CSI != nil { + return spec.ReadOnly, nil + } + + return false, fmt.Errorf("CSIPersistentVolumeSource not defined in spec") +} + // log prepends log string with `kubernetes.io/csi` func log(msg string, parts ...interface{}) string { return fmt.Sprintf(fmt.Sprintf("%s: %s", csiPluginName, msg), parts...)