Commit 4a3bdbec authored by mlmhl's avatar mlmhl

set readOnly for CSI mounter

parent f7d9fb47
...@@ -98,6 +98,10 @@ func (p *csiPlugin) NewMounter( ...@@ -98,6 +98,10 @@ func (p *csiPlugin) NewMounter(
if err != nil { if err != nil {
return nil, err return nil, err
} }
readOnly, err := getReadOnlyFromSpec(spec)
if err != nil {
return nil, err
}
// before it is used in any paths such as socket etc // before it is used in any paths such as socket etc
addr := fmt.Sprintf(csiAddrTemplate, pvSource.Driver) addr := fmt.Sprintf(csiAddrTemplate, pvSource.Driver)
...@@ -120,6 +124,7 @@ func (p *csiPlugin) NewMounter( ...@@ -120,6 +124,7 @@ func (p *csiPlugin) NewMounter(
volumeID: pvSource.VolumeHandle, volumeID: pvSource.VolumeHandle,
specVolumeID: spec.Name(), specVolumeID: spec.Name(),
csiClient: client, csiClient: client,
readOnly: readOnly,
} }
return mounter, nil return mounter, nil
} }
...@@ -217,6 +222,15 @@ func getCSISourceFromSpec(spec *volume.Spec) (*api.CSIPersistentVolumeSource, er ...@@ -217,6 +222,15 @@ func getCSISourceFromSpec(spec *volume.Spec) (*api.CSIPersistentVolumeSource, er
return nil, fmt.Errorf("CSIPersistentVolumeSource not defined in spec") 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` // log prepends log string with `kubernetes.io/csi`
func log(msg string, parts ...interface{}) string { func log(msg string, parts ...interface{}) string {
return fmt.Sprintf(fmt.Sprintf("%s: %s", csiPluginName, msg), parts...) return fmt.Sprintf(fmt.Sprintf("%s: %s", csiPluginName, msg), parts...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment